2018-12-16 13:27:29 +03:00
|
|
|
/*
|
|
|
|
Copyright 2018 0KIMS association.
|
|
|
|
|
|
|
|
This file is part of circom (Zero Knowledge Circuit Compiler).
|
|
|
|
|
|
|
|
circom is a free software: you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
circom is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with circom. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2018-12-15 11:00:35 +03:00
|
|
|
This circuit has 2 hash
|
2018-12-06 19:32:49 +03:00
|
|
|
|
|
|
|
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
|
|
|
}
|