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.

71 lines
1.7 KiB

6 years ago
  1. /*
  2. Copyright 2018 0KIMS association.
  3. This file is part of circom (Zero Knowledge Circuit Compiler).
  4. circom is a free software: you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. circom is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  11. License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with circom. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. /******
  16. SMTVerifierLevel
  17. This circuit has 1 hash
  18. Outputs according to the state.
  19. State root
  20. ===== =======
  21. top H'(child, sibling)
  22. i0 0
  23. iold old1leaf
  24. inew new1leaf
  25. na 0
  26. H' is the Hash function with the inputs shifted acordingly.
  27. *****/
  28. template SMTVerifierLevel() {
  29. signal input st_top;
  30. signal input st_i0;
  31. signal input st_iold;
  32. signal input st_inew;
  33. signal input st_na;
  34. signal output root;
  35. signal input sibling;
  36. signal input old1leaf;
  37. signal input new1leaf;
  38. signal input lrbit;
  39. signal input child;
  40. signal aux[2];
  41. component proofHash = SMTHash2();
  42. component switcher = Switcher();
  43. switcher.L <== child;
  44. switcher.R <== sibling;
  45. switcher.sel <== lrbit;
  46. proofHash.L <== switcher.outL;
  47. proofHash.R <== switcher.outR;
  48. aux[0] <== proofHash.out * st_top;
  49. aux[1] <== old1leaf*st_iold;
  50. root <== aux[0] + aux[1] + new1leaf*st_inew;
  51. }