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.

49 lines
1.1 KiB

  1. const path = require("path");
  2. const bigInt = require("big-integer");
  3. const tester = require("circom").tester;
  4. const babyJub = require("../src/babyjub.js");
  5. const pedersen = require("../src/pedersenHash.js");
  6. describe("Pedersen test", function() {
  7. let circuit;
  8. this.timeout(100000);
  9. before( async() => {
  10. circuit = await tester(path.join(__dirname, "circuits", "pedersen2_test.circom"));
  11. });
  12. it("Should pedersen at zero", async () => {
  13. let w;
  14. w = await circuit.calculateWitness({ in: 0}, true);
  15. const b = Buffer.alloc(32);
  16. const h = pedersen.hash(b);
  17. const hP = babyJub.unpackPoint(h);
  18. await circuit.assertOut(w, {out: hP});
  19. });
  20. it("Should pedersen with 253 ones", async () => {
  21. let w;
  22. const n = bigInt.one.shiftLeft(253).minus(bigInt.one);
  23. w = await circuit.calculateWitness({ in: n}, true);
  24. const b = Buffer.alloc(32);
  25. for (let i=0; i<31; i++) b[i] = 0xFF;
  26. b[31] = 0x1F;
  27. const h = pedersen.hash(b);
  28. const hP = babyJub.unpackPoint(h);
  29. await circuit.assertOut(w, {out: hP});
  30. });
  31. });