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.

56 lines
1.4 KiB

  1. const path = require("path");
  2. const Scalar = require("ffjavascript").Scalar;
  3. const buildPedersenHash = require("circomlibjs").buildPedersenHash;
  4. const buildBabyJub = require("circomlibjs").buildBabyjub;
  5. const wasm_tester = require("circom_tester").wasm;
  6. describe("Pedersen test", function() {
  7. let babyJub
  8. let pedersen;
  9. let F;
  10. let circuit;
  11. this.timeout(100000);
  12. before( async() => {
  13. babyJub = await buildBabyJub();
  14. F = babyJub.F;
  15. pedersen = await buildPedersenHash();
  16. circuit = await wasm_tester(path.join(__dirname, "circuits", "pedersen2_test.circom"));
  17. });
  18. it("Should pedersen at zero", async () => {
  19. let w;
  20. w = await circuit.calculateWitness({ in: 0}, true);
  21. const b = Buffer.alloc(32);
  22. const h = pedersen.hash(b);
  23. const hP = babyJub.unpackPoint(h);
  24. await circuit.assertOut(w, {out: [F.toObject(hP[0]), F.toObject(hP[1])] });
  25. });
  26. it("Should pedersen with 253 ones", async () => {
  27. let w;
  28. const n = F.e(Scalar.sub(Scalar.shl(Scalar.e(1), 253), Scalar.e(1)));
  29. w = await circuit.calculateWitness({ in: F.toObject(n)}, true);
  30. const b = Buffer.alloc(32);
  31. for (let i=0; i<31; i++) b[i] = 0xFF;
  32. b[31] = 0x1F;
  33. const h = pedersen.hash(b);
  34. const hP = babyJub.unpackPoint(h);
  35. await circuit.assertOut(w, {out: [F.toObject(hP[0]), F.toObject(hP[1])] });
  36. });
  37. });