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.

105 lines
4.4 KiB

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