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.

48 lines
737 B

  1. include "../mimc.circom";
  2. /*
  3. Hash1 = H(1 | key | value)
  4. */
  5. template SMTHash1() {
  6. signal input key;
  7. signal input value;
  8. signal output out;
  9. component h1 = MiMC7(91); // Constant
  10. h1.x_in <== 0;
  11. h1.k <== 1;
  12. component h2 = MiMC7(91);
  13. h2.x_in <== h1.out;
  14. h2.k <== key;
  15. component h3 = MiMC7(91);
  16. h3.x_in <== h2.out;
  17. h3.k <== value;
  18. out <== h3.out;
  19. }
  20. /*
  21. This component is used to create the 2 nodes.
  22. Hash2 = H(Hl | Hr)
  23. */
  24. template SMTHash2() {
  25. signal input L;
  26. signal input R;
  27. signal output out;
  28. component h1 = MiMC7(91);
  29. h1.x_in <== 0;
  30. h1.k <== L;
  31. component h2 = MiMC7(91);
  32. h2.x_in <== h1.out;
  33. h2.k <== R;
  34. out <== h2.out;
  35. }