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.

145 lines
6.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. /***************************************************************************************************
  2. Each level on a SMTProcessor has a state.
  3. The state of the level depends on the state of te botom level and on `xor` and
  4. `is0` signals.
  5. `isOldLev` 1 when is the level where oldLeaf is.
  6. `xor` signal is 0 if the index bit at the current level is the same in the old
  7. and the new index, and 1 if it is different.
  8. `is0` signal, is 1 if we are inserting/deleting in an empty leaf and 0 if we
  9. are inserting/deleting in a leaf that contains an element.
  10. The states are:
  11. top: While the index bits of the old and new insex in the top level is the same, whe are in the top state.
  12. old0: When the we reach insert level, we go to old0 state
  13. if `is0`=1.
  14. btn: Once in insert level and `is0` =0 we go to btn or new1 level if xor=1
  15. new1: This level is reached when xor=1. Here is where we insert/delete the hash of the
  16. old and the new trees with just one element.
  17. na: Not appliable. After processing it, we go to the na level.
  18. Fnction
  19. fnc[0] fnc[1]
  20. 0 0 NOP
  21. 0 1 UPDATE
  22. 1 0 INSERT
  23. 1 1 DELETE
  24. ###########
  25. # #
  26. ┌────────────────────────────▶# upd #─────────────────────┐
  27. │ ## ## │
  28. │ ######### │
  29. levIns=1 │ │
  30. fnc[0]=0 │ │ any
  31. │ │
  32. │ │
  33. │ │
  34. │ ########### │
  35. │ levIns=1 # # │
  36. levIns=0 │ is0=1 ┌────────────▶# old0 #────────┐ │ any
  37. ┌─────┐ │ fnc[0]=1│ ## ## │ │ ┌──────┐
  38. │ │ │ │ ######### │ any │ │ │
  39. │ ▼ │ │ │ ▼ ▼ │
  40. │ ########### │ │ ########### │
  41. │ # # ────────────┘ └────────▶# #│
  42. └──# top # # na #
  43. ## ## ───────────────────┐ levIns=1 ┌──▶## ##
  44. ######### │ is0=0 │ #########
  45. │ │ fnc[0]=1 │
  46. │ │ xor=1 ########### │ any
  47. │ └──────────────────▶# # │
  48. │ # new1 #──┘
  49. │ ## ##
  50. └────────────────────────────────┐ #########
  51. levIns=1 │ ▲
  52. is0=0 │ ┌─────┘
  53. fnc[0]=1 │ ###########│ xor=1
  54. xor=0 │ # #
  55. ▼# btn #
  56. ## ##
  57. #########◀───────┐
  58. │ │
  59. │ │
  60. └────────────┘
  61. xor=0
  62. ***************************************************************************************************/
  63. template SMTProcessorSM() {
  64. signal input xor;
  65. signal input is0;
  66. signal input levIns;
  67. signal input fnc[2];
  68. signal input prev_top;
  69. signal input prev_old0;
  70. signal input prev_bot;
  71. signal input prev_new1;
  72. signal input prev_na;
  73. signal input prev_upd;
  74. signal output st_top;
  75. signal output st_old0;
  76. signal output st_bot;
  77. signal output st_new1;
  78. signal output st_na;
  79. signal output st_upd;
  80. signal aux1;
  81. signal aux2;
  82. aux1 <== prev_top * levIns;
  83. aux2 <== aux1*fnc[0]; // prev_top * levIns * fnc[0]
  84. // st_top = prev_top*(1-levIns)
  85. // = + prev_top
  86. // - prev_top * levIns = aux1
  87. st_top <== prev_top - aux1;
  88. // st_old0 = prev_top * levIns * is0 * fnc[0]
  89. // = + prev_top * levIns * is0 * fnc[0] = aux2 * is0
  90. st_old0 <== aux2 * is0; // prev_top * levIns * is0 * fnc[0]
  91. // st_new1 = prev_top * levIns * (1-is0)*fnc[0] * xor + prev_bot*xor =
  92. // = + prev_top * levIns * fnc[0] * xor = aux2 * xor
  93. // - prev_top * levIns * is0 * fnc[0] * xor = st_old0 * xor
  94. // + prev_bot * xor = prev_bot * xor
  95. st_new1 <== (aux2 - st_old0 + prev_bot)*xor;
  96. // st_bot = prev_top * levIns * (1-is0)*fnc[0] * (1-xor) + prev_bot*(1-xor);
  97. // = + prev_top * levIns * fnc[0]
  98. // - prev_top * levIns * is0 * fnc[0]
  99. // - prev_top * levIns * fnc[0] * xor
  100. // + prev_top * levIns * is0 * fnc[0] * xor
  101. // + prev_bot
  102. // - prev_bot * xor
  103. st_bot <== (1-xor) * (aux2 - st_old0 + prev_bot)
  104. // st_upd = prev_top * (1-fnc[0]) *levIns;
  105. // = + prev_top * levIns
  106. // - prev_top * levIns * fnc[0]
  107. st_upd <== aux1 - aux2
  108. // st_na = prev_new1 + prev_old0 + prev_na + prev_upd;
  109. // = + prev_new1
  110. // + prev_old0
  111. // + prev_na
  112. // + prev_upd
  113. st_na <== prev_new1 + prev_old0 + prev_na + prev_upd;
  114. }