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.

77 lines
2.7 KiB

  1. const chai = require("chai");
  2. const path = require("path");
  3. const Fr = require("ffjavascript").bn128.Fr;
  4. const tester = require("circom").tester;
  5. const babyJub = require("../src/babyjub.js");
  6. const PBASE =
  7. [
  8. [Fr.e("7688621503272331394947188562469131124099290577812125474996268020905176040083"),Fr.e("6637287939860384587467947982369268811366630904563077767287326262235485629411")],
  9. [Fr.e("11549681895645637778324638856880330712650895608496649854094912415387988201330"),Fr.e("5771732722784528537721081267383956005090479808901717812009343940574217488577")],
  10. [Fr.e("18790245153471844934157747708238883966079935875787657036767664036124524381945"),Fr.e("18300275459419441151064576487317481499516933849631632883767173501999997278432")],
  11. [Fr.e("16301069151422548986850494139112207641738464387919729729324473657161689764196"),Fr.e("8215273507373494014441104012907835625670941526105528197815397741007626226499")],
  12. [Fr.e("12597665704678284488008395353749282149622295037737374782196049599390683534185"),Fr.e("4072455241781501621593714139281767473040087753548015968773801065193764079468")]
  13. ];
  14. describe("Double Pedersen test", function() {
  15. let circuit;
  16. this.timeout(100000);
  17. before( async() => {
  18. circuit = await tester(path.join(__dirname, "circuits", "pedersen_test.circom"));
  19. });
  20. it("Should pedersen at zero", async () => {
  21. let w;
  22. w = await circuit.calculateWitness({ in: ["0", "0"]}, true);
  23. await circuit.assertOut(w, {out: [0,1]});
  24. });
  25. it("Should pedersen at one first generator", async () => {
  26. let w;
  27. w = await circuit.calculateWitness({ in: ["1", "0"]}, true);
  28. await circuit.assertOut(w, {out: PBASE[0]});
  29. });
  30. it("Should pedersen at one second generator", async () => {
  31. let w;
  32. w = await circuit.calculateWitness({ in: ["0", "1"]}, true);
  33. await circuit.assertOut(w, {out: PBASE[1]});
  34. });
  35. it("Should pedersen at mixed generators", async () => {
  36. let w;
  37. w = await circuit.calculateWitness({ in: ["3", "7"]}, true);
  38. const r = babyJub.addPoint(
  39. babyJub.mulPointEscalar(PBASE[0], 3),
  40. babyJub.mulPointEscalar(PBASE[1], 7)
  41. );
  42. await circuit.assertOut(w, {out: r});
  43. });
  44. it("Should pedersen all ones", async () => {
  45. let w;
  46. const allOnes = Fr.sub(Fr.shl(Fr.e("1"), Fr.e(250)), Fr.e("1"));
  47. w = await circuit.calculateWitness({ in: [allOnes, allOnes]}, true);
  48. const r2 = babyJub.addPoint(
  49. babyJub.mulPointEscalar(PBASE[0], allOnes),
  50. babyJub.mulPointEscalar(PBASE[1], allOnes)
  51. );
  52. await circuit.assertOut(w, {out: r2});
  53. });
  54. });