You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
858 B

  1. const chai = require("chai");
  2. const path = require("path");
  3. const snarkjs = require("snarkjs");
  4. const compiler = require("circom");
  5. const mimcjs = require("../src/mimc7.js");
  6. const assert = chai.assert;
  7. describe("MiMC Circuit test", function () {
  8. let circuit;
  9. this.timeout(100000);
  10. before( async () => {
  11. const cirDef = await compiler(path.join(__dirname, "circuits", "mimc_test.circom"));
  12. circuit = new snarkjs.Circuit(cirDef);
  13. console.log("MiMC constraints: " + circuit.nConstraints);
  14. });
  15. it("Should check constrain", async () => {
  16. const w = circuit.calculateWitness({x_in: 1, k: 2});
  17. const res = w[circuit.getSignalIdx("main.out")];
  18. const res2 = mimcjs.hash(1,2,91);
  19. assert.equal(res.toString(), res2.toString());
  20. assert(circuit.checkWitness(w));
  21. });
  22. });