Skip to content

Commit

Permalink
Merge branch 'circom2' of github.com:iden3/circomlib into circom2
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaylina committed Oct 6, 2021
2 parents 31d892d + c528e8e commit a0cec75
Show file tree
Hide file tree
Showing 24 changed files with 68 additions and 69 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"dependencies": {
"blake-hash": "^1.1.0",
"blake2b": "^2.1.3",
"circom": "0.5.33",
"ffjavascript": "0.2.38",
"snarkjs": "^0.4.7",
"web3-utils": "^1.3.0"
Expand Down
2 changes: 1 addition & 1 deletion test/aliascheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Aliascheck test", function () {
let cir;
before( async() => {

cir = await wasm_tester(path.join(__dirname, "circuits", "aliascheck_test.circom"));
cir = await wasm_wasm_tester(path.join(__dirname, "circuits", "aliascheck_test.circom"));
});

it("Satisfy the aliastest 0", async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/babyjub.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const F = require("circomlibjs").babyjub.F;

const assert = chai.assert;

const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;
const utils = require("ffjavascript").utils;
const Scalar = require("ffjavascript").Scalar;

Expand All @@ -19,11 +19,11 @@ describe("Baby Jub test", function () {
this.timeout(100000);

before( async() => {
circuitAdd = await tester(path.join(__dirname, "circuits", "babyadd_tester.circom"));
circuitAdd = await wasm_tester(path.join(__dirname, "circuits", "babyadd_tester.circom"));

circuitTest = await tester(path.join(__dirname, "circuits", "babycheck_test.circom"));
circuitTest = await wasm_tester(path.join(__dirname, "circuits", "babycheck_test.circom"));

circuitPbk = await tester(path.join(__dirname, "circuits", "babypbk_test.circom"));
circuitPbk = await wasm_tester(path.join(__dirname, "circuits", "babypbk_test.circom"));
});

it("Should add point (0,1) and (0,1)", async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/binsub.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require("path");

const Scalar = require("ffjavascript").Scalar;
const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;

function print(circuit, w, s) {
console.log(s + ": " + w[circuit.getSignalIdx(s)]);
Expand All @@ -26,7 +26,7 @@ describe("BinSub test", function () {

let circuit;
before( async() => {
circuit = await tester(path.join(__dirname, "circuits", "binsub_test.circom"));
circuit = await wasm_tester(path.join(__dirname, "circuits", "binsub_test.circom"));
});

it("Should check variuos ege cases", async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/binsum.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const chai = require("chai");
const path = require("path");

const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;

const F1Field = require("ffjavascript").F1Field;
const Scalar = require("ffjavascript").Scalar;
Expand All @@ -14,7 +14,7 @@ describe("Binary sum test", function () {
this.timeout(100000000);

it("Should create a constant circuit", async () => {
const circuit = await tester(path.join(__dirname, "circuits", "constants_test.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "constants_test.circom"));
await circuit.loadConstraints();

assert.equal(circuit.nVars, 2);
Expand All @@ -26,7 +26,7 @@ describe("Binary sum test", function () {
assert(Fr.eq(Fr.e(witness[1]),Fr.e("0xd807aa98")));
});
it("Should create a sum circuit", async () => {
const circuit = await tester(path.join(__dirname, "circuits", "sum_test.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "sum_test.circom"));
await circuit.loadConstraints();

assert.equal(circuit.constraints.length, 97); // 32 (in1) + 32(in2) + 32(out) + 1 (carry)
Expand Down
14 changes: 7 additions & 7 deletions test/comparators.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Scalar = require("ffjavascript").Scalar;
exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
const Fr = new F1Field(exports.p);

const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;

const assert = chai.assert;

Expand All @@ -14,7 +14,7 @@ describe("Comparators test", function () {
this.timeout(100000);

it("Should create a iszero circuit", async() => {
const circuit = await tester(path.join(__dirname, "circuits", "iszero.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "iszero.circom"));

let witness;
witness = await circuit.calculateWitness({ "in": 111}, true);
Expand All @@ -26,7 +26,7 @@ describe("Comparators test", function () {
assert(Fr.eq(Fr.e(witness[1]), Fr.e(1)));
});
it("Should create a isequal circuit", async() => {
const circuit = await tester(path.join(__dirname, "circuits", "isequal.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "isequal.circom"));

let witness;
witness = await circuit.calculateWitness({ "in": [111,222] }, true);
Expand All @@ -39,7 +39,7 @@ describe("Comparators test", function () {
assert(Fr.eq(Fr.e(witness[1]), Fr.e(1)));
});
it("Should create a comparison lessthan", async() => {
const circuit = await tester(path.join(__dirname, "circuits", "lessthan.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "lessthan.circom"));

let witness;
witness = await circuit.calculateWitness({ "in": [333,444] }), true;
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("Comparators test", function () {
});
it("Should create a comparison lesseqthan", async() => {

const circuit = await tester(path.join(__dirname, "circuits", "lesseqthan.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "lesseqthan.circom"));

let witness;
witness = await circuit.calculateWitness({ "in": [333,444] }, true);
Expand Down Expand Up @@ -113,7 +113,7 @@ describe("Comparators test", function () {
});
it("Should create a comparison greaterthan", async() => {

const circuit = await tester(path.join(__dirname, "circuits", "greaterthan.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "greaterthan.circom"));

let witness;
witness = await circuit.calculateWitness({ "in": [333,444] }, true);
Expand Down Expand Up @@ -149,7 +149,7 @@ describe("Comparators test", function () {
assert(Fr.eq(Fr.e(witness[1]), Fr.e(0)));
});
it("Should create a comparison greatereqthan", async() => {
const circuit = await tester(path.join(__dirname, "circuits", "greatereqthan.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "greatereqthan.circom"));

let witness;
witness = await circuit.calculateWitness({ "in": [333,444] }, true);
Expand Down
4 changes: 2 additions & 2 deletions test/eddsa.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const chai = require("chai");
const path = require("path");

const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;

const eddsa = require("circomlibjs").eddsa;
const babyJub = require("circomlibjs").babyjub;
Expand Down Expand Up @@ -38,7 +38,7 @@ describe("EdDSA test", function () {
this.timeout(100000);

before( async () => {
circuit = await tester(path.join(__dirname, "circuits", "eddsa_test.circom"));
circuit = await wasm_tester(path.join(__dirname, "circuits", "eddsa_test.circom"));
});

it("Sign a single 10 bytes from 0 to 9", async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/eddsamimc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const chai = require("chai");
const path = require("path");
const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;

const eddsa = require("circomlibjs").eddsa;
const F1Field = require("ffjavascript").F1Field;
Expand All @@ -16,7 +16,7 @@ describe("EdDSA MiMC test", function () {
this.timeout(100000);

before( async () => {
circuit = await tester(path.join(__dirname, "circuits", "eddsamimc_test.circom"));
circuit = await wasm_tester(path.join(__dirname, "circuits", "eddsamimc_test.circom"));
});

it("Sign a single number", async () => {
Expand Down Expand Up @@ -66,7 +66,7 @@ describe("EdDSA MiMC test", function () {
M: msg}, true);
assert(false);
} catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );
assert(err.message.includes("Assert Failed"));
}
});

Expand Down
6 changes: 3 additions & 3 deletions test/eddsaposeidon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const chai = require("chai");
const path = require("path");
const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;

const eddsa = require("circomlibjs").eddsa;
const F1Field = require("ffjavascript").F1Field;
Expand All @@ -16,7 +16,7 @@ describe("EdDSA Poseidon test", function () {
this.timeout(100000);

before( async () => {
circuit = await tester(path.join(__dirname, "circuits", "eddsaposeidon_test.circom"));
circuit = await wasm_tester(path.join(__dirname, "circuits", "eddsaposeidon_test.circom"));
});

it("Sign a single number", async () => {
Expand Down Expand Up @@ -69,7 +69,7 @@ describe("EdDSA Poseidon test", function () {
M: msg}, true);
assert(false);
} catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );
assert(err.message.includes("Assert Failed"));
}
});

Expand Down
10 changes: 5 additions & 5 deletions test/escalarmul.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const chai = require("chai");
const path = require("path");
const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;
const babyJub = require("circomlibjs").babyjub;

const F1Field = require("ffjavascript").F1Field;
Expand All @@ -19,7 +19,7 @@ describe("Exponentioation test", function () {

it("Should generate the Exponentiation table in k=0", async () => {

const circuit = await tester(path.join(__dirname, "circuits", "escalarmulw4table_test.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "escalarmulw4table_test.circom"));

const w = await circuit.calculateWitness({in: 1});

Expand All @@ -46,7 +46,7 @@ describe("Exponentioation test", function () {

it("Should generate the Exponentiation table in k=3", async () => {

const circuit = await tester(path.join(__dirname, "circuits", "escalarmulw4table_test3.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "escalarmulw4table_test3.circom"));

const w = await circuit.calculateWitness({in: 1});

Expand Down Expand Up @@ -77,7 +77,7 @@ describe("Exponentioation test", function () {

it("Should exponentiate g^31", async () => {

const circuit = await tester(path.join(__dirname, "circuits", "escalarmul_test.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "escalarmul_test.circom"));

const w = await circuit.calculateWitness({"in": 31});

Expand Down Expand Up @@ -110,7 +110,7 @@ describe("Exponentioation test", function () {

it("Number of constrains for 256 bits", async () => {

const circuit = await tester(path.join(__dirname, "circuits", "escalarmul_test_min.circom"));
const circuit = await wasm_tester(path.join(__dirname, "circuits", "escalarmul_test_min.circom"));

}).timeout(10000000);

Expand Down
4 changes: 2 additions & 2 deletions test/escalarmulany.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const chai = require("chai");
const path = require("path");
const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;

const F1Field = require("ffjavascript").F1Field;
const Scalar = require("ffjavascript").Scalar;
Expand All @@ -19,7 +19,7 @@ describe("Escalarmul test", function () {
let g;

before( async() => {
circuitEMulAny = await tester(path.join(__dirname, "circuits", "escalarmulany_test.circom"));
circuitEMulAny = await wasm_tester(path.join(__dirname, "circuits", "escalarmulany_test.circom"));
g = [
Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
Expand Down
4 changes: 2 additions & 2 deletions test/escalarmulfix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const chai = require("chai");
const path = require("path");
const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;
const babyjub = require("circomlibjs").babyjub;
const F1Field = require("ffjavascript").F1Field;
const Scalar = require("ffjavascript").Scalar;
Expand All @@ -19,7 +19,7 @@ describe("Escalarmul test", function () {
this.timeout(100000);

before( async() => {
circuit = await tester(path.join(__dirname, "circuits", "escalarmulfix_test.circom"));
circuit = await wasm_tester(path.join(__dirname, "circuits", "escalarmulfix_test.circom"));
});

it("Should generate Same escalar mul", async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/mimccircuit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const chai = require("chai");
const path = require("path");
const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;

const mimcjs = require("circomlibjs").mimc7;

Expand All @@ -10,7 +10,7 @@ describe("MiMC Circuit test", function () {
this.timeout(100000);

before( async () => {
circuit = await tester(path.join(__dirname, "circuits", "mimc_test.circom"));
circuit = await wasm_tester(path.join(__dirname, "circuits", "mimc_test.circom"));
});

it("Should check constrain", async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/mimcspongecircuit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const tester = require("circom").tester;
const wasm_tester = require("circom_tester").wasm;

const mimcjs = require("circomlibjs").mimcsponge;

Expand All @@ -11,7 +11,7 @@ describe("MiMC Sponge Circuit test", function () {

it("Should check permutation", async () => {

circuit = await tester(path.join(__dirname, "circuits", "mimc_sponge_test.circom"));
circuit = await wasm_tester(path.join(__dirname, "circuits", "mimc_sponge_test.circom"));

const w = await circuit.calculateWitness({xL_in: 1, xR_in: 2, k: 3});

Expand All @@ -24,7 +24,7 @@ describe("MiMC Sponge Circuit test", function () {
});

it("Should check hash", async () => {
circuit = await tester(path.join(__dirname, "circuits", "mimc_sponge_hash_test.circom"));
circuit = await wasm_tester(path.join(__dirname, "circuits", "mimc_sponge_hash_test.circom"));

const w = await circuit.calculateWitness({ins: [1, 2], k: 0});

Expand Down
10 changes: 5 additions & 5 deletions test/montgomery.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const chai = require("chai");
const path = require("path");
const tester = require("circom").tester;
const babyJub = require("circomlibjs").babyjub;
const wasm_tester = require("circom_tester").wasm;
const F1Field = require("ffjavascript").F1Field;
const Scalar = require("ffjavascript").Scalar;
exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
Expand All @@ -24,13 +24,13 @@ describe("Montgomery test", function () {

this.timeout(100000);
before( async() => {
circuitE2M = await tester(path.join(__dirname, "circuits", "edwards2montgomery.circom"));
circuitE2M = await wasm_tester(path.join(__dirname, "circuits", "edwards2montgomery.circom"));
await circuitE2M.loadSymbols();
circuitM2E = await tester(path.join(__dirname, "circuits", "montgomery2edwards.circom"));
circuitM2E = await wasm_tester(path.join(__dirname, "circuits", "montgomery2edwards.circom"));
await circuitM2E.loadSymbols();
circuitMAdd = await tester(path.join(__dirname, "circuits", "montgomeryadd.circom"));
circuitMAdd = await wasm_tester(path.join(__dirname, "circuits", "montgomeryadd.circom"));
await circuitMAdd.loadSymbols();
circuitMDouble = await tester(path.join(__dirname, "circuits", "montgomerydouble.circom"));
circuitMDouble = await wasm_tester(path.join(__dirname, "circuits", "montgomerydouble.circom"));
await circuitMDouble.loadSymbols();
});
it("Convert Edwards to Montgomery and back again", async () => {
Expand Down
Loading

0 comments on commit a0cec75

Please sign in to comment.