iden3 / circom

zkSnark circuit compiler
GNU General Public License v3.0
1.29k stars 247 forks source link

"\" operator causes downstream verification failure despite witness+proof generation success #167

Closed nanaknihal closed 1 year ago

nanaknihal commented 1 year ago

using circom compiler 2.1.2 code to replicate:

git pull https://github.com/nanaknihal/quotient-circom-replication.git
cd quotient-circom-replication
sh test.sh

Witness + proof generation succeeds, but verification fails. The witness and proof are generated without error, so this failure shouldn't happen.

However, when you change main.circom by replacing line signal y <== x \ 30; to signal y <== x / 30; verification succeeds.

main.circom for reference:

include "./node_modules/circomlib/circuits/bitify.circom";

template ReplicateBug() {
    signal input x;
    // This line works:
    // signal y <== x / 30;
    // Replacing it with this means it works for witness+proof generation but causes proof verification failure
    signal y <== x \ 30;
    component asBits = Num2Bits(254);
    asBits.in <== y;

}

component main { public [x] } = ReplicateBug();
alrubio commented 1 year ago

There was a bug with the handling of integer division "\" with constants in some cases. That was fixed in the release 2.1.3. Please, update your version (the current one is 2.1.5) and check it.

nanaknihal commented 1 year ago

Thanks, that worked