arnaucube
arnaucube/grapevine-sonobePublic Self-hosted repository
grapevine-sonobe/circom/templates/chaff.circom
circom/templates/chaff.circomRaw
 1pragma circom 2.1.6;
 2
 3include "../node_modules/circomlib/circuits/mux1.circom";
 4include "../node_modules/circomlib/circuits/comparators.circom";
 5
 6// multiplexes signals according to whether this is a chaff step or not
 7template ChaffMux() {
 8    // inputs from step_in
 9    signal input degrees_of_separation;
10    signal input given_phrase_hash;
11    signal input given_degree_secret_hash;
12    signal input is_chaff_step;
13    // computed inputs from circuit
14    signal input computed_phrase_hash;
15    signal input computed_degree_secret_hash;
16    // output formatted for step_out
17    signal output out[4];
18
19    // constrain is_chaff_step to be 0 or 1
20    is_chaff_step * (is_chaff_step - 1) === 0;
21
22    // mux 3 different inputs selected by is_chaff_step
23    component mux = MultiMux1(3);
24    mux.s <== is_chaff_step;
25
26    // mux the degree of separation
27    // if ! chaff step, increment degree of separation
28    mux.c[0][0] <== degrees_of_separation + 1;
29    mux.c[0][1] <== degrees_of_separation;
30
31    // mux the secret hash
32    // if ! chaff step, grab muxed hash output
33    mux.c[1][0] <== computed_phrase_hash;
34    mux.c[1][1] <== given_phrase_hash;
35
36    // mux the username hash
37    // if ! chaff step, grab the computed current username hash
38    mux.c[2][0] <== computed_degree_secret_hash;
39    mux.c[2][1] <== given_degree_secret_hash;
40
41    // flip chaff step
42    component flipped_chaff_step = IsZero();
43    flipped_chaff_step.in <== is_chaff_step;
44
45    // set step output
46    out[0] <== mux.out[0];
47    out[1] <== mux.out[1];
48    out[2] <== mux.out[2];
49    out[3] <== flipped_chaff_step.out;
50}