any difference in proving NotEqual constraint using if and without it

15 Views Asked by At

I practice writing circom using the problem from RareSkill' zero knowledge puzzle. I was working on the problem NotEqual. I have two different solutions. Both of them passed the test provided by the puzzle creators.

The first version used var and if.

template NotEqual() {
    signal input a[2];
    signal output c;
    signal d;
    var v;
    
    if (a[0] != a[1]) {
        v = 1;
    } else {
        v = 0;
    }
    d <-- v;
    c <== d;
}

The second version does not.

template NotEqual() {
    signal input a[2];
    signal output c;
    signal d;
    d <-- (a[0]-a[1]) * (1/(a[0]-a[1]));
    c <== d;
}

I was wondering that are there any differences in zero knowledge proof between both version. And I don't understand why in the first version I cannot simply use c <== v;

0

There are 0 best solutions below