0xPARC ZK Learning Group

https://dev.to/tonyolendo/the-complete-full-stack-guide-to-getting-started-with-zero-knowledge-proofs-using-circom-and-zk-snarks-part-2-58o

  • x is declared as public input

  • if not declared, assumes inputs are private.

Public vs Private inputs

  • public and private inputs to the circuit.

  • Public signals are variables that are public for everyone, if one takes a look on the blockchain, one can see these public variables are open for everyone to see.

  • Private values are only available to the proof creator.

all output signals of the main component are public (and cannot be made private),

For example, you want to prove you know a x such that y = f(x), x would be private, but y would be public.

  • out would be y [signal output out]

Examples

NonEqual

pragma circom 2.0.0

template NonEqual(){
    signal input in0;
    signal input in1;
    
    // check that (in0-in1) is non-zero: check tt they not same
    signal inverse;
    // assign inverse value
    inverse <-- 1 / (in0 - in1);
    // create constraint
    inverse * (in0 - in1) === 1;
            
}
  • Template NonEqual checks that in0 and in1 are not equal to each other.

  • If they are not equal, the difference btw the signals is non-zero.

  • To check that the signals are non-zero, we verify that the inverse exists.

Distinct

  • Checks if all elements of an array are unique.

  • Takes an array of n signals as input.

template Distinct(){
    
    signal input in[n];
    //declare a component
    component nonEqual[n][n];

    for (var i = 0, i < n, i++){

        for (var j = 0, j < i, j++){
            // create a subcircuit
            nonEqual[i][j] = NonEqual();
            // assign input values + set contraints
            nonEqual[i][j].in0 <== in[i];
            nonEqual[i][j].in1 <== in[j];
        }
    }
}
  • i,j a pair signals

  • for each pair, we want to check that they are not unique.

  • for each pair we will create a non-zero sub-circuit; and wire it up

Last updated

Was this helpful?