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

  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. pragma circom 2.0.0;
  29. template SMTVerifierLevel() {
  30. signal input st_top;
  31. signal input st_i0;
  32. signal input st_iold;
  33. signal input st_inew;
  34. signal input st_na;
  35. signal output root;
  36. signal input sibling;
  37. signal input old1leaf;
  38. signal input new1leaf;
  39. signal input lrbit;
  40. signal input child;
  41. signal aux[2];
  42. component proofHash = SMTHash2();
  43. component switcher = Switcher();
  44. switcher.L <== child;
  45. switcher.R <== sibling;
  46. switcher.sel <== lrbit;
  47. proofHash.L <== switcher.outL;
  48. proofHash.R <== switcher.outR;
  49. aux[0] <== proofHash.out * st_top;
  50. aux[1] <== old1leaf*st_iold;
  51. root <== aux[0] + aux[1] + new1leaf*st_inew;
  52. }