circomlib/test/poseidoncircuit.js

58 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-06-04 14:40:15 +03:00
const chai = require("chai");
const path = require("path");
2019-12-14 22:32:45 +03:00
const tester = require("circom").tester;
2019-06-04 14:40:15 +03:00
const poseidon = require("../src/poseidon.js");
const assert = chai.assert;
describe("Poseidon Circuit test", function () {
2020-02-25 16:41:51 +03:00
let circuit6;
let circuit3;
2019-06-04 14:40:15 +03:00
this.timeout(100000);
before( async () => {
2020-03-26 21:52:34 +03:00
circuit6 = await tester(path.join(__dirname, "circuits", "poseidon6_test.circom"));
circuit3 = await tester(path.join(__dirname, "circuits", "poseidon3_test.circom"));
2020-02-25 16:41:51 +03:00
});
it("Should check constrain of hash([1, 2]) t=6", async () => {
2020-08-09 18:13:04 +03:00
const w = await circuit6.calculateWitness({inputs: [1, 2, 0,0,0]}, true);
2020-02-25 16:41:51 +03:00
2020-08-09 18:13:04 +03:00
const res2 = poseidon([1,2,0,0,0]);
assert.equal("3975478831357328722254985704342968745327876719981393787143845259590563829094", res2.toString());
2020-03-26 21:52:34 +03:00
await circuit6.assertOut(w, {out : res2});
await circuit6.checkConstraints(w);
2019-06-04 14:40:15 +03:00
});
2020-02-25 16:41:51 +03:00
it("Should check constrain of hash([3, 4]) t=6", async () => {
2020-08-09 18:13:04 +03:00
const w = await circuit6.calculateWitness({inputs: [3, 4,5,10,23]});
2019-06-04 14:40:15 +03:00
2020-08-09 18:13:04 +03:00
const res2 = poseidon([3, 4,5,10,23]);
2019-06-04 14:40:15 +03:00
2020-08-09 18:13:04 +03:00
assert.equal("18540626624821144952552691894137986276337186174352554475896834101336254024067", res2.toString());
2020-03-26 21:52:34 +03:00
await circuit6.assertOut(w, {out : res2});
await circuit6.checkConstraints(w);
2020-02-25 16:41:51 +03:00
});
it("Should check constrain of hash([1, 2]) t=3", async () => {
2020-03-26 21:52:34 +03:00
const w = await circuit3.calculateWitness({inputs: [1, 2]});
2020-02-25 16:41:51 +03:00
2020-08-09 18:13:04 +03:00
const res2 = poseidon([1,2]);
assert.equal("17117985411748610629288516079940078114952304104811071254131751175361957805920", res2.toString());
2020-03-26 21:52:34 +03:00
await circuit3.assertOut(w, {out : res2});
await circuit3.checkConstraints(w);
2019-06-28 11:50:49 +03:00
});
2019-06-04 14:40:15 +03:00
2020-02-25 16:41:51 +03:00
it("Should check constrain of hash([3, 4]) t=3", async () => {
2020-03-26 21:52:34 +03:00
const w = await circuit3.calculateWitness({inputs: [3, 4]});
2019-06-28 11:50:49 +03:00
2020-08-09 18:13:04 +03:00
const res2 = poseidon([3, 4]);
assert.equal("21867347236198497199818917118739170715216974132230970409806500217655788551452", res2.toString());
2020-03-26 21:52:34 +03:00
await circuit3.assertOut(w, {out : res2});
await circuit3.checkConstraints(w);
2019-06-04 14:40:15 +03:00
});
});