arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/test/poseidoncircuit.js
test/poseidoncircuit.jsRaw
 1const chai = require("chai");
 2const path = require("path");
 3var blake2b = require("blake2b");
 4const bigInt = require("big-integer");
 5const tester = require("circom").tester;
 6
 7const poseidon = require("../src/poseidon.js");
 8
 9const assert = chai.assert;
10
11describe("Blake2b version test", function() {
12    it("Should give the expected output for blake2b version", async () => {
13        var output = new Uint8Array(32);
14        var input = Buffer.from("poseidon_constants");
15        const h = blake2b(output.length).update(input).digest("hex");
16        assert.equal("e57ba154fb2c47811dc1a2369b27e25a44915b4e4ece4eb8ec74850cb78e01b1", h);
17    });
18});
19
20describe("Poseidon Circuit test", function () {
21    let circuit6;
22    let circuit3;
23
24    this.timeout(100000);
25
26    before( async () => {
27        circuit6 = await tester(path.join(__dirname, "circuits", "poseidon6_test.circom"));
28        circuit3 = await tester(path.join(__dirname, "circuits", "poseidon3_test.circom"));
29    });
30
31    it("Should check constrain of hash([1, 2]) t=6", async () => {
32        const w = await circuit6.calculateWitness({inputs: [1, 2]}, true);
33
34        const hash = poseidon.createHash(6, 8, 57);
35
36        const res2 = hash([1,2]);
37        assert.equal("12242166908188651009877250812424843524687801523336557272219921456462821518061", res2.toString());
38        await circuit6.assertOut(w, {out : res2});
39        await circuit6.checkConstraints(w);
40    });
41
42    it("Should check constrain of hash([3, 4]) t=6", async () => {
43        const w = await circuit6.calculateWitness({inputs: [3, 4]});
44
45        const hash = poseidon.createHash(6, 8, 57);
46
47        const res2 = hash([3, 4]);
48
49        assert.equal("17185195740979599334254027721507328033796809509313949281114643312710535000993", res2.toString());
50        await circuit6.assertOut(w, {out : res2});
51        await circuit6.checkConstraints(w);
52    });
53
54
55    it("Should check constrain of hash([1, 2]) t=3", async () => {
56        const w = await circuit3.calculateWitness({inputs: [1, 2]});
57
58        const hash = poseidon.createHash(3, 8, 57);
59
60        const res2 = hash([1,2]);
61        assert.equal("2104035019328376391822106787753454168168617545136592089411833517434990977743", res2.toString());
62        await circuit3.assertOut(w, {out : res2});
63        await circuit3.checkConstraints(w);
64    });
65
66    it("Should check constrain of hash([3, 4]) t=3", async () => {
67        const w = await circuit3.calculateWitness({inputs: [3, 4]});
68
69        const hash = poseidon.createHash(3, 8, 57);
70
71        const res2 = hash([3, 4]);
72        assert.equal("12456141564250880945411182508630957604732712316993112736876413121277158512223", res2.toString());
73        await circuit3.assertOut(w, {out : res2});
74        await circuit3.checkConstraints(w);
75    });
76});