2019-06-02 00:19:07 +03:00
|
|
|
const path = require("path");
|
2019-12-14 22:32:45 +03:00
|
|
|
const tester = require("circom").tester;
|
2019-06-02 00:19:07 +03:00
|
|
|
|
|
|
|
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 22:32:45 +03:00
|
|
|
circuit = await tester(path.join(__dirname, "circuits", "mimc_sponge_test.circom"));
|
2019-06-02 00:19:07 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
const w = await circuit.calculateWitness({xL_in: 1, xR_in: 2, k: 3});
|
2019-06-02 00:19:07 +03:00
|
|
|
|
|
|
|
const out2 = mimcjs.hash(1,2,3);
|
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
await circuit.assertOut(w, {xL_out: out2.xL, xR_out: out2.xR});
|
2019-06-02 00:19:07 +03:00
|
|
|
|
2019-12-16 23:35:52 +03:00
|
|
|
await circuit.checkConstraints(w);
|
2019-06-02 00:19:07 +03:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should check hash", async () => {
|
2019-12-14 22:32:45 +03:00
|
|
|
circuit = await tester(path.join(__dirname, "circuits", "mimc_sponge_hash_test.circom"));
|
2019-06-02 00:19:07 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
const w = await circuit.calculateWitness({ins: [1, 2], k: 0});
|
2019-06-02 00:19:07 +03:00
|
|
|
|
|
|
|
const out2 = mimcjs.multiHash([1,2], 0, 3);
|
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
await circuit.assertOut(w, {outs: out2});
|
2019-06-02 00:19:07 +03:00
|
|
|
|
2019-12-16 23:35:52 +03:00
|
|
|
await circuit.checkConstraints(w);
|
2019-06-02 00:19:07 +03:00
|
|
|
});
|
|
|
|
});
|