Sparse Merkle tree working

This commit is contained in:
Jordi Baylina 2018-12-15 09:15:58 +01:00
parent 09f36d1e4d
commit 6d6558370f
No known key found for this signature in database
GPG Key ID: 7480C80C1BE43112
7 changed files with 29 additions and 85588 deletions

@ -46,13 +46,6 @@ template SMTVerifier(nLevels) {
for (var i=0; i<nLevels; i++) smtLevIns.siblings[i] <== siblings[i];
smtLevIns.enabled <== 1;
component xors[nLevels];
for (var i=0; i<nLevels; i++) {
xors[i] = XOR();
xors[i].a <== n2bOld.out[i];
xors[i].b <== n2bNew.out[i];
}
component sm[nLevels];
for (var i=0; i<nLevels; i++) {
sm[i] = SMTVerifierSM();
@ -70,11 +63,10 @@ template SMTVerifier(nLevels) {
sm[i].prev_na <== sm[i-1].st_na;
}
sm[i].is0 <== isOld0;
sm[i].xor <== xors[i].out;
sm[i].fnc <== fnc;
sm[i].levIns <== smtLevIns.levIns[i];
}
// sm[nLevels-1].st_na === 1;
sm[nLevels-1].st_na === 1;
component levels[nLevels];
for (var i=nLevels-1; i != -1; i--) {

@ -15,17 +15,12 @@ err state is not a state itself. It's a lack of state.
The end of the last level will have to be `na`
levIns=0 ###########
xor=1 # #
fnc=1 ┌──────────▶# err #
│ ## ##
levIns=0 │ #########
xor=0 || fnc=0 │ any
┌────┐ │ ┌────┐
│ │ │ │ │
│ ▼ │ levIns=1 ▼ │
│ ########### │ is0=1 ########### ########### │
│ # # ───────────┘ fnc=1 # # any # # │
levIns=0 any
┌────┐ ┌────┐
│ │ │ │
│ ▼ levIns=1 ▼ │
│ ########### is0=1 ########### ########### │
│ # # fnc=1 # # any # # │
└──# top # ─────────────────────▶# i0 #───────────────▶# na #──┘
## ## ──────────┐ ## ## ┌───────▶## ##
########─────────────┐│ ######### │┌────────▶#########
@ -46,7 +41,6 @@ The end of the last level will have to be `na`
template SMTVerifierSM() {
signal input xor;
signal input is0;
signal input levIns;
signal input fnc;
@ -65,19 +59,14 @@ template SMTVerifierSM() {
signal prev_top_lev_ins;
signal prev_top_lev_ins_fnc;
signal xor_fnc;
prev_top_lev_ins <== prev_top * levIns;
prev_top_lev_ins_fnc <== prev_top_lev_ins*fnc; // prev_top * levIns * fnc
xor_fnc <== xor*fnc;
// st_top = prev_top * (1-levIns) * (1 - xor*fnc)
// st_top = prev_top * (1-levIns)
// = + prev_top
// - prev_top * levIns
// - prev_top * xor * fnc
// + prev_top * levIns * xor * fnc
st_top <== (prev_top - prev_top_lev_ins)*(1-xor_fnc);
st_top <== prev_top - prev_top_lev_ins;
// st_inew = prev_top * levIns * (1-fnc)
// = + prev_top * levIns

Binary file not shown.

61546
err.sig

File diff suppressed because it is too large Load Diff

@ -7,7 +7,7 @@
"test": "test"
},
"scripts": {
"test": "mocha"
"test": "mocha --max-old-space-size=4000"
},
"keywords": [
"pedersen",

23994
test.sig

File diff suppressed because it is too large Load Diff

@ -51,7 +51,7 @@ async function testExclusion(tree, key, circuit) {
isOld0: res.isOld0 ? 1 : 0,
key: key,
value: 0
}, console.log);
});
assert(circuit.checkWitness(w));
}
@ -82,13 +82,13 @@ describe("SMT test", function () {
});
it("Check exclussion in a tree of 3", async () => {
// await testExclusion(tree, 0, circuit);
await testExclusion(tree, 0, circuit);
await testExclusion(tree, 6, circuit);
/* await testExclusion(tree, 9, circuit);
await testExclusion(tree, 9, circuit);
await testExclusion(tree, 33, circuit);
await testExclusion(tree, 31, circuit);
await testExclusion(tree, 16, circuit);
await testExclusion(tree, 64, circuit); */
await testExclusion(tree, 64, circuit);
});