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.

75 lines
1.9 KiB

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