arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/test/poseidoncircuit.js
test/poseidoncircuit.jsRaw
 1const chai = require("chai");
 2const path = require("path");
 3const tester = require("circom").tester;
 4
 5const poseidon = require("../src/poseidon.js");
 6
 7const assert = chai.assert;
 8
 9describe("Poseidon Circuit test", function () {
10    let circuit6;
11    let circuit3;
12
13    this.timeout(100000);
14
15    before( async () => {
16        circuit6 = await tester(path.join(__dirname, "circuits", "poseidon6_test.circom"));
17        circuit3 = await tester(path.join(__dirname, "circuits", "poseidon3_test.circom"));
18    });
19
20    it("Should check constrain of hash([1, 2]) t=6", async () => {
21        const w = await circuit6.calculateWitness({inputs: [1, 2, 0,0,0]}, true);
22
23        const res2 = poseidon([1,2,0,0,0]);
24        assert.equal("3975478831357328722254985704342968745327876719981393787143845259590563829094", res2.toString());
25        await circuit6.assertOut(w, {out : res2});
26        await circuit6.checkConstraints(w);
27    });
28
29    it("Should check constrain of hash([3, 4]) t=6", async () => {
30        const w = await circuit6.calculateWitness({inputs: [3, 4,5,10,23]});
31
32        const res2 = poseidon([3, 4,5,10,23]);
33
34        assert.equal("18540626624821144952552691894137986276337186174352554475896834101336254024067", res2.toString());
35        await circuit6.assertOut(w, {out : res2});
36        await circuit6.checkConstraints(w);
37    });
38
39
40    it("Should check constrain of hash([1, 2]) t=3", async () => {
41        const w = await circuit3.calculateWitness({inputs: [1, 2]});
42
43        const res2 = poseidon([1,2]);
44        assert.equal("17117985411748610629288516079940078114952304104811071254131751175361957805920", res2.toString());
45        await circuit3.assertOut(w, {out : res2});
46        await circuit3.checkConstraints(w);
47    });
48
49    it("Should check constrain of hash([3, 4]) t=3", async () => {
50        const w = await circuit3.calculateWitness({inputs: [3, 4]});
51
52        const res2 = poseidon([3, 4]);
53        assert.equal("21867347236198497199818917118739170715216974132230970409806500217655788551452", res2.toString());
54        await circuit3.assertOut(w, {out : res2});
55        await circuit3.checkConstraints(w);
56    });
57});