You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.6 KiB

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