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 circuit;
22
23 this.timeout(100000);
24
25 before( async () => {
26 circuit = await tester(path.join(__dirname, "circuits", "poseidon_test.circom"));
27
28 });
29
30 it("Should check constrain of hash([1, 2])", async () => {
31 const w = await circuit.calculateWitness({inputs: [1, 2]}, true);
32
33 const hash = poseidon.createHash(6, 8, 57);
34
35 const res2 = hash([1,2]);
36 assert.equal("12242166908188651009877250812424843524687801523336557272219921456462821518061", res2.toString());
37
38 await circuit.assertOut(w, {out : res2});
39
40 await circuit.checkConstraints(w);
41 });
42
43 it("Should check constrain of hash([3, 4])", async () => {
44 const w = await circuit.calculateWitness({inputs: [3, 4]}, true);
45
46 const hash = poseidon.createHash(6, 8, 57);
47
48 const res2 = hash([3, 4]);
49 assert.equal("17185195740979599334254027721507328033796809509313949281114643312710535000993", res2.toString());
50
51 await circuit.assertOut(w, {out : res2});
52
53 await circuit.checkConstraints(w);
54 });
55});