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("3975478831357328722254985704342968745327876719981393787143845259590563829094", 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("18540626624821144952552691894137986276337186174352554475896834101336254024067", 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("17117985411748610629288516079940078114952304104811071254131751175361957805920", 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("21867347236198497199818917118739170715216974132230970409806500217655788551452", res2.toString());
  39. await circuit3.assertOut(w, {out : res2});
  40. await circuit3.checkConstraints(w);
  41. });
  42. });