2018-12-06 19:32:49 +03:00
|
|
|
const chai = require("chai");
|
|
|
|
const path = require("path");
|
2023-07-21 13:10:01 +03:00
|
|
|
const snarkjs = require("@tornado/snarkjs");
|
2018-12-06 19:32:49 +03:00
|
|
|
const compiler = require("circom");
|
|
|
|
|
|
|
|
const mimcjs = require("../src/mimc7.js");
|
|
|
|
|
|
|
|
const assert = chai.assert;
|
|
|
|
|
|
|
|
describe("MiMC Circuit test", function () {
|
|
|
|
let circuit;
|
|
|
|
|
|
|
|
this.timeout(100000);
|
|
|
|
|
2023-07-21 13:10:01 +03:00
|
|
|
before(async () => {
|
2018-12-06 19:32:49 +03:00
|
|
|
const cirDef = await compiler(path.join(__dirname, "circuits", "mimc_test.circom"));
|
|
|
|
|
|
|
|
circuit = new snarkjs.Circuit(cirDef);
|
|
|
|
|
|
|
|
console.log("MiMC constraints: " + circuit.nConstraints);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should check constrain", async () => {
|
2023-07-21 13:10:01 +03:00
|
|
|
const w = circuit.calculateWitness({ x_in: 1, k: 2 });
|
2018-12-06 19:32:49 +03:00
|
|
|
|
|
|
|
const res = w[circuit.getSignalIdx("main.out")];
|
|
|
|
|
2023-07-21 13:10:01 +03:00
|
|
|
const res2 = mimcjs.hash(1, 2, 91);
|
2018-12-06 19:32:49 +03:00
|
|
|
|
|
|
|
assert.equal(res.toString(), res2.toString());
|
|
|
|
|
|
|
|
assert(circuit.checkWitness(w));
|
|
|
|
});
|
|
|
|
});
|