circomlib/circuits/smt/smtprocessorlevel.circom

78 lines
1.9 KiB
Plaintext
Raw Normal View History

2018-12-06 19:32:49 +03:00
/******
2018-12-14 16:24:30 +03:00
SMTProcessorLevel
2018-12-06 19:32:49 +03:00
This circuit has 2 has
Outputs according to the state.
State oldRoot newRoot
===== ======= =======
top H'(oldChild, sibling) H'(newChild, sibling)
old0 0 new1leaf
2018-12-13 23:04:37 +03:00
bot old1leaf H'(newChild, 0)
new1 old1leaf H'(new1leaf, old1leaf)
2018-12-06 19:32:49 +03:00
na 0 0
2018-12-13 21:53:32 +03:00
upd old1leaf new1leaf
2018-12-06 19:32:49 +03:00
H' is the Hash function with the inputs shifted acordingly.
*****/
2018-12-14 16:24:30 +03:00
template SMTProcessorLevel() {
2018-12-06 19:32:49 +03:00
signal input st_top;
signal input st_old0;
signal input st_bot;
signal input st_new1;
signal input st_na;
2018-12-13 21:53:32 +03:00
signal input st_upd;
2018-12-06 19:32:49 +03:00
signal output oldRoot;
signal output newRoot;
signal input sibling;
signal input old1leaf;
signal input new1leaf;
signal input newlrbit;
signal input oldChild;
signal input newChild;
signal aux[4];
component oldProofHash = SMTHash2();
component newProofHash = SMTHash2();
component oldSwitcher = Switcher();
component newSwitcher = Switcher();
// Old side
2018-12-11 19:25:21 +03:00
oldSwitcher.L <== oldChild;
oldSwitcher.R <== sibling;
2018-12-06 19:32:49 +03:00
oldSwitcher.sel <== newlrbit;
oldProofHash.L <== oldSwitcher.outL;
oldProofHash.R <== oldSwitcher.outR;
2018-12-13 23:04:37 +03:00
aux[0] <== old1leaf * (st_bot + st_new1 + st_upd);
2018-12-06 19:32:49 +03:00
oldRoot <== aux[0] + oldProofHash.out * st_top;
// New side
2018-12-13 23:04:37 +03:00
aux[1] <== newChild * ( st_top + st_bot);
2018-12-11 19:25:21 +03:00
newSwitcher.L <== aux[1] + new1leaf*st_new1;
2018-12-06 19:32:49 +03:00
aux[2] <== sibling*st_top;
2018-12-11 19:25:21 +03:00
newSwitcher.R <== aux[2] + old1leaf*st_new1;
2018-12-06 19:32:49 +03:00
2018-12-11 19:25:21 +03:00
newSwitcher.sel <== newlrbit;
newProofHash.L <== newSwitcher.outL;
newProofHash.R <== newSwitcher.outR;
2018-12-06 19:32:49 +03:00
2018-12-13 23:04:37 +03:00
aux[3] <== newProofHash.out * (st_top + st_bot + st_new1);
2018-12-13 21:53:32 +03:00
newRoot <== aux[3] + new1leaf * (st_old0 + st_upd);
2018-12-06 19:32:49 +03:00
}