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.

97 lines
4.2 KiB

  1. /*
  2. Each level in the SMTVerifier has a state.
  3. This is the state machine.
  4. The signals are
  5. levIns: 1 if we are in the level where the insertion should happen
  6. xor: 1 if the bitKey of the old and new keys are different in this level
  7. is0: Input that indicates that the oldKey is 0
  8. fnc: 0 -> VERIFY INCLUSION
  9. 1 -> VERIFY NOT INCLUSION
  10. err state is not a state itself. It's a lack of state.
  11. The end of the last level will have to be `na`
  12. levIns=0 ###########
  13. xor=1 # #
  14. fnc=1 ┌──────────▶# err #
  15. │ ## ##
  16. levIns=0 │ #########
  17. xor=0 || fnc=0 │ any
  18. ┌────┐ │ ┌────┐
  19. │ │ │ │ │
  20. │ ▼ │ levIns=1 ▼ │
  21. │ ########### │ is0=1 ########### ########### │
  22. │ # # ───────────┘ fnc=1 # # any # # │
  23. └──# top # ─────────────────────▶# i0 #───────────────▶# na #──┘
  24. ## ## ──────────┐ ## ## ┌───────▶## ##
  25. ########─────────────┐│ ######### │┌────────▶#########
  26. ││ levIns=1 ││
  27. ││ is0=0 ########### ││
  28. ││ fnc=1 # # any│
  29. │└──────────▶ # iold #────────┘│
  30. │ ## ## │
  31. │ ######### │
  32. │ │
  33. │ levIns=1 ########### │
  34. │ fnc=0 # # any
  35. └────────────▶# inew #─────────┘
  36. ## ##
  37. #########
  38. */
  39. template SMTVerifierSM() {
  40. signal input xor;
  41. signal input is0;
  42. signal input levIns;
  43. signal input fnc;
  44. signal input prev_top;
  45. signal input prev_i0;
  46. signal input prev_iold;
  47. signal input prev_inew;
  48. signal input prev_na;
  49. signal output st_top;
  50. signal output st_i0;
  51. signal output st_iold;
  52. signal output st_inew;
  53. signal output st_na;
  54. signal prev_top_lev_ins;
  55. signal prev_top_lev_ins_fnc;
  56. signal xor_fnc;
  57. prev_top_lev_ins <== prev_top * levIns;
  58. prev_top_lev_ins_fnc <== prev_top_lev_ins*fnc; // prev_top * levIns * fnc
  59. xor_fnc <== xor*fnc;
  60. // st_top = prev_top * (1-levIns) * (1 - xor*fnc)
  61. // = + prev_top
  62. // - prev_top * levIns
  63. // - prev_top * xor * fnc
  64. // + prev_top * levIns * xor * fnc
  65. st_top <== (prev_top - prev_top_lev_ins)*(1-xor_fnc);
  66. // st_inew = prev_top * levIns * (1-fnc)
  67. // = + prev_top * levIns
  68. // - prev_top * levIns * fnc
  69. st_inew <== prev_top_lev_ins - prev_top_lev_ins_fnc;
  70. // st_iold = prev_top * levIns * (1-is0)*fnc
  71. // = + prev_top * levIns * fnc
  72. // - prev_top * levIns * fnc * is0
  73. st_iold <== prev_top_lev_ins_fnc * (1 - is0);
  74. // st_i0 = prev_top * levIns * is0
  75. // = + prev_top * levIns * is0
  76. st_i0 <== prev_top_lev_ins * is0;
  77. st_na <== prev_na + prev_inew + prev_iold + prev_i0;
  78. }