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.

95 lines
2.6 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. 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. pragma circom 2.0.0;
  30. template SMTProcessorLevel() {
  31. signal input st_top;
  32. signal input st_old0;
  33. signal input st_bot;
  34. signal input st_new1;
  35. signal input st_na;
  36. signal input st_upd;
  37. signal output oldRoot;
  38. signal output newRoot;
  39. signal input sibling;
  40. signal input old1leaf;
  41. signal input new1leaf;
  42. signal input newlrbit;
  43. signal input oldChild;
  44. signal input newChild;
  45. signal aux[4];
  46. component oldProofHash = SMTHash2();
  47. component newProofHash = SMTHash2();
  48. component oldSwitcher = Switcher();
  49. component newSwitcher = Switcher();
  50. // Old side
  51. oldSwitcher.L <== oldChild;
  52. oldSwitcher.R <== sibling;
  53. oldSwitcher.sel <== newlrbit;
  54. oldProofHash.L <== oldSwitcher.outL;
  55. oldProofHash.R <== oldSwitcher.outR;
  56. aux[0] <== old1leaf * (st_bot + st_new1 + st_upd);
  57. oldRoot <== aux[0] + oldProofHash.out * st_top;
  58. // New side
  59. aux[1] <== newChild * ( st_top + st_bot);
  60. newSwitcher.L <== aux[1] + new1leaf*st_new1;
  61. aux[2] <== sibling*st_top;
  62. newSwitcher.R <== aux[2] + old1leaf*st_new1;
  63. newSwitcher.sel <== newlrbit;
  64. newProofHash.L <== newSwitcher.outL;
  65. newProofHash.R <== newSwitcher.outR;
  66. aux[3] <== newProofHash.out * (st_top + st_bot + st_new1);
  67. newRoot <== aux[3] + new1leaf * (st_old0 + st_upd);
  68. }