iden3 / circom

zkSnark circuit compiler
GNU General Public License v3.0
1.23k stars 230 forks source link

Division by Zero issue #206

Open TuyetTDuong opened 11 months ago

TuyetTDuong commented 11 months ago

I'm using circom 2.1.4. c <-- b/a where a === 0 returns c = 0, while c <-- b/0 throws division by 0 error. Since Zero has no modular multiplicative inverse, both cases should throw runtime error.

Here is a test example

pragma circom 2.1.4;

include "circomlib/poseidon.circom";

template Example () {
    signal input a;
    signal input b;
    signal output c;

    a ===0;
    c <-- b/a;

    component hash = Poseidon(2);
    hash.inputs[0] <== a;
    hash.inputs[1] <== a;

    log(c);
}

component main { public [ a ] } = Example();

/* INPUT = 
   {
    "a": "0",
    "b": "5"
}
 */
kumar-mahendra commented 5 months ago

+1 Tried to reproduce it and this bug is still not resolved. @alrubio please have a look. Reason: when perform "/" operation using idiv function, we only check if denominator is non-zero when both numerator and denominator are numbers. instead we should check if denominator is number and numerator can be anything then, always make sure denominator is non-zero.
In fact, If no one is working on this, please assign this issue to me. I will solve it and open a pull request.

image