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.

115 lines
3.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. const chai = require("chai");
  2. const path = require("path");
  3. const tester = require("circom").tester;
  4. const babyJub = require("../src/babyjub.js");
  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("Exponentioation test", function () {
  11. this.timeout(100000);
  12. it("Should generate the Exponentiation table in k=0", async () => {
  13. const circuit = await tester(path.join(__dirname, "circuits", "escalarmulw4table_test.circom"));
  14. const w = await circuit.calculateWitness({in: 1});
  15. await circuit.checkConstraints(w);
  16. let g = [
  17. Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
  18. Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
  19. ];
  20. let dbl= [Fr.e("0"), Fr.e("1")];
  21. const expectedOut = [];
  22. for (let i=0; i<16; i++) {
  23. expectedOut.push(dbl);
  24. dbl = babyJub.addPoint(dbl,g);
  25. }
  26. await circuit.assertOut(w, {out: expectedOut});
  27. });
  28. it("Should generate the Exponentiation table in k=3", async () => {
  29. const circuit = await tester(path.join(__dirname, "circuits", "escalarmulw4table_test3.circom"));
  30. const w = await circuit.calculateWitness({in: 1});
  31. await circuit.checkConstraints(w);
  32. let g = [
  33. Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
  34. Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
  35. ];
  36. for (let i=0; i<12;i++) {
  37. g = babyJub.addPoint(g,g);
  38. }
  39. let dbl= [Fr.e("0"), Fr.e("1")];
  40. const expectedOut = [];
  41. for (let i=0; i<16; i++) {
  42. expectedOut.push(dbl);
  43. dbl = babyJub.addPoint(dbl,g);
  44. }
  45. await circuit.assertOut(w, {out: expectedOut});
  46. });
  47. it("Should exponentiate g^31", async () => {
  48. const circuit = await tester(path.join(__dirname, "circuits", "escalarmul_test.circom"));
  49. const w = await circuit.calculateWitness({"in": 31});
  50. await circuit.checkConstraints(w);
  51. let g = [
  52. Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
  53. Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
  54. ];
  55. let c = [Fr.e(0), Fr.e(1)];
  56. for (let i=0; i<31;i++) {
  57. c = babyJub.addPoint(c,g);
  58. }
  59. await circuit.assertOut(w, {out: c});
  60. const w2 = await circuit.calculateWitness({"in": Fr.add(Fr.shl(Fr.e(1), Fr.e(252)),Fr.one)});
  61. c = [g[0], g[1]];
  62. for (let i=0; i<252;i++) {
  63. c = babyJub.addPoint(c,c);
  64. }
  65. c = babyJub.addPoint(c,g);
  66. await circuit.assertOut(w2, {out: c});
  67. }).timeout(10000000);
  68. it("Number of constrains for 256 bits", async () => {
  69. const circuit = await tester(path.join(__dirname, "circuits", "escalarmul_test_min.circom"));
  70. }).timeout(10000000);
  71. });