Small patches

This commit is contained in:
Jordi Baylina
2018-12-22 23:54:25 +01:00
parent 345f040b41
commit 0639963bea
18 changed files with 379 additions and 272968 deletions

View File

@@ -77,7 +77,7 @@ 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.
signal done[nLevels-1]; // Indicates if the insLevel has aready been detected.
component isZero[nLevels];
@@ -87,7 +87,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) * enabled === 0;
(isZero[nLevels-1].out - 1) * enabled === 0;
levIns[nLevels-1] <== (1-isZero[nLevels-2].out);
done[nLevels-2] <== levIns[nLevels-1];

View File

@@ -139,7 +139,7 @@ include "smthash.circom";
template SMTProcessor(nLevels) {
signal input oldRoot;
signal input newRoot;
signal output newRoot;
signal input siblings[nLevels];
signal input oldKey;
signal input oldValue;
@@ -201,7 +201,7 @@ template SMTProcessor(nLevels) {
sm[i].fnc[1] <== fnc[1];
sm[i].levIns <== smtLevIns.levIns[i];
}
sm[nLevels-1].st_na === 1;
sm[nLevels-1].st_na + sm[nLevels-1].st_new1 + sm[nLevels-1].st_old0 +sm[nLevels-1].st_upd === 1;
component levels[nLevels];
for (var i=nLevels-1; i != -1; i--) {
@@ -234,8 +234,15 @@ template SMTProcessor(nLevels) {
topSwitcher.L <== levels[0].oldRoot;
topSwitcher.R <== levels[0].newRoot;
topSwitcher.outL === oldRoot*enabled;
topSwitcher.outR === newRoot*enabled;
component checkOldInput = ForceEqualIfEnabled();
checkOldInput.enabled <== enabled;
checkOldInput.in[0] <== oldRoot;
checkOldInput.in[1] <== topSwitcher.outL;
newRoot <== enabled * (topSwitcher.outR - oldRoot) + oldRoot;
// topSwitcher.outL === oldRoot*enabled;
// topSwitcher.outR === newRoot*enabled;
// Ckeck keys are equal if updating
component areKeyEquals = IsEqual();

View File

@@ -38,6 +38,7 @@ include "smtverifiersm.circom";
include "smthash.circom";
template SMTVerifier(nLevels) {
signal input enabled;
signal input root;
signal input siblings[nLevels];
signal input oldKey;
@@ -63,17 +64,17 @@ template SMTVerifier(nLevels) {
component smtLevIns = SMTLevIns(nLevels);
for (var i=0; i<nLevels; i++) smtLevIns.siblings[i] <== siblings[i];
smtLevIns.enabled <== 1;
smtLevIns.enabled <== enabled;
component sm[nLevels];
for (var i=0; i<nLevels; i++) {
sm[i] = SMTVerifierSM();
if (i==0) {
sm[i].prev_top <== 1;
sm[i].prev_top <== enabled;
sm[i].prev_i0 <== 0;
sm[i].prev_inew <== 0;
sm[i].prev_iold <== 0;
sm[i].prev_na <== 0;
sm[i].prev_na <== 1-enabled;
} else {
sm[i].prev_top <== sm[i-1].st_top;
sm[i].prev_i0 <== sm[i-1].st_i0;
@@ -85,7 +86,7 @@ template SMTVerifier(nLevels) {
sm[i].fnc <== fnc;
sm[i].levIns <== smtLevIns.levIns[i];
}
sm[nLevels-1].st_na === 1;
sm[nLevels-1].st_na + sm[nLevels-1].st_iold + sm[nLevels-1].st_inew + sm[nLevels-1].st_i0 === 1;
component levels[nLevels];
for (var i=nLevels-1; i != -1; i--) {
@@ -115,14 +116,20 @@ template SMTVerifier(nLevels) {
areKeyEquals.in[0] <== oldKey;
areKeyEquals.in[1] <== key;
component keysOk = MultiAND(3);
component keysOk = MultiAND(4);
keysOk.in[0] <== fnc;
keysOk.in[1] <== 1-isOld0;
keysOk.in[2] <== areKeyEquals.out;
keysOk.in[3] <== enabled;
keysOk.out === 0;
// Check the roots
levels[0].root === root;
// Check the root
component checkRoot = ForceEqualIfEnabled();
checkRoot.enabled <== enabled;
checkRoot.in[0] <== levels[0].root;
checkRoot.in[1] <== root;
// levels[0].root === root;
}