pre 0.5 all working

This commit is contained in:
Jordi Baylina 2020-03-26 19:24:20 +01:00
parent 273ab79665
commit e240605642
No known key found for this signature in database
GPG Key ID: 7480C80C1BE43112
28 changed files with 2982 additions and 3500 deletions

@ -1,7 +1,4 @@
module.exports = { module.exports = {
"plugins": [
"mocha"
],
"env": { "env": {
"es6": true, "es6": true,
"node": true, "node": true,
@ -27,7 +24,6 @@ module.exports = {
"semi": [ "semi": [
"error", "error",
"always" "always"
], ]
"mocha/no-exclusive-tests": "error"
} }
}; };

6219
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -26,15 +26,15 @@
"dependencies": { "dependencies": {
"blake-hash": "^1.1.0", "blake-hash": "^1.1.0",
"blake2b": "^2.1.3", "blake2b": "^2.1.3",
"circom": "0.0.35", "circom": "0.5.2",
"fflib": "0.0.1", "ffjavascript": "0.0.3",
"snarkjs": "^0.1.20", "snarkjs": "^0.1.20",
"typedarray-to-buffer": "^3.1.5", "typedarray-to-buffer": "^3.1.5",
"web3": "^1.0.0-beta.55" "web3": "^1.2.6"
}, },
"devDependencies": { "devDependencies": {
"eslint-plugin-mocha": "^5.2.0", "eslint": "^6.8.0",
"ganache-cli": "^6.4.4", "ganache-cli": "^6.9.1",
"mocha": "^5.2.0" "mocha": "^5.2.0"
} }
} }

@ -1,5 +1,5 @@
const bigInt = require("big-integer"); const bigInt = require("big-integer");
const ZqField = require("fflib").ZqField; const ZqField = require("ffjavascript").ZqField;
const utils = require("./utils.js"); const utils = require("./utils.js");
exports.addPoint = addPoint; exports.addPoint = addPoint;

@ -1,5 +1,5 @@
const bigInt = require("big-integer"); const bigInt = require("big-integer");
const ZqField = require("fflib").ZqField; const ZqField = require("ffjavascript").ZqField;
const Web3Utils = require("web3-utils"); const Web3Utils = require("web3-utils");
const F = new ZqField(bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617")); const F = new ZqField(bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"));

@ -1,6 +1,6 @@
const bigInt = require("big-integer"); const bigInt = require("big-integer");
const Web3Utils = require("web3-utils"); const Web3Utils = require("web3-utils");
const ZqField = require("fflib").ZqField; const ZqField = require("ffjavascript").ZqField;
const F = new ZqField(bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617")); const F = new ZqField(bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"));
const SEED = "mimcsponge"; const SEED = "mimcsponge";

@ -1,7 +1,7 @@
const bigInt = require("big-integer"); const bigInt = require("big-integer");
const blake2b = require("blake2b"); const blake2b = require("blake2b");
const assert = require("assert"); const assert = require("assert");
const ZqField = require("fflib").ZqField; const ZqField = require("ffjavascript").ZqField;
const utils = require("./utils"); const utils = require("./utils");
const F = new ZqField(bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617")); const F = new ZqField(bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"));

@ -1,6 +1,5 @@
const chai = require("chai"); const chai = require("chai");
const path = require("path"); const path = require("path");
const compiler = require("circom");
const assert = chai.assert; const assert = chai.assert;
@ -37,23 +36,23 @@ describe("Aliascheck test", function () {
it("Satisfy the aliastest 0", async () => { it("Satisfy the aliastest 0", async () => {
const inp = getBits(bigInt.zero, 254); const inp = getBits(bigInt.zero, 254);
await cir.calculateWitness({in: inp}); await cir.calculateWitness({in: inp}, true);
}); });
it("Satisfy the aliastest 3", async () => { it("Satisfy the aliastest 3", async () => {
const inp = getBits(bigInt(3), 254); const inp = getBits(bigInt(3), 254);
await cir.calculateWitness({in: inp}); await cir.calculateWitness({in: inp}, true);
}); });
it("Satisfy the aliastest q-1", async () => { it("Satisfy the aliastest q-1", async () => {
const inp = getBits(q.minus(bigInt.one), 254); const inp = getBits(q.minus(bigInt.one), 254);
await cir.calculateWitness({in: inp}); await cir.calculateWitness({in: inp}, true);
}); });
it("Should not satisfy an input of q", async () => { it("Should not satisfy an input of q", async () => {
const inp = getBits(q, 254); const inp = getBits(q, 254);
try { try {
await cir.calculateWitness({in: inp}); await cir.calculateWitness({in: inp}, true);
assert(false); assert(false);
} catch(err) { } catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) ); assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );
@ -64,7 +63,7 @@ describe("Aliascheck test", function () {
const inp = getBits(bigInt(1).shiftLeft(254).minus(bigInt.one), 254); const inp = getBits(bigInt(1).shiftLeft(254).minus(bigInt.one), 254);
try { try {
await cir.calculateWitness({in: inp}); await cir.calculateWitness({in: inp}, true);
assert(false); assert(false);
} catch(err) { } catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) ); assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );

@ -34,7 +34,7 @@ describe("Baby Jub test", function () {
y2: bigInt(1) y2: bigInt(1)
}; };
const w = await circuitAdd.calculateWitness(input); const w = await circuitAdd.calculateWitness(input, true);
await circuitAdd.assertOut(w, {xout: bigInt(0), yout: bigInt(1)}); await circuitAdd.assertOut(w, {xout: bigInt(0), yout: bigInt(1)});
}); });
@ -48,7 +48,7 @@ describe("Baby Jub test", function () {
y2: bigInt("2626589144620713026669568689430873010625803728049924121243784502389097019475") y2: bigInt("2626589144620713026669568689430873010625803728049924121243784502389097019475")
}; };
const w = await circuitAdd.calculateWitness(input); const w = await circuitAdd.calculateWitness(input, true);
await circuitAdd.assertOut(w, { await circuitAdd.assertOut(w, {
xout: bigInt("6890855772600357754907169075114257697580319025794532037257385534741338397365"), xout: bigInt("6890855772600357754907169075114257697580319025794532037257385534741338397365"),
@ -66,7 +66,7 @@ describe("Baby Jub test", function () {
y2: bigInt("20819045374670962167435360035096875258406992893633759881276124905556507972311") y2: bigInt("20819045374670962167435360035096875258406992893633759881276124905556507972311")
}; };
const w = await circuitAdd.calculateWitness(input); const w = await circuitAdd.calculateWitness(input, true);
await circuitAdd.assertOut(w, { await circuitAdd.assertOut(w, {
xout: bigInt("7916061937171219682591368294088513039687205273691143098332585753343424131937"), xout: bigInt("7916061937171219682591368294088513039687205273691143098332585753343424131937"),
@ -75,15 +75,15 @@ describe("Baby Jub test", function () {
}); });
it("Should check (0,1) is a valid poiny", async() => { it("Should check (0,1) is a valid point", async() => {
const w = await circuitTest.calculateWitness({x: 0, y:1}); const w = await circuitTest.calculateWitness({x: 0, y:1}, true);
await circuitTest.checkConstraints(w); await circuitTest.checkConstraints(w);
}); });
it("Should check (1,0) is an invalid point", async() => { it("Should check (1,0) is an invalid point", async() => {
try { try {
await circuitTest.calculateWitness({x: 1, y: 0}); await circuitTest.calculateWitness({x: 1, y: 0}, true);
assert(false, "Should be a valid point"); assert(false, "Should be a valid point");
} catch(err) { } catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)168700\s!=\s1/.test(err.message) ); assert(/Constraint\sdoesn't\smatch(.*)168700\s!=\s1/.test(err.message) );
@ -102,7 +102,7 @@ describe("Baby Jub test", function () {
in : S in : S
}; };
const w = await circuitPbk.calculateWitness(input); const w = await circuitPbk.calculateWitness(input, true);
await circuitPbk.assertOut(w, {Ax : A[0], Ay: A[1]}); await circuitPbk.assertOut(w, {Ax : A[0], Ay: A[1]});

@ -12,7 +12,7 @@ async function checkSub(_a,_b, circuit) {
let b=bigInt(_b); let b=bigInt(_b);
if (a.lesser(bigInt.zero)) a = a.add(bigInt.one.shiftLeft(16)); if (a.lesser(bigInt.zero)) a = a.add(bigInt.one.shiftLeft(16));
if (b.lesser(bigInt.zero)) b = b.add(bigInt.one.shiftLeft(16)); if (b.lesser(bigInt.zero)) b = b.add(bigInt.one.shiftLeft(16));
const w = await circuit.calculateWitness({a: a, b: b}); const w = await circuit.calculateWitness({a: a, b: b}, true);
let res = a.minus(b); let res = a.minus(b);
if (res.lesser(bigInt.zero)) res = res.add(bigInt.one.shiftLeft(16)); if (res.lesser(bigInt.zero)) res = res.add(bigInt.one.shiftLeft(16));

@ -15,9 +15,10 @@ describe("Binary sum test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "constants_test.circom")); const circuit = await tester(path.join(__dirname, "circuits", "constants_test.circom"));
await circuit.loadConstraints(); await circuit.loadConstraints();
assert.equal(circuit.nWires, 2); assert.equal(circuit.nVars, 2);
assert.equal(circuit.constraints.length, 1);
const witness = await circuit.calculateWitness({ "in": bigInt("d807aa98", 16)}); const witness = await circuit.calculateWitness({ "in": bigInt("d807aa98", 16)}, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt("d807aa98", 16))); assert(witness[1].equals(bigInt("d807aa98", 16)));
@ -26,9 +27,9 @@ describe("Binary sum test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "sum_test.circom")); const circuit = await tester(path.join(__dirname, "circuits", "sum_test.circom"));
await circuit.loadConstraints(); await circuit.loadConstraints();
assert.equal(circuit.nWires, 97); // 32 (in1) + 32(in2) + 32(out) + 1 (carry) assert.equal(circuit.constraints.length, 97); // 32 (in1) + 32(in2) + 32(out) + 1 (carry)
const witness = await circuit.calculateWitness({ "a": "111", "b": "222" }); const witness = await circuit.calculateWitness({ "a": "111", "b": "222" }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt("333"))); assert(witness[1].equals(bigInt("333")));

@ -15,11 +15,11 @@ describe("Comparators test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "iszero.circom")); const circuit = await tester(path.join(__dirname, "circuits", "iszero.circom"));
let witness; let witness;
witness = await circuit.calculateWitness({ "in": 111}); witness = await circuit.calculateWitness({ "in": 111}, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": 0 }); witness = await circuit.calculateWitness({ "in": 0 }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
}); });
@ -27,11 +27,11 @@ describe("Comparators test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "isequal.circom")); const circuit = await tester(path.join(__dirname, "circuits", "isequal.circom"));
let witness; let witness;
witness = await circuit.calculateWitness({ "in": [111,222] }); witness = await circuit.calculateWitness({ "in": [111,222] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [444,444] }); witness = await circuit.calculateWitness({ "in": [444,444] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
}); });
@ -39,35 +39,35 @@ describe("Comparators test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "lessthan.circom")); const circuit = await tester(path.join(__dirname, "circuits", "lessthan.circom"));
let witness; let witness;
witness = await circuit.calculateWitness({ "in": [333,444] }); witness = await circuit.calculateWitness({ "in": [333,444] }), true;
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in":[1,1] }); witness = await circuit.calculateWitness({ "in":[1,1] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [661, 660] }); witness = await circuit.calculateWitness({ "in": [661, 660] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [0, 1] }); witness = await circuit.calculateWitness({ "in": [0, 1] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [0, 444] }); witness = await circuit.calculateWitness({ "in": [0, 444] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [1, 0] }); witness = await circuit.calculateWitness({ "in": [1, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [555, 0] }); witness = await circuit.calculateWitness({ "in": [555, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [0, 0] }); witness = await circuit.calculateWitness({ "in": [0, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
}); });
@ -76,35 +76,35 @@ describe("Comparators test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "lesseqthan.circom")); const circuit = await tester(path.join(__dirname, "circuits", "lesseqthan.circom"));
let witness; let witness;
witness = await circuit.calculateWitness({ "in": [333,444] }); witness = await circuit.calculateWitness({ "in": [333,444] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in":[1,1] }); witness = await circuit.calculateWitness({ "in":[1,1] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [661, 660] }); witness = await circuit.calculateWitness({ "in": [661, 660] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [0, 1] }); witness = await circuit.calculateWitness({ "in": [0, 1] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [0, 444] }); witness = await circuit.calculateWitness({ "in": [0, 444] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [1, 0] }); witness = await circuit.calculateWitness({ "in": [1, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [555, 0] }); witness = await circuit.calculateWitness({ "in": [555, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [0, 0] }); witness = await circuit.calculateWitness({ "in": [0, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
}); });
@ -113,35 +113,35 @@ describe("Comparators test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "greaterthan.circom")); const circuit = await tester(path.join(__dirname, "circuits", "greaterthan.circom"));
let witness; let witness;
witness = await circuit.calculateWitness({ "in": [333,444] }); witness = await circuit.calculateWitness({ "in": [333,444] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in":[1,1] }); witness = await circuit.calculateWitness({ "in":[1,1] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [661, 660] }); witness = await circuit.calculateWitness({ "in": [661, 660] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [0, 1] }); witness = await circuit.calculateWitness({ "in": [0, 1] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [0, 444] }); witness = await circuit.calculateWitness({ "in": [0, 444] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [1, 0] }); witness = await circuit.calculateWitness({ "in": [1, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [555, 0] }); witness = await circuit.calculateWitness({ "in": [555, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [0, 0] }); witness = await circuit.calculateWitness({ "in": [0, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
}); });
@ -149,35 +149,35 @@ describe("Comparators test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "greatereqthan.circom")); const circuit = await tester(path.join(__dirname, "circuits", "greatereqthan.circom"));
let witness; let witness;
witness = await circuit.calculateWitness({ "in": [333,444] }); witness = await circuit.calculateWitness({ "in": [333,444] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in":[1,1] }); witness = await circuit.calculateWitness({ "in":[1,1] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [661, 660] }); witness = await circuit.calculateWitness({ "in": [661, 660] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [0, 1] }); witness = await circuit.calculateWitness({ "in": [0, 1] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [0, 444] }); witness = await circuit.calculateWitness({ "in": [0, 444] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(0))); assert(witness[1].equals(bigInt(0)));
witness = await circuit.calculateWitness({ "in": [1, 0] }); witness = await circuit.calculateWitness({ "in": [1, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [555, 0] }); witness = await circuit.calculateWitness({ "in": [555, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
witness = await circuit.calculateWitness({ "in": [0, 0] }); witness = await circuit.calculateWitness({ "in": [0, 0] }, true);
assert(witness[0].equals(bigInt(1))); assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(1))); assert(witness[1].equals(bigInt(1)));
}); });

@ -60,7 +60,7 @@ describe("EdDSA test", function () {
const sBits = buffer2bits(pSignature.slice(32, 64)); const sBits = buffer2bits(pSignature.slice(32, 64));
const aBits = buffer2bits(pPubKey); const aBits = buffer2bits(pPubKey);
const w = await circuit.calculateWitness({A: aBits, R8: r8Bits, S: sBits, msg: msgBits}); const w = await circuit.calculateWitness({A: aBits, R8: r8Bits, S: sBits, msg: msgBits}, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
}); });

@ -35,7 +35,7 @@ describe("EdDSA MiMC test", function () {
R8x: signature.R8[0], R8x: signature.R8[0],
R8y: signature.R8[1], R8y: signature.R8[1],
S: signature.S, S: signature.S,
M: msg}); M: msg}, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
@ -61,7 +61,7 @@ describe("EdDSA MiMC test", function () {
R8x: signature.R8[0].add(bigInt(1)), R8x: signature.R8[0].add(bigInt(1)),
R8y: signature.R8[1], R8y: signature.R8[1],
S: signature.S, S: signature.S,
M: msg}); M: msg}, true);
assert(false); assert(false);
} catch(err) { } catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) ); assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );
@ -88,7 +88,7 @@ describe("EdDSA MiMC test", function () {
R8x: signature.R8[0].add(bigInt(1)), R8x: signature.R8[0].add(bigInt(1)),
R8y: signature.R8[1], R8y: signature.R8[1],
S: signature.S, S: signature.S,
M: msg}); M: msg}, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);

@ -2,7 +2,6 @@ const chai = require("chai");
const path = require("path"); const path = require("path");
const bigInt = require("big-integer"); const bigInt = require("big-integer");
const tester = require("circom").tester; const tester = require("circom").tester;
const utils = require("../src/utils");
const eddsa = require("../src/eddsa.js"); const eddsa = require("../src/eddsa.js");
@ -42,7 +41,7 @@ describe("EdDSA Poseidon test", function () {
// console.log(JSON.stringify(utils.stringifyBigInts(input))); // console.log(JSON.stringify(utils.stringifyBigInts(input)));
const w = await circuit.calculateWitness(input); const w = await circuit.calculateWitness(input, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
}); });
@ -66,7 +65,7 @@ describe("EdDSA Poseidon test", function () {
R8x: signature.R8[0].add(bigInt(1)), R8x: signature.R8[0].add(bigInt(1)),
R8y: signature.R8[1], R8y: signature.R8[1],
S: signature.S, S: signature.S,
M: msg}); M: msg}, true);
assert(false); assert(false);
} catch(err) { } catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) ); assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );
@ -93,7 +92,7 @@ describe("EdDSA Poseidon test", function () {
R8x: signature.R8[0].add(bigInt(1)), R8x: signature.R8[0].add(bigInt(1)),
R8y: signature.R8[1], R8y: signature.R8[1],
S: signature.S, S: signature.S,
M: msg}); M: msg}, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
}); });

@ -27,7 +27,7 @@ describe("Escalarmul test", function () {
await circuitEMulAny.checkConstraints(w); await circuitEMulAny.checkConstraints(w);
await circuitEMulAny.assertOut(w, {out: g}); await circuitEMulAny.assertOut(w, {out: g}, true);
}); });
@ -38,7 +38,7 @@ describe("Escalarmul test", function () {
await circuitEMulAny.checkConstraints(w); await circuitEMulAny.checkConstraints(w);
await circuitEMulAny.assertOut(w, {out: [0,1]}); await circuitEMulAny.assertOut(w, {out: [0,1]}, true);
}); });

@ -25,13 +25,13 @@ describe("Escalarmul test", function () {
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
await circuit.assertOut(w, {out: [0,1]}); await circuit.assertOut(w, {out: [0,1]}, true);
}); });
it("Should generate Same escalar mul", async () => { it("Should generate Same escalar mul", async () => {
const w = await circuit.calculateWitness({"e": 1}); const w = await circuit.calculateWitness({"e": 1}, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
@ -47,7 +47,7 @@ describe("Escalarmul test", function () {
bigInt("16950150798460657717958625567821834550301663161624707787222815936182638968203") bigInt("16950150798460657717958625567821834550301663161624707787222815936182638968203")
]; ];
const w = await circuit.calculateWitness({"e": s}); const w = await circuit.calculateWitness({"e": s}, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
@ -67,7 +67,7 @@ describe("Escalarmul test", function () {
for (let i=0; i<50; i++) { for (let i=0; i<50; i++) {
const s = bigInt(i); const s = bigInt(i);
const w = await circuit.calculateWitness({"e": s}); const w = await circuit.calculateWitness({"e": s}, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
@ -79,7 +79,7 @@ describe("Escalarmul test", function () {
it("If multiply by order should return 0", async () => { it("If multiply by order should return 0", async () => {
const w = await circuit.calculateWitness({"e": babyjub.subOrder }); const w = await circuit.calculateWitness({"e": babyjub.subOrder }, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);

@ -14,7 +14,7 @@ describe("MiMC Circuit test", function () {
}); });
it("Should check constrain", async () => { it("Should check constrain", async () => {
const w = await circuit.calculateWitness({x_in: 1, k: 2}); const w = await circuit.calculateWitness({x_in: 1, k: 2}, true);
const res2 = mimcjs.hash(1,2,91); const res2 = mimcjs.hash(1,2,91);

@ -33,17 +33,17 @@ describe("Montgomery test", function () {
it("Convert Edwards to Montgomery and back again", async () => { it("Convert Edwards to Montgomery and back again", async () => {
let w, xout, yout; let w, xout, yout;
w = await circuitE2M.calculateWitness({ in: g}); w = await circuitE2M.calculateWitness({ in: g}, true);
xout = w[circuitE2M.symbols["main.out[0]"].idxWit]; xout = w[circuitE2M.symbols["main.out[0]"].varIdx];
yout = w[circuitE2M.symbols["main.out[1]"].idxWit]; yout = w[circuitE2M.symbols["main.out[1]"].varIdx];
mg = [xout, yout]; mg = [xout, yout];
w = await circuitM2E.calculateWitness({ in: [xout, yout]}); w = await circuitM2E.calculateWitness({ in: [xout, yout]}, true);
xout = w[circuitM2E.symbols["main.out[0]"].idxWit]; xout = w[circuitM2E.symbols["main.out[0]"].varIdx];
yout = w[circuitM2E.symbols["main.out[1]"].idxWit]; yout = w[circuitM2E.symbols["main.out[1]"].varIdx];
assert(xout.equals(g[0])); assert(xout.equals(g[0]));
assert(yout.equals(g[1])); assert(yout.equals(g[1]));
@ -53,17 +53,17 @@ describe("Montgomery test", function () {
g2 = babyJub.addPoint(g,g); g2 = babyJub.addPoint(g,g);
w = await circuitMDouble.calculateWitness({ in: mg}); w = await circuitMDouble.calculateWitness({ in: mg}, true);
xout = w[circuitE2M.symbols["main.out[0]"].idxWit]; xout = w[circuitE2M.symbols["main.out[0]"].varIdx];
yout = w[circuitE2M.symbols["main.out[1]"].idxWit]; yout = w[circuitE2M.symbols["main.out[1]"].varIdx];
mg2 = [xout, yout]; mg2 = [xout, yout];
w = await circuitM2E.calculateWitness({ in: mg2}); w = await circuitM2E.calculateWitness({ in: mg2}, true);
xout = w[circuitM2E.symbols["main.out[0]"].idxWit]; xout = w[circuitM2E.symbols["main.out[0]"].varIdx];
yout = w[circuitM2E.symbols["main.out[1]"].idxWit]; yout = w[circuitM2E.symbols["main.out[1]"].varIdx];
assert(xout.equals(g2[0])); assert(xout.equals(g2[0]));
assert(yout.equals(g2[1])); assert(yout.equals(g2[1]));
@ -73,17 +73,17 @@ describe("Montgomery test", function () {
g3 = babyJub.addPoint(g,g2); g3 = babyJub.addPoint(g,g2);
w = await circuitMAdd.calculateWitness({ in1: mg, in2: mg2}); w = await circuitMAdd.calculateWitness({ in1: mg, in2: mg2}, true);
xout = w[circuitMAdd.symbols["main.out[0]"].idxWit]; xout = w[circuitMAdd.symbols["main.out[0]"].varIdx];
yout = w[circuitMAdd.symbols["main.out[1]"].idxWit]; yout = w[circuitMAdd.symbols["main.out[1]"].varIdx];
mg3 = [xout, yout]; mg3 = [xout, yout];
w = await circuitM2E.calculateWitness({ in: mg3}); w = await circuitM2E.calculateWitness({ in: mg3}, true);
xout = w[circuitM2E.symbols["main.out[0]"].idxWit]; xout = w[circuitM2E.symbols["main.out[0]"].varIdx];
yout = w[circuitM2E.symbols["main.out[1]"].idxWit]; yout = w[circuitM2E.symbols["main.out[1]"].varIdx];
assert(xout.equals(g3[0])); assert(xout.equals(g3[0]));
assert(yout.equals(g3[1])); assert(yout.equals(g3[1]));

@ -28,7 +28,7 @@ describe("Mux4 test", function() {
]; ];
for (let i=0; i<16; i++) { for (let i=0; i<16; i++) {
const w = await circuit.calculateWitness({ "selector": i }); const w = await circuit.calculateWitness({ "selector": i }, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
@ -52,7 +52,7 @@ describe("Mux4 test", function() {
]; ];
for (let i=0; i<8; i++) { for (let i=0; i<8; i++) {
const w = await circuit.calculateWitness({ "selector": i }); const w = await circuit.calculateWitness({ "selector": i }, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
@ -71,7 +71,7 @@ describe("Mux4 test", function() {
]; ];
for (let i=0; i<4; i++) { for (let i=0; i<4; i++) {
const w = await circuit.calculateWitness({ "selector": i }); const w = await circuit.calculateWitness({ "selector": i }, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
@ -88,7 +88,7 @@ describe("Mux4 test", function() {
]; ];
for (let i=0; i<2; i++) { for (let i=0; i<2; i++) {
const w = await circuit.calculateWitness({ "selector": i }); const w = await circuit.calculateWitness({ "selector": i }, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);

@ -27,7 +27,7 @@ describe("Double Pedersen test", function() {
let w; let w;
w = await circuit.calculateWitness({ in: ["0", "0"]}); w = await circuit.calculateWitness({ in: ["0", "0"]}, true);
await circuit.assertOut(w, {out: [0,1]}); await circuit.assertOut(w, {out: [0,1]});
@ -35,7 +35,7 @@ describe("Double Pedersen test", function() {
it("Should pedersen at one first generator", async () => { it("Should pedersen at one first generator", async () => {
let w; let w;
w = await circuit.calculateWitness({ in: ["1", "0"]}); w = await circuit.calculateWitness({ in: ["1", "0"]}, true);
await circuit.assertOut(w, {out: PBASE[0]}); await circuit.assertOut(w, {out: PBASE[0]});
@ -43,14 +43,14 @@ describe("Double Pedersen test", function() {
it("Should pedersen at one second generator", async () => { it("Should pedersen at one second generator", async () => {
let w; let w;
w = await circuit.calculateWitness({ in: ["0", "1"]}); w = await circuit.calculateWitness({ in: ["0", "1"]}, true);
await circuit.assertOut(w, {out: PBASE[1]}); await circuit.assertOut(w, {out: PBASE[1]});
}); });
it("Should pedersen at mixed generators", async () => { it("Should pedersen at mixed generators", async () => {
let w; let w;
w = await circuit.calculateWitness({ in: ["3", "7"]}); w = await circuit.calculateWitness({ in: ["3", "7"]}, true);
const r = babyJub.addPoint( const r = babyJub.addPoint(
babyJub.mulPointEscalar(PBASE[0], 3), babyJub.mulPointEscalar(PBASE[0], 3),
@ -64,7 +64,7 @@ describe("Double Pedersen test", function() {
let w; let w;
const allOnes = bigInt("1").shiftLeft(250).minus(bigInt("1")); const allOnes = bigInt("1").shiftLeft(250).minus(bigInt("1"));
w = await circuit.calculateWitness({ in: [allOnes, allOnes]}); w = await circuit.calculateWitness({ in: [allOnes, allOnes]}, true);
const r2 = babyJub.addPoint( const r2 = babyJub.addPoint(

@ -18,7 +18,7 @@ describe("Pedersen test", function() {
let w; let w;
w = await circuit.calculateWitness({ in: 0}); w = await circuit.calculateWitness({ in: 0}, true);
const b = Buffer.alloc(32); const b = Buffer.alloc(32);
@ -34,7 +34,7 @@ describe("Pedersen test", function() {
const n = bigInt.one.shiftLeft(253).minus(bigInt.one); const n = bigInt.one.shiftLeft(253).minus(bigInt.one);
w = await circuit.calculateWitness({ in: n}); w = await circuit.calculateWitness({ in: n}, true);
const b = Buffer.alloc(32); const b = Buffer.alloc(32);
for (let i=0; i<31; i++) b[i] = 0xFF; for (let i=0; i<31; i++) b[i] = 0xFF;

@ -11,12 +11,12 @@ describe("Point 2 bits test", function() {
circuit = await tester(path.join(__dirname, "circuits", "pointbits_loopback.circom")); circuit = await tester(path.join(__dirname, "circuits", "pointbits_loopback.circom"));
}); });
it("Should do the both convertions for 8Base", async () => { it("Should do the both convertions for 8Base", async () => {
const w = await circuit.calculateWitness({ in: babyJub.Base8}); const w = await circuit.calculateWitness({ in: babyJub.Base8}, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
}); });
it("Should do the both convertions for Zero point", async () => { it("Should do the both convertions for Zero point", async () => {
const w = await circuit.calculateWitness({ in: [0, 1]}); const w = await circuit.calculateWitness({ in: [0, 1]}, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
}); });

@ -28,7 +28,7 @@ describe("Poseidon Circuit test", function () {
}); });
it("Should check constrain of hash([1, 2])", async () => { it("Should check constrain of hash([1, 2])", async () => {
const w = await circuit.calculateWitness({inputs: [1, 2]}); const w = await circuit.calculateWitness({inputs: [1, 2]}, true);
const hash = poseidon.createHash(6, 8, 57); const hash = poseidon.createHash(6, 8, 57);
@ -41,7 +41,7 @@ describe("Poseidon Circuit test", function () {
}); });
it("Should check constrain of hash([3, 4])", async () => { it("Should check constrain of hash([3, 4])", async () => {
const w = await circuit.calculateWitness({inputs: [3, 4]}); const w = await circuit.calculateWitness({inputs: [3, 4]}, true);
const hash = poseidon.createHash(6, 8, 57); const hash = poseidon.createHash(6, 8, 57);

@ -46,13 +46,13 @@ describe("SHA256 test", function () {
const a = buffer2bitArray(b); const a = buffer2bitArray(b);
const b2 = bitArray2buffer(a); const b2 = bitArray2buffer(a);
assert.equal(b.toString("hex"), b2.toString("hex")); assert.equal(b.toString("hex"), b2.toString("hex"), true);
}); });
it("Should calculate a hash of 1 compressor", async () => { it("Should calculate a hash of 1 compressor", async () => {
const cir = await tester(path.join(__dirname, "circuits", "sha256_2_test.circom")); const cir = await tester(path.join(__dirname, "circuits", "sha256_2_test.circom"));
const witness = await cir.calculateWitness({ "a": "1", "b": "2" }); const witness = await cir.calculateWitness({ "a": "1", "b": "2" }, true);
const b = new Buffer.alloc(54); const b = new Buffer.alloc(54);
b[26] = 1; b[26] = 1;
@ -83,7 +83,7 @@ describe("SHA256 test", function () {
.digest("hex"); .digest("hex");
const arrIn = buffer2bitArray(b); const arrIn = buffer2bitArray(b);
const witness = await cir.calculateWitness({ "in": arrIn }); const witness = await cir.calculateWitness({ "in": arrIn }, true);
const arrOut = witness.slice(1, 257); const arrOut = witness.slice(1, 257);
const hash2 = bitArray2buffer(arrOut).toString("hex"); const hash2 = bitArray2buffer(arrOut).toString("hex");
@ -104,7 +104,7 @@ describe("SHA256 test", function () {
const arrIn = buffer2bitArray(b); const arrIn = buffer2bitArray(b);
const witness = await cir.calculateWitness({ "in": arrIn }); const witness = await cir.calculateWitness({ "in": arrIn }, true);
const arrOut = witness.slice(1, 257); const arrOut = witness.slice(1, 257);
const hash2 = bitArray2buffer(arrOut).toString("hex"); const hash2 = bitArray2buffer(arrOut).toString("hex");

@ -30,49 +30,49 @@ describe("Sign test", function() {
it("Sign of 0", async () => { it("Sign of 0", async () => {
const inp = getBits(bigInt.zero, 254); const inp = getBits(bigInt.zero, 254);
const w = await circuit.calculateWitness({in: inp}); const w = await circuit.calculateWitness({in: inp}, true);
await circuit.assertOut(w, {sign: 0}); await circuit.assertOut(w, {sign: 0});
}); });
it("Sign of 3", async () => { it("Sign of 3", async () => {
const inp = getBits(bigInt(3), 254); const inp = getBits(bigInt(3), 254);
const w = await circuit.calculateWitness({in: inp}); const w = await circuit.calculateWitness({in: inp}, true);
await circuit.assertOut(w, {sign: 0}); await circuit.assertOut(w, {sign: 0});
}); });
it("Sign of q/2", async () => { it("Sign of q/2", async () => {
const inp = getBits(q.shiftRight(bigInt.one), 254); const inp = getBits(q.shiftRight(bigInt.one), 254);
const w = await circuit.calculateWitness({in: inp}); const w = await circuit.calculateWitness({in: inp}, true);
await circuit.assertOut(w, {sign: 0}); await circuit.assertOut(w, {sign: 0});
}); });
it("Sign of q/2+1", async () => { it("Sign of q/2+1", async () => {
const inp = getBits(q.shiftRight(bigInt.one).add(bigInt.one), 254); const inp = getBits(q.shiftRight(bigInt.one).add(bigInt.one), 254);
const w = await circuit.calculateWitness({in: inp}); const w = await circuit.calculateWitness({in: inp}, true);
await circuit.assertOut(w, {sign: 1}); await circuit.assertOut(w, {sign: 1});
}); });
it("Sign of q-1", async () => { it("Sign of q-1", async () => {
const inp = getBits(q.minus(bigInt.one), 254); const inp = getBits(q.minus(bigInt.one), 254);
const w = await circuit.calculateWitness({in: inp}); const w = await circuit.calculateWitness({in: inp}, true);
await circuit.assertOut(w, {sign: 1}); await circuit.assertOut(w, {sign: 1});
}); });
it("Sign of q", async () => { it("Sign of q", async () => {
const inp = getBits(q, 254); const inp = getBits(q, 254);
const w = await circuit.calculateWitness({in: inp}); const w = await circuit.calculateWitness({in: inp}, true);
await circuit.assertOut(w, {sign: 1}); await circuit.assertOut(w, {sign: 1});
}); });
it("Sign of all ones", async () => { it("Sign of all ones", async () => {
const inp = getBits(bigInt(1).shiftLeft(254).minus(bigInt(1)), 254); const inp = getBits(bigInt(1).shiftLeft(254).minus(bigInt(1)), 254);
const w = await circuit.calculateWitness({in: inp}); const w = await circuit.calculateWitness({in: inp}, true);
await circuit.assertOut(w, {sign: 1}); await circuit.assertOut(w, {sign: 1});
}); });

@ -11,7 +11,7 @@ function print(circuit, w, s) {
console.log(s + ": " + w[circuit.getSignalIdx(s)]); console.log(s + ": " + w[circuit.getSignalIdx(s)]);
} }
async function testInsert(tree, key, value, circuit, log ) { async function testInsert(tree, key, value, circuit ) {
const res = await tree.insert(key,value); const res = await tree.insert(key,value);
let siblings = res.siblings; let siblings = res.siblings;
@ -26,7 +26,7 @@ async function testInsert(tree, key, value, circuit, log ) {
isOld0: res.isOld0 ? 1 : 0, isOld0: res.isOld0 ? 1 : 0,
newKey: key, newKey: key,
newValue: value newValue: value
}, log); }, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
@ -48,7 +48,7 @@ async function testDelete(tree, key, circuit) {
isOld0: res.isOld0 ? 1 : 0, isOld0: res.isOld0 ? 1 : 0,
newKey: res.delKey, newKey: res.delKey,
newValue: res.delValue newValue: res.delValue
}); }, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);
@ -182,8 +182,8 @@ describe("SMT Processor test", function () {
newValue: 77 newValue: 77
}); });
const root1 = w[circuit.symbols["main.oldRoot"].idxWit]; const root1 = w[circuit.symbols["main.oldRoot"].varIdx];
const root2 = w[circuit.symbols["main.newRoot"].idxWit]; const root2 = w[circuit.symbols["main.newRoot"].varIdx];
await circuit.checkConstraints(w); await circuit.checkConstraints(w);

@ -29,7 +29,7 @@ async function testInclusion(tree, key, circuit) {
isOld0: 0, isOld0: 0,
key: key, key: key,
value: res.foundValue value: res.foundValue
}); }, true);
await circuit.checkConstraints(w); await circuit.checkConstraints(w);