Skip to content

Commit

Permalink
pre 0.5 all working
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaylina committed Mar 26, 2020
1 parent 273ab79 commit e240605
Show file tree
Hide file tree
Showing 28 changed files with 2,973 additions and 3,491 deletions.
6 changes: 1 addition & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = {
"plugins": [
"mocha"
],
"env": {
"es6": true,
"node": true,
Expand All @@ -27,7 +24,6 @@ module.exports = {
"semi": [
"error",
"always"
],
"mocha/no-exclusive-tests": "error"
]
}
};
6,201 changes: 2,844 additions & 3,357 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
"dependencies": {
"blake-hash": "^1.1.0",
"blake2b": "^2.1.3",
"circom": "0.0.35",
"fflib": "0.0.1",
"circom": "0.5.2",
"ffjavascript": "0.0.3",
"snarkjs": "^0.1.20",
"typedarray-to-buffer": "^3.1.5",
"web3": "^1.0.0-beta.55"
"web3": "^1.2.6"
},
"devDependencies": {
"eslint-plugin-mocha": "^5.2.0",
"ganache-cli": "^6.4.4",
"eslint": "^6.8.0",
"ganache-cli": "^6.9.1",
"mocha": "^5.2.0"
}
}
2 changes: 1 addition & 1 deletion src/babyjub.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const bigInt = require("big-integer");
const ZqField = require("fflib").ZqField;
const ZqField = require("ffjavascript").ZqField;
const utils = require("./utils.js");

exports.addPoint = addPoint;
Expand Down
2 changes: 1 addition & 1 deletion src/mimc7.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const bigInt = require("big-integer");
const ZqField = require("fflib").ZqField;
const ZqField = require("ffjavascript").ZqField;

const Web3Utils = require("web3-utils");
const F = new ZqField(bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"));
Expand Down
2 changes: 1 addition & 1 deletion src/mimcsponge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const bigInt = require("big-integer");
const Web3Utils = require("web3-utils");
const ZqField = require("fflib").ZqField;
const ZqField = require("ffjavascript").ZqField;
const F = new ZqField(bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"));

const SEED = "mimcsponge";
Expand Down
2 changes: 1 addition & 1 deletion src/poseidon.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const bigInt = require("big-integer");
const blake2b = require("blake2b");
const assert = require("assert");
const ZqField = require("fflib").ZqField;
const ZqField = require("ffjavascript").ZqField;
const utils = require("./utils");

const F = new ZqField(bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"));
Expand Down
11 changes: 5 additions & 6 deletions test/aliascheck.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const chai = require("chai");
const path = require("path");
const compiler = require("circom");

const assert = chai.assert;

Expand Down Expand Up @@ -37,23 +36,23 @@ describe("Aliascheck test", function () {

it("Satisfy the aliastest 0", async () => {
const inp = getBits(bigInt.zero, 254);
await cir.calculateWitness({in: inp});
await cir.calculateWitness({in: inp}, true);
});

it("Satisfy the aliastest 3", async () => {
const inp = getBits(bigInt(3), 254);
await cir.calculateWitness({in: inp});
await cir.calculateWitness({in: inp}, true);
});

it("Satisfy the aliastest q-1", async () => {
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 () => {
const inp = getBits(q, 254);
try {
await cir.calculateWitness({in: inp});
await cir.calculateWitness({in: inp}, true);
assert(false);
} catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );
Expand All @@ -64,7 +63,7 @@ describe("Aliascheck test", function () {

const inp = getBits(bigInt(1).shiftLeft(254).minus(bigInt.one), 254);
try {
await cir.calculateWitness({in: inp});
await cir.calculateWitness({in: inp}, true);
assert(false);
} catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );
Expand Down
14 changes: 7 additions & 7 deletions test/babyjub.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Baby Jub test", function () {
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)});
});
Expand All @@ -48,7 +48,7 @@ describe("Baby Jub test", function () {
y2: bigInt("2626589144620713026669568689430873010625803728049924121243784502389097019475")
};

const w = await circuitAdd.calculateWitness(input);
const w = await circuitAdd.calculateWitness(input, true);

await circuitAdd.assertOut(w, {
xout: bigInt("6890855772600357754907169075114257697580319025794532037257385534741338397365"),
Expand All @@ -66,7 +66,7 @@ describe("Baby Jub test", function () {
y2: bigInt("20819045374670962167435360035096875258406992893633759881276124905556507972311")
};

const w = await circuitAdd.calculateWitness(input);
const w = await circuitAdd.calculateWitness(input, true);

await circuitAdd.assertOut(w, {
xout: bigInt("7916061937171219682591368294088513039687205273691143098332585753343424131937"),
Expand All @@ -75,15 +75,15 @@ describe("Baby Jub test", function () {

});

it("Should check (0,1) is a valid poiny", async() => {
const w = await circuitTest.calculateWitness({x: 0, y:1});
it("Should check (0,1) is a valid point", async() => {
const w = await circuitTest.calculateWitness({x: 0, y:1}, true);

await circuitTest.checkConstraints(w);
});

it("Should check (1,0) is an invalid point", async() => {
try {
await circuitTest.calculateWitness({x: 1, y: 0});
await circuitTest.calculateWitness({x: 1, y: 0}, true);
assert(false, "Should be a valid point");
} catch(err) {
assert(/Constraint\sdoesn't\smatch(.*)168700\s!=\s1/.test(err.message) );
Expand All @@ -102,7 +102,7 @@ describe("Baby Jub test", function () {
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]});

Expand Down
2 changes: 1 addition & 1 deletion test/binsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function checkSub(_a,_b, circuit) {
let b=bigInt(_b);
if (a.lesser(bigInt.zero)) a = a.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);
if (res.lesser(bigInt.zero)) res = res.add(bigInt.one.shiftLeft(16));
Expand Down
9 changes: 5 additions & 4 deletions test/binsum.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ describe("Binary sum test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "constants_test.circom"));
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[1].equals(bigInt("d807aa98", 16)));
Expand All @@ -26,9 +27,9 @@ describe("Binary sum test", function () {
const circuit = await tester(path.join(__dirname, "circuits", "sum_test.circom"));
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[1].equals(bigInt("333")));
Expand Down
Loading

0 comments on commit e240605

Please sign in to comment.