-1

I am working on passing a test for a hackerhouse where I need to compare two inputs using an IsEqual function. Please provide code and explanation of it. Thank you!

Pavel Fedotov
  • 748
  • 1
  • 7
  • 29

1 Answers1

1

First, you'll need to define the IsEqual template and all its components. The IsEqual template takes two inputs (in[0] and in[1]) and outputs a boolean value (out) indicating whether the two inputs are equal.

template IsZero () {
    signal input in;
    signal output out;
    signal inverse;
    inverse <-- in!= 0 ? 1/in : 0; 
    
    out <== -in*inverse+1;
    in*out === 0;
}

template IsEqual () {
    signal input in[2];
    signal output out;

    component comp = IsZero();

    comp.in <== in[1] - in[0];
    
    out <== comp.out;
}

The comp component in the IsEqual template uses the IsZero template to determine if the difference between the two input signals is zero. If the difference is zero, it means the inputs are equal, and the out signal is set to true, otherwise, it's set to false.

Here is the test case for the template:

component main { public [ in ] } = IsEqual();

/* INPUT = {
    "in":["0", "1"]
} */
Pavel Fedotov
  • 748
  • 1
  • 7
  • 29