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.

80 lines
2.9 KiB

  1. const chai = require("chai");
  2. const path = require("path");
  3. const wasm_tester = require("circom_tester").wasm;
  4. const buildPoseidon = require("circomlibjs").buildPoseidon;
  5. const assert = chai.assert;
  6. describe("Poseidon Circuit test", function () {
  7. let poseidon;
  8. let F;
  9. let circuit6;
  10. let circuit3;
  11. let circuitEx;
  12. this.timeout(1000000);
  13. before( async () => {
  14. poseidon = await buildPoseidon();
  15. F = poseidon.F;
  16. circuit6 = await wasm_tester(path.join(__dirname, "circuits", "poseidon6_test.circom"));
  17. circuit3 = await wasm_tester(path.join(__dirname, "circuits", "poseidon3_test.circom"));
  18. circuitEx = await wasm_tester(path.join(__dirname, "circuits", "poseidonex_test.circom"));
  19. });
  20. it("Should check constrain of hash([1, 2]) t=6", async () => {
  21. const w = await circuit6.calculateWitness({inputs: [1, 2, 0,0,0]}, true);
  22. const res2 = poseidon([1,2,0,0,0]);
  23. assert(F.eq(F.e("1018317224307729531995786483840663576608797660851238720571059489595066344487"), F.e(res2)));
  24. await circuit6.assertOut(w, {out : F.toObject(res2)});
  25. await circuit6.checkConstraints(w);
  26. });
  27. it("Should check constrain of hash([3, 4]) t=6", async () => {
  28. const w = await circuit6.calculateWitness({inputs: [3, 4,5,10,23]});
  29. const res2 = poseidon([3, 4,5,10,23]);
  30. assert(F.eq(F.e("13034429309846638789535561449942021891039729847501137143363028890275222221409"), F.e(res2)));
  31. await circuit6.assertOut(w, {out : F.toObject(res2)});
  32. await circuit6.checkConstraints(w);
  33. });
  34. it("Should check constrain of hash([1, 2]) t=3", async () => {
  35. const w = await circuit3.calculateWitness({inputs: [1, 2]});
  36. const res2 = poseidon([1,2]);
  37. assert(F.eq(F.e("7853200120776062878684798364095072458815029376092732009249414926327459813530"), F.e(res2)));
  38. await circuit3.assertOut(w, {out : F.toObject(res2)});
  39. await circuit3.checkConstraints(w);
  40. });
  41. it("Should check constrain of hash([3, 4]) t=3", async () => {
  42. const w = await circuit3.calculateWitness({inputs: [3, 4]});
  43. const res2 = poseidon([3, 4]);
  44. assert(F.eq(F.e("14763215145315200506921711489642608356394854266165572616578112107564877678998"), F.e(res2)));
  45. await circuit3.assertOut(w, {out : F.toObject(res2)});
  46. await circuit3.checkConstraints(w);
  47. });
  48. it("Should check constrain of hash with state and 16 ins and outs", async () => {
  49. const ins = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
  50. const w = await circuitEx.calculateWitness({inputs: ins, initialState: 17});
  51. const res2 = poseidon(ins, 17, 17);
  52. const res2f = [];
  53. for (let i=0; i<res2.length; i++) {
  54. res2f[i] = F.toObject(res2[i]);
  55. }
  56. await circuitEx.assertOut(w, {out : res2f});
  57. await circuitEx.checkConstraints(w);
  58. });
  59. });