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.

57 lines
2.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. const chai = require("chai");
  2. const path = require("path");
  3. const tester = require("circom").tester;
  4. const poseidon = require("../src/poseidon.js");
  5. const assert = chai.assert;
  6. describe("Poseidon Circuit test", function () {
  7. let circuit6;
  8. let circuit3;
  9. this.timeout(100000);
  10. before( async () => {
  11. circuit6 = await tester(path.join(__dirname, "circuits", "poseidon6_test.circom"));
  12. circuit3 = await tester(path.join(__dirname, "circuits", "poseidon3_test.circom"));
  13. });
  14. it("Should check constrain of hash([1, 2]) t=6", async () => {
  15. const w = await circuit6.calculateWitness({inputs: [1, 2, 0,0,0]}, true);
  16. const res2 = poseidon([1,2,0,0,0]);
  17. assert.equal("1944517543886089121158331594914426541694339782056411886233994349799551050705", res2.toString());
  18. await circuit6.assertOut(w, {out : res2});
  19. await circuit6.checkConstraints(w);
  20. });
  21. it("Should check constrain of hash([3, 4]) t=6", async () => {
  22. const w = await circuit6.calculateWitness({inputs: [3, 4,5,10,23]});
  23. const res2 = poseidon([3, 4,5,10,23]);
  24. assert.equal("15043529598202765311255531083507141602555136943545139099151157943137780370931", res2.toString());
  25. await circuit6.assertOut(w, {out : res2});
  26. await circuit6.checkConstraints(w);
  27. });
  28. it("Should check constrain of hash([1, 2]) t=3", async () => {
  29. const w = await circuit3.calculateWitness({inputs: [1, 2]});
  30. const res2 = poseidon([1,2]);
  31. assert.equal("11309872961022349216464221841186646423561022368884850929991258903497301047946", res2.toString());
  32. await circuit3.assertOut(w, {out : res2});
  33. await circuit3.checkConstraints(w);
  34. });
  35. it("Should check constrain of hash([3, 4]) t=3", async () => {
  36. const w = await circuit3.calculateWitness({inputs: [3, 4]});
  37. const res2 = poseidon([3, 4]);
  38. assert.equal("5452722186384045185233705092171776011224530037417547968760104202263491217182", res2.toString());
  39. await circuit3.assertOut(w, {out : res2});
  40. await circuit3.checkConstraints(w);
  41. });
  42. });