circomlib/test/mimcspongecircuit.js

38 lines
981 B
JavaScript
Raw Permalink Normal View History

const path = require("path");
2019-12-14 20:32:45 +01:00
const tester = require("circom").tester;
const mimcjs = require("../src/mimcsponge.js");
describe("MiMC Sponge Circuit test", function () {
let circuit;
this.timeout(100000);
it("Should check permutation", async () => {
2019-12-14 20:32:45 +01:00
circuit = await tester(path.join(__dirname, "circuits", "mimc_sponge_test.circom"));
2019-12-14 20:32:45 +01:00
const w = await circuit.calculateWitness({xL_in: 1, xR_in: 2, k: 3});
const out2 = mimcjs.hash(1,2,3);
2019-12-14 20:32:45 +01:00
await circuit.assertOut(w, {xL_out: out2.xL, xR_out: out2.xR});
2019-12-16 21:35:52 +01:00
await circuit.checkConstraints(w);
});
it("Should check hash", async () => {
2019-12-14 20:32:45 +01:00
circuit = await tester(path.join(__dirname, "circuits", "mimc_sponge_hash_test.circom"));
2019-12-14 20:32:45 +01:00
const w = await circuit.calculateWitness({ins: [1, 2], k: 0});
const out2 = mimcjs.multiHash([1,2], 0, 3);
2019-12-14 20:32:45 +01:00
await circuit.assertOut(w, {outs: out2});
2019-12-16 21:35:52 +01:00
await circuit.checkConstraints(w);
});
});