circomlib/circuits/smt/smtverifierlevel.circom
circuits/smt/smtverifierlevel.circomRaw
1/*
2 Copyright 2018 0KIMS association.
3
4 This file is part of circom (Zero Knowledge Circuit Compiler).
5
6 circom is a free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 circom is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with circom. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20/******
21
22SMTVerifierLevel
23
24This circuit has 1 hash
25
26Outputs according to the state.
27
28State root
29===== =======
30top H'(child, sibling)
31i0 0
32iold old1leaf
33inew new1leaf
34na 0
35
36H' is the Hash function with the inputs shifted acordingly.
37
38*****/
39
40
41template SMTVerifierLevel() {
42 signal input st_top;
43 signal input st_i0;
44 signal input st_iold;
45 signal input st_inew;
46 signal input st_na;
47
48 signal output root;
49 signal input sibling;
50 signal input old1leaf;
51 signal input new1leaf;
52 signal input lrbit;
53 signal input child;
54
55 signal aux[2];
56
57 component proofHash = SMTHash2();
58 component switcher = Switcher();
59
60 switcher.L <== child;
61 switcher.R <== sibling;
62
63 switcher.sel <== lrbit;
64 proofHash.L <== switcher.outL;
65 proofHash.R <== switcher.outR;
66
67 aux[0] <== proofHash.out * st_top;
68 aux[1] <== old1leaf*st_iold;
69
70 root <== aux[0] + aux[1] + new1leaf*st_inew;
71}