mirror of
https://github.com/arnaucube/circomlib.git
synced 2026-02-07 03:06:44 +01:00
Verification not working
This commit is contained in:
3
test/circuits/smtverifier10_test.circom
Normal file
3
test/circuits/smtverifier10_test.circom
Normal file
@@ -0,0 +1,3 @@
|
||||
include "../../circuits/smt/smtverifier.circom";
|
||||
|
||||
component main = SMTVerifier(10);
|
||||
@@ -24,8 +24,8 @@ async function testInsert(tree, key, value, circuit, log ) {
|
||||
oldRoot: res.oldRoot,
|
||||
newRoot: res.newRoot,
|
||||
siblings: siblings,
|
||||
oldKey: res.oldKey,
|
||||
oldValue: res.oldValue,
|
||||
oldKey: res.isOld0 ? 0 : res.oldKey,
|
||||
oldValue: res.isOld0 ? 0 : res.oldValue,
|
||||
isOld0: res.isOld0 ? 1 : 0,
|
||||
newKey: key,
|
||||
newValue: value
|
||||
@@ -46,8 +46,8 @@ async function testDelete(tree, key, circuit) {
|
||||
oldRoot: res.oldRoot,
|
||||
newRoot: res.newRoot,
|
||||
siblings: siblings,
|
||||
oldKey: res.oldKey,
|
||||
oldValue: res.oldValue,
|
||||
oldKey: res.isOld0 ? 0 : res.oldKey,
|
||||
oldValue: res.isOld0 ? 0 : res.oldValue,
|
||||
isOld0: res.isOld0 ? 1 : 0,
|
||||
newKey: res.delKey,
|
||||
newValue: res.delValue
|
||||
@@ -214,12 +214,4 @@ describe("SMT test", function () {
|
||||
await testUpdate(tree1, 32, 323232, circuit);
|
||||
});
|
||||
|
||||
it("Should verify existance of an element", async () => {
|
||||
|
||||
});
|
||||
|
||||
it("Should verify non existance of an element", async () => {
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
95
test/smtverifier.js
Normal file
95
test/smtverifier.js
Normal file
@@ -0,0 +1,95 @@
|
||||
const chai = require("chai");
|
||||
const path = require("path");
|
||||
const snarkjs = require("snarkjs");
|
||||
const compiler = require("circom");
|
||||
|
||||
const smt = require("../src/smt.js");
|
||||
|
||||
const assert = chai.assert;
|
||||
|
||||
const bigInt = snarkjs.bigInt;
|
||||
|
||||
function print(circuit, w, s) {
|
||||
console.log(s + ": " + w[circuit.getSignalIdx(s)]);
|
||||
}
|
||||
|
||||
async function testInclusion(tree, key, circuit) {
|
||||
|
||||
const res = await tree.find(key);
|
||||
|
||||
assert(res.found);
|
||||
let siblings = res.siblings;
|
||||
while (siblings.length<10) siblings.push(bigInt(0));
|
||||
|
||||
const w = circuit.calculateWitness({
|
||||
fnc: 0,
|
||||
root: tree.root,
|
||||
siblings: siblings,
|
||||
oldKey: 0,
|
||||
oldValue: 0,
|
||||
isOld0: 0,
|
||||
key: key,
|
||||
value: res.foundValue
|
||||
});
|
||||
|
||||
assert(circuit.checkWitness(w));
|
||||
}
|
||||
|
||||
async function testExclusion(tree, key, circuit) {
|
||||
const res = await tree.find(key);
|
||||
|
||||
assert(!res.found);
|
||||
let siblings = res.siblings;
|
||||
while (siblings.length<10) siblings.push(bigInt(0));
|
||||
|
||||
const w = circuit.calculateWitness({
|
||||
fnc: 1,
|
||||
root: tree.root,
|
||||
siblings: siblings,
|
||||
oldKey: res.isOld0 ? 0 : res.notFoundKey,
|
||||
oldValue: res.isOld0 ? 0 : res.notFoundValue,
|
||||
isOld0: res.isOld0 ? 1 : 0,
|
||||
key: key,
|
||||
value: 0
|
||||
}, console.log);
|
||||
|
||||
assert(circuit.checkWitness(w));
|
||||
}
|
||||
|
||||
describe("SMT test", function () {
|
||||
let circuit;
|
||||
let tree;
|
||||
|
||||
this.timeout(100000);
|
||||
|
||||
before( async () => {
|
||||
const cirDef = await compiler(path.join(__dirname, "circuits", "smtverifier10_test.circom"));
|
||||
|
||||
circuit = new snarkjs.Circuit(cirDef);
|
||||
|
||||
console.log("NConstrains SMTVerifier: " + circuit.nConstraints);
|
||||
|
||||
tree = await smt.newMemEmptyTrie();
|
||||
await tree.insert(7,77);
|
||||
await tree.insert(8,88);
|
||||
await tree.insert(32,3232);
|
||||
});
|
||||
|
||||
it("Check inclussion in a tree of 3", async () => {
|
||||
await testInclusion(tree, 7, circuit);
|
||||
await testInclusion(tree, 8, circuit);
|
||||
await testInclusion(tree, 32, circuit);
|
||||
});
|
||||
|
||||
it("Check exclussion in a tree of 3", async () => {
|
||||
// await testExclusion(tree, 0, circuit);
|
||||
await testExclusion(tree, 6, 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); */
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user