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