Browse Source

Sparse Merkle tree working

feature/synctests2
Jordi Baylina 6 years ago
parent
commit
6d6558370f
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
7 changed files with 29 additions and 85588 deletions
  1. +1
    -9
      circuits/smt/smtverifier.circom
  2. +23
    -34
      circuits/smt/smtverifiersm.circom
  3. BIN
      doc/smt_verifier_sm.monopic
  4. +0
    -61546
      err.sig
  5. +1
    -1
      package.json
  6. +0
    -23994
      test.sig
  7. +4
    -4
      test/smtverifier.js

+ 1
- 9
circuits/smt/smtverifier.circom

@ -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--) {

+ 23
- 34
circuits/smt/smtverifiersm.circom

@ -15,38 +15,32 @@ 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 # # │
└──# top # ─────────────────────▶# i0 #───────────────▶# na #──┘
## ## ──────────┐ ## ## ┌───────▶## ##
########─────────────┐│ ######### │┌────────▶#########
││ levIns=1 ││
││ is0=0 ########### ││
││ fnc=1 # # any│
│└──────────▶ # iold #────────┘│
│ ## ## │
│ ######### │
│ │
│ levIns=1 ########### │
│ fnc=0 # # any
└────────────▶# inew #─────────┘
## ##
#########
levIns=0 any
┌────┐ ┌────┐
│ │ │ │
│ ▼ levIns=1 ▼ │
│ ########### is0=1 ########### ########### │
│ # # fnc=1 # # any # # │
└──# top # ─────────────────────▶# i0 #───────────────▶# na #──┘
## ## ──────────┐ ## ## ┌───────▶## ##
########─────────────┐│ ######### │┌────────▶#########
││ levIns=1 ││
││ is0=0 ########### ││
││ fnc=1 # # any│
│└──────────▶ # iold #────────┘│
│ ## ## │
│ ######### │
│ │
│ levIns=1 ########### │
│ fnc=0 # # any
└────────────▶# inew #─────────┘
## ##
#########
*/
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

BIN
doc/smt_verifier_sm.monopic


+ 0
- 61546
err.sig
File diff suppressed because it is too large
View File


+ 1
- 1
package.json

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

+ 0
- 23994
test.sig
File diff suppressed because it is too large
View File


+ 4
- 4
test/smtverifier.js

@ -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);
});

Loading…
Cancel
Save