From c4ce4cd9466486b645308757404835b28bb33417 Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Wed, 2 Oct 2019 09:34:49 +0200 Subject: [PATCH] multiget --- package-lock.json | 24 +++++----- package.json | 2 +- src/smt_memdb.js | 8 ++++ test/rawsmt3.circom | 23 +++++++++ test/smtverifier.js | 23 +++++++++ test/smtverifier_adria.js | 98 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 test/rawsmt3.circom create mode 100644 test/smtverifier_adria.js diff --git a/package-lock.json b/package-lock.json index 2fa27ac..c790785 100644 --- a/package-lock.json +++ b/package-lock.json @@ -348,9 +348,9 @@ } }, "big-integer": { - "version": "1.6.44", - "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.44.tgz", - "integrity": "sha512-7MzElZPTyJ2fNvBkPxtFQ2fWIkVmuzw41+BZHSzpEq3ymB2MfeKp1+yXl/tS75xCx+WnyV+yb0kp+K1C3UNwmQ==" + "version": "1.6.46", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.46.tgz", + "integrity": "sha512-Vj2TNtZ8Y0XaL6HCkzJiEqfykjtv/9wVCWIutMe+QVIXLPe2tCLEzULtYvcX9WRtmNIj3Jqi5tNjIsR0N4QOsg==" }, "binary-extensions": { "version": "1.13.1", @@ -601,9 +601,9 @@ } }, "circom": { - "version": "0.0.28", - "resolved": "https://registry.npmjs.org/circom/-/circom-0.0.28.tgz", - "integrity": "sha512-cYivdFVPUAVsGFgx3/W3BQe50fwiu+w8Mq9rWA/UYLWwjAgY0Ctk+obpxGL5v9ZHJpO6pvmczLnOXmV/KqiB5g==", + "version": "0.0.34", + "resolved": "https://registry.npmjs.org/circom/-/circom-0.0.34.tgz", + "integrity": "sha512-R7yNW8PtX2xREtLYWZ/o5cfKHT/qa+CveXsGVAX1ej7mPrTat9mlEMXEy2vX//IuP9/cnYTY/KxJ2SN05PUeGA==", "dev": true, "requires": { "big-integer": "^1.6.32", @@ -3929,9 +3929,9 @@ "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==" }, "p-limit": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", - "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.1.tgz", + "integrity": "sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg==", "requires": { "p-try": "^2.0.0" } @@ -4703,9 +4703,9 @@ } }, "snarkjs": { - "version": "0.1.18", - "resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.18.tgz", - "integrity": "sha512-JWZMBvPPIL424+QCY0PtreIiHTRoX4h4qYvKv3nqKPVZl0T7sw3B/ZeizrCVRz7Jr9vrwZxmzJ0XIg6D1yC8Mg==", + "version": "0.1.20", + "resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.20.tgz", + "integrity": "sha512-tYmWiVm1sZiB44aIh5w/3HUaTntTUC4fv+CWs4rR0gfkt2KbHTpArOqZW++/Lxujrn9IypXVhdKVUr/eE6Hxfg==", "requires": { "big-integer": "^1.6.43", "chai": "^4.2.0", diff --git a/package.json b/package.json index 9213f11..4673209 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "web3": "^1.0.0-beta.55" }, "devDependencies": { - "circom": "0.0.32", + "circom": "0.0.34", "eslint-plugin-mocha": "^5.2.0", "ganache-cli": "^6.4.4", "mocha": "^5.2.0" diff --git a/src/smt_memdb.js b/src/smt_memdb.js index d73e88d..c88f2c1 100644 --- a/src/smt_memdb.js +++ b/src/smt_memdb.js @@ -27,6 +27,14 @@ class SMTMemDb { return this.nodes[keyS]; } + async multiGet(keys) { + const promises = []; + for (let i=0; i { + const e1_hi= bigInt("17124152697573569611556136390143205198134245887034837071647643529178599000839"); + const e1_hv= bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179"); + + const e2ok_hi= bigInt("16498254692537945203721083102154618658340563351558973077349594629411025251262"); + const e2ok_hv= bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179"); + + const e2fail_hi= bigInt("17195092312975762537892237130737365903429674363577646686847513978084990105579"); + const e2fail_hv= bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179"); + + const tree1 = await smt.newMemEmptyTrie(); + await tree1.insert(e1_hi,e1_hv); + await tree1.insert(e2ok_hi,e2ok_hv); + + await testInclusion(tree1, e2ok_hi, circuit); + + const tree2 = await smt.newMemEmptyTrie(); + await tree2.insert(e1_hi,e1_hv); + await tree2.insert(e2fail_hi,e2fail_hv); + + await testInclusion(tree2, e2fail_hi, circuit); + }); + }); diff --git a/test/smtverifier_adria.js b/test/smtverifier_adria.js new file mode 100644 index 0000000..3b93d09 --- /dev/null +++ b/test/smtverifier_adria.js @@ -0,0 +1,98 @@ +const path = require("path"); +const snarkjs = require("snarkjs"); +const compiler = require("circom"); +const fs = require("fs") + +const bigInt = snarkjs.bigInt; +const smt = require("../src/smt.js"); + +const circuitSource = ` +include "../circuits/smt/smtverifier.circom"; +template SMT(nLevels) { + signal input root; + signal input mtp[nLevels]; + signal input hi; + signal input hv; + + component smtClaimExists = SMTVerifier(nLevels); + smtClaimExists.enabled <== 1; + smtClaimExists.fnc <== 0; + smtClaimExists.root <== root; + for (var i=0; i { + circuitFileName = path.join(__dirname, ".", "rawsmt3.circom"); + fs.writeFileSync(circuitFileName,circuitSource); + }); + + const levels = 4; + async function testsmt3(e1, e2) { + let tree = await smt.newMemEmptyTrie(); + + // insert e1, e2 + await tree.insert(e1.hi, e1.hv); + await tree.insert(e2.hi, e2.hv); + + // generate proof for e1 + const findInfo = await tree.find(e1.hi); + const siblings = findInfo.siblings; + while (siblings.length < levels) siblings.push(bigInt(0)); + + const input = { + root: tree.root, + mtp: siblings, + hi: e1.hi, + hv: e1.hv, + }; + + const compiledCircuit = await compiler( + circuitFileName, + { reduceConstraints: false } + ); + + const circuit = new snarkjs.Circuit(compiledCircuit); + const witness = circuit.calculateWitness(input); + circuit.checkWitness(witness); + } + + it("TestSmts", async () => { + + const e1 = { + hi: bigInt("17124152697573569611556136390143205198134245887034837071647643529178599000839"), + hv: bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179"), + }; + + const e2ok = { + hi: bigInt("16498254692537945203721083102154618658340563351558973077349594629411025251262"), + hv: bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179"), + }; + + const e2fail = { + hi: bigInt("17195092312975762537892237130737365903429674363577646686847513978084990105579"), + hv: bigInt("19650379996168153643111744440707177573540245771926102415571667548153444658179"), + }; + + console.log("test e1, e2ok"); + await testsmt3(e1, e2ok); + + console.log("test e1, e2fail"); + await testsmt3(e1, e2fail); + }); +}); +