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 bigInt = require("big-integer");
  4. const tester = require("circom").tester;
  5. const babyjub = require("../src/babyjub");
  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]});
  20. });
  21. it("Should generate Same escalar mul", async () => {
  22. const w = await circuit.calculateWitness({"e": 1});
  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 = bigInt("2351960337287830298912035165133676222414898052661454064215017316447594616519");
  28. const base8 = [
  29. bigInt("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
  30. bigInt("16950150798460657717958625567821834550301663161624707787222815936182638968203")
  31. ];
  32. const w = await circuit.calculateWitness({"e": s});
  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. bigInt("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
  40. bigInt("16950150798460657717958625567821834550301663161624707787222815936182638968203")
  41. ];
  42. for (let i=0; i<50; i++) {
  43. const s = bigInt(i);
  44. const w = await circuit.calculateWitness({"e": s});
  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 });
  52. await circuit.checkConstraints(w);
  53. await circuit.assertOut(w, {out: [0,1]});
  54. });
  55. });