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.

79 lines
1.9 KiB

  1. /******
  2. SMTInsertLevel
  3. This circuit has 2 has
  4. Outputs according to the state.
  5. State oldRoot newRoot
  6. ===== ======= =======
  7. top H'(oldChild, sibling) H'(newChild, sibling)
  8. old1 old1leaf H'(newChild, 0)
  9. old0 0 new1leaf
  10. bot 0 H'(newChild, 0)
  11. new1 0 H'(new1leaf, old1leaf)
  12. na 0 0
  13. upd old1leaf new1leaf
  14. H' is the Hash function with the inputs shifted acordingly.
  15. *****/
  16. template SMTInsertLevel() {
  17. signal input st_top;
  18. signal input st_old1;
  19. signal input st_old0;
  20. signal input st_bot;
  21. signal input st_new1;
  22. signal input st_na;
  23. signal input st_upd;
  24. signal output oldRoot;
  25. signal output newRoot;
  26. signal input sibling;
  27. signal input old1leaf;
  28. signal input new1leaf;
  29. signal input newlrbit;
  30. signal input oldChild;
  31. signal input newChild;
  32. signal aux[4];
  33. component oldProofHash = SMTHash2();
  34. component newProofHash = SMTHash2();
  35. component oldSwitcher = Switcher();
  36. component newSwitcher = Switcher();
  37. // Old side
  38. oldSwitcher.L <== oldChild;
  39. oldSwitcher.R <== sibling;
  40. oldSwitcher.sel <== newlrbit;
  41. oldProofHash.L <== oldSwitcher.outL;
  42. oldProofHash.R <== oldSwitcher.outR;
  43. aux[0] <== old1leaf * (st_old1 + st_upd);
  44. oldRoot <== aux[0] + oldProofHash.out * st_top;
  45. // New side
  46. aux[1] <== newChild * ( st_top + st_old1 + st_bot);
  47. newSwitcher.L <== aux[1] + new1leaf*st_new1;
  48. aux[2] <== sibling*st_top;
  49. newSwitcher.R <== aux[2] + old1leaf*st_new1;
  50. newSwitcher.sel <== newlrbit;
  51. newProofHash.L <== newSwitcher.outL;
  52. newProofHash.R <== newSwitcher.outR;
  53. aux[3] <== newProofHash.out * (st_top + st_old1 + st_bot + st_new1);
  54. newRoot <== aux[3] + new1leaf * (st_old0 + st_upd);
  55. }