mirror of
https://github.com/arnaucube/circomlib.git
synced 2026-02-06 18:56:43 +01:00
multiget
This commit is contained in:
23
test/rawsmt3.circom
Normal file
23
test/rawsmt3.circom
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
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<nLevels; i++) {
|
||||
smtClaimExists.siblings[i] <== mtp[i];
|
||||
}
|
||||
smtClaimExists.oldKey <== 0;
|
||||
smtClaimExists.oldValue <== 0;
|
||||
smtClaimExists.isOld0 <== 0;
|
||||
|
||||
smtClaimExists.key <== hi;
|
||||
smtClaimExists.value <== hv;
|
||||
}
|
||||
component main = SMT(4);
|
||||
@@ -111,5 +111,28 @@ describe("SMT test", function () {
|
||||
assert(circuit.checkWitness(w));
|
||||
});
|
||||
|
||||
it("Check inclussion Adria case", async () => {
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
98
test/smtverifier_adria.js
Normal file
98
test/smtverifier_adria.js
Normal file
@@ -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<nLevels; i++) {
|
||||
smtClaimExists.siblings[i] <== mtp[i];
|
||||
}
|
||||
smtClaimExists.oldKey <== 0;
|
||||
smtClaimExists.oldValue <== 0;
|
||||
smtClaimExists.isOld0 <== 0;
|
||||
|
||||
smtClaimExists.key <== hi;
|
||||
smtClaimExists.value <== hv;
|
||||
}
|
||||
component main = SMT(4);
|
||||
`;
|
||||
|
||||
describe("smt3test", function () {
|
||||
this.timeout(200000);
|
||||
|
||||
let circuitFileName;
|
||||
|
||||
before( async () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user