arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/test/poseidoncircuit.js
test/poseidoncircuit.jsRaw
 1const chai = require("chai");
 2const path = require("path");
 3const snarkjs = require("snarkjs");
 4const compiler = require("circom");
 5
 6const poseidon = require("../src/poseidon.js");
 7
 8const assert = chai.assert;
 9
10describe("Poseidon Circuit test", function () {
11    let circuit;
12
13    this.timeout(100000);
14
15    before( async () => {
16        const cirDef = await compiler(path.join(__dirname, "circuits", "poseidon_test.circom"));
17
18        circuit = new snarkjs.Circuit(cirDef);
19
20        console.log("Poseidon constraints: " + circuit.nConstraints);
21    });
22
23    it("Should check constrain", async () => {
24        const w = circuit.calculateWitness({inputs: [1, 2]});
25
26        const res = w[circuit.getSignalIdx("main.out")];
27
28        const hash = poseidon.createHash(6, 8, 57);
29
30        const res2 = hash([1,2]);
31
32        console.log(res.toString());
33
34        assert.equal(res.toString(), res2.toString());
35
36        assert(circuit.checkWitness(w));
37
38    });
39});