working with some errors yet

This commit is contained in:
Jordi Baylina
2018-12-13 19:53:32 +01:00
parent 38fc4b7396
commit ccaa7ff23b
11 changed files with 24599 additions and 150 deletions

View File

@@ -94,6 +94,15 @@ Insert to a used leaf.
na ┃ Hash ┃ ┃ Hash ┃
┗━━━━━━━┛ ┗━━━━━━━┛
Fnction
fnc[0] fnc[1]
0 0 NOP
0 1 UPDATE
1 0 INSERT
1 1 DELETE
***************************************************************************************************/
include "../gates.circom";
@@ -114,6 +123,11 @@ template SMTInsert(nLevels) {
signal input isOld0;
signal input newKey;
signal input newValue;
signal input fnc[2];
signal enabled;
enabled <== fnc[0] + fnc[1] - fnc[0]*fnc[1]
component hash1Old = SMTHash1();
hash1Old.key <== oldKey;
@@ -131,6 +145,7 @@ template SMTInsert(nLevels) {
component smtLevIns = SMTLevIns(nLevels);
for (var i=0; i<nLevels; i++) smtLevIns.siblings[i] <== siblings[i];
smtLevIns.enabled <== enabled;
component xors[nLevels];
for (var i=0; i<nLevels; i++) {
@@ -143,12 +158,13 @@ template SMTInsert(nLevels) {
for (var i=0; i<nLevels; i++) {
sm[i] = SMTInsertSM();
if (i==0) {
sm[i].prev_top <== 1;
sm[i].prev_top <== enabled;
sm[i].prev_old1 <== 0;
sm[i].prev_old0 <== 0;
sm[i].prev_bot <== 0;
sm[i].prev_new1 <== 0;
sm[i].prev_na <== 0;
sm[i].prev_na <== 1-enabled;
sm[i].prev_upd <== 0;
} else {
sm[i].prev_top <== sm[i-1].st_top;
sm[i].prev_old1 <== sm[i-1].st_old1;
@@ -156,9 +172,12 @@ template SMTInsert(nLevels) {
sm[i].prev_bot <== sm[i-1].st_bot;
sm[i].prev_new1 <== sm[i-1].st_new1;
sm[i].prev_na <== sm[i-1].st_na;
sm[i].prev_upd <== sm[i-1].st_upd;
}
sm[i].is0 <== isOld0;
sm[i].xor <== xors[i].out;
sm[i].fnc[0] <== fnc[0];
sm[i].fnc[1] <== fnc[1];
sm[i].levIns <== smtLevIns.levIns[i];
}
sm[nLevels-1].st_na === 1;
@@ -172,7 +191,8 @@ template SMTInsert(nLevels) {
levels[i].st_old0 <== sm[i].st_old0;
levels[i].st_bot <== sm[i].st_bot;
levels[i].st_new1 <== sm[i].st_new1;
levels[i].st_na <==sm[i].st_na;
levels[i].st_na <== sm[i].st_na;
levels[i].st_upd <== sm[i].st_upd;
levels[i].sibling <== siblings[i];
levels[i].old1leaf <== hash1Old.out;
@@ -188,6 +208,12 @@ template SMTInsert(nLevels) {
}
}
levels[0].oldRoot === oldRoot;
levels[0].newRoot === newRoot;
component topSwitcher = Switcher();
topSwitcher.sel <== fnc[0]*fnc[1];
topSwitcher.L <== levels[0].oldRoot;
topSwitcher.R <== levels[0].newRoot;
topSwitcher.outL === oldRoot*enabled;
topSwitcher.outR === newRoot*enabled;
}

View File

@@ -17,6 +17,8 @@ bot 0 H'(newChild, 0)
new1 0 H'(new1leaf, old1leaf)
na 0 0
upd old1leaf new1leaf
H' is the Hash function with the inputs shifted acordingly.
*****/
@@ -29,6 +31,7 @@ template SMTInsertLevel() {
signal input st_bot;
signal input st_new1;
signal input st_na;
signal input st_upd;
signal output oldRoot;
signal output newRoot;
@@ -56,7 +59,7 @@ template SMTInsertLevel() {
oldProofHash.L <== oldSwitcher.outL;
oldProofHash.R <== oldSwitcher.outR;
aux[0] <== old1leaf * st_old1;
aux[0] <== old1leaf * (st_old1 + st_upd);
oldRoot <== aux[0] + oldProofHash.out * st_top;
// New side
@@ -72,5 +75,5 @@ template SMTInsertLevel() {
newProofHash.R <== newSwitcher.outR;
aux[3] <== newProofHash.out * (st_top + st_old1 + st_bot + st_new1);
newRoot <== aux[3] + new1leaf * st_old0;
newRoot <== aux[3] + new1leaf * (st_old0 + st_upd);
}

View File

@@ -33,33 +33,43 @@ fnc[0] fnc[1]
###########
levIns=1 # #
levIns=0 is0=1 ┌────────────▶# old0 #────────┐ any
┌─────┐ ## ## ┌──────┐
######### │ any
│ ▼
│ ########### ########### │
# # ────────────┘ └────────▶# #
└──# top # # na #
## ## ────┐ ┌──▶## ##
######### │ │ #########
│ ########### ########### │ any
levIns=1 # # xor=1 # #
is0=0 └───▶# old1 #─────────────▶# new1 #──┘
## ## ## ##
#########│ #########
└───┐ ┌─────┘
xor=0 │ ###########│ xor=1
│ # #
▼# btn #
## ##
#########◀───────┐
└────────────┘
xor=0
# #
┌────────────────────────────▶# upd #─────────────────────┐
## ##
│ #########
levIns=1
fnc[0]=0 │ any
###########
levIns=1 # #
levIns=0 is0=1 ┌────────────▶# old0 #────────┐ any
┌─────┐ │ fnc[0]=1 ## ## ┌──────┐
│ │ │ ######### │ any │ │ │
│ ▼ │ ▼ ▼ │
########### ########### │
│ # # ────────────┘ └────────▶# #│
└──# top # # na #
## ## ────┐ ┌──▶## ##
######### │ #########
########### ########### │ any
levIns=1 # # xor=1 # # │
is0=0 └───▶# old1 #─────────────▶# new1 #──┘
fnc[0]=1 ## ## ## ##
#########│ #########
└───┐ ┌─────┘
xor=0 │ ###########│ xor=1
│ # #
▼# btn #
## ##
#########◀───────┐
│ │
│ │
└────────────┘
xor=0
***************************************************************************************************/
@@ -67,8 +77,7 @@ template SMTInsertSM() {
signal input xor;
signal input is0;
signal input levIns;
signal input fnc[0];
signal input fnc[1];
signal input fnc[2];
signal input prev_top;
signal input prev_old0;
@@ -102,7 +111,7 @@ template SMTInsertSM() {
st_bot <== -st_new1 + prev_old1 + prev_bot // prev_old1*(1-xor) + prev_bot*(1-xor) =
// = - prev_old1*xor -prev_bot*xor + prev_old1 + prev_bot =
// = -st_new1 + prev_old1 + prev_bot
st_na <== prev_new1 + prev_old0 + prev_na + st_upd;
st_na <== prev_new1 + prev_old0 + prev_na + prev_upd;
st_upd <== aux1*(1-fnc[0]); // prev_top*levIns*(1-fnc[0]) =
// = aux1 * (1-fnc[0])

View File

@@ -55,6 +55,7 @@ a parent with a sibling != 0.
*/
template SMTLevIns(nLevels) {
signal input enabled;
signal input siblings[nLevels];
signal output levIns[nLevels];
signal done[nLevels-1]; // Indicates if the insLevel has aready been detecetd.
@@ -67,7 +68,7 @@ template SMTLevIns(nLevels) {
}
// The last level must always have a sibling of 0. If not, then it cannot be inserted.
isZero[nLevels-2].out === 1;
(isZero[nLevels-2].out - 1) * enabled === 0;
levIns[nLevels-1] <== (1-isZero[nLevels-2].out);
done[nLevels-2] <== levIns[nLevels-1];