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.

90 lines
2.5 KiB

  1. const chai = require("chai");
  2. const path = require("path");
  3. const tester = require("circom").tester;
  4. const babyjub = require("../src/babyjub");
  5. const Fr = require("ffjavascript").bn128.Fr;
  6. const assert = chai.assert;
  7. function print(circuit, w, s) {
  8. console.log(s + ": " + w[circuit.getSignalIdx(s)]);
  9. }
  10. describe("Escalarmul test", function () {
  11. let circuit;
  12. this.timeout(100000);
  13. before( async() => {
  14. circuit = await tester(path.join(__dirname, "circuits", "escalarmulfix_test.circom"));
  15. });
  16. it("Should generate Same escalar mul", async () => {
  17. const w = await circuit.calculateWitness({"e": 0});
  18. await circuit.checkConstraints(w);
  19. await circuit.assertOut(w, {out: [0,1]}, true);
  20. });
  21. it("Should generate Same escalar mul", async () => {
  22. const w = await circuit.calculateWitness({"e": 1}, true);
  23. await circuit.checkConstraints(w);
  24. await circuit.assertOut(w, {out: babyjub.Base8});
  25. });
  26. it("Should generate scalar mul of a specific constant", async () => {
  27. const s = Fr.e("2351960337287830298912035165133676222414898052661454064215017316447594616519");
  28. const base8 = [
  29. Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
  30. Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
  31. ];
  32. const w = await circuit.calculateWitness({"e": s}, true);
  33. await circuit.checkConstraints(w);
  34. const expectedRes = babyjub.mulPointEscalar(base8, s);
  35. await circuit.assertOut(w, {out: expectedRes});
  36. });
  37. it("Should generate scalar mul of the firsts 50 elements", async () => {
  38. const base8 = [
  39. Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
  40. Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
  41. ];
  42. for (let i=0; i<50; i++) {
  43. const s = Fr.e(i);
  44. const w = await circuit.calculateWitness({"e": s}, true);
  45. await circuit.checkConstraints(w);
  46. const expectedRes = babyjub.mulPointEscalar(base8, s);
  47. await circuit.assertOut(w, {out: expectedRes});
  48. }
  49. });
  50. it("If multiply by order should return 0", async () => {
  51. const w = await circuit.calculateWitness({"e": babyjub.subOrder }, true);
  52. await circuit.checkConstraints(w);
  53. await circuit.assertOut(w, {out: [0,1]});
  54. });
  55. });