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.

94 lines
2.6 KiB

6 years ago
6 years ago
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. SMTProcessorLevel
  17. This circuit has 2 hash
  18. Outputs according to the state.
  19. State oldRoot newRoot
  20. ===== ======= =======
  21. top H'(oldChild, sibling) H'(newChild, sibling)
  22. old0 0 new1leaf
  23. bot old1leaf H'(newChild, 0)
  24. new1 old1leaf H'(new1leaf, old1leaf)
  25. na 0 0
  26. upd old1leaf new1leaf
  27. H' is the Hash function with the inputs shifted acordingly.
  28. *****/
  29. template SMTProcessorLevel() {
  30. signal input st_top;
  31. signal input st_old0;
  32. signal input st_bot;
  33. signal input st_new1;
  34. signal input st_na;
  35. signal input st_upd;
  36. signal output oldRoot;
  37. signal output newRoot;
  38. signal input sibling;
  39. signal input old1leaf;
  40. signal input new1leaf;
  41. signal input newlrbit;
  42. signal input oldChild;
  43. signal input newChild;
  44. signal aux[4];
  45. component oldProofHash = SMTHash2();
  46. component newProofHash = SMTHash2();
  47. component oldSwitcher = Switcher();
  48. component newSwitcher = Switcher();
  49. // Old side
  50. oldSwitcher.L <== oldChild;
  51. oldSwitcher.R <== sibling;
  52. oldSwitcher.sel <== newlrbit;
  53. oldProofHash.L <== oldSwitcher.outL;
  54. oldProofHash.R <== oldSwitcher.outR;
  55. aux[0] <== old1leaf * (st_bot + st_new1 + st_upd);
  56. oldRoot <== aux[0] + oldProofHash.out * st_top;
  57. // New side
  58. aux[1] <== newChild * ( st_top + st_bot);
  59. newSwitcher.L <== aux[1] + new1leaf*st_new1;
  60. aux[2] <== sibling*st_top;
  61. newSwitcher.R <== aux[2] + old1leaf*st_new1;
  62. newSwitcher.sel <== newlrbit;
  63. newProofHash.L <== newSwitcher.outL;
  64. newProofHash.R <== newSwitcher.outR;
  65. aux[3] <== newProofHash.out * (st_top + st_bot + st_new1);
  66. newRoot <== aux[3] + new1leaf * (st_old0 + st_upd);
  67. }