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.

39 lines
959 B

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