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.

67 lines
1.8 KiB

  1. const chai = require("chai");
  2. const path = require("path");
  3. const snarkjs = require("snarkjs");
  4. const compiler = require("circom");
  5. const babyjub = require("../src/babyjub");
  6. const assert = chai.assert;
  7. const bigInt = snarkjs.bigInt;
  8. function print(circuit, w, s) {
  9. console.log(s + ": " + w[circuit.getSignalIdx(s)]);
  10. }
  11. describe("Escalarmul test", function () {
  12. let circuit;
  13. this.timeout(100000);
  14. before( async() => {
  15. const cirDef = await compiler(path.join(__dirname, "circuits", "escalarmulfix_test.circom"));
  16. circuit = new snarkjs.Circuit(cirDef);
  17. console.log("NConstrains Escalarmul fix: " + circuit.nConstraints);
  18. });
  19. it("Should generate Same escalar mul", async () => {
  20. const w = circuit.calculateWitness({"e": 0});
  21. assert(circuit.checkWitness(w));
  22. const xout = w[circuit.getSignalIdx("main.out[0]")];
  23. const yout = w[circuit.getSignalIdx("main.out[1]")];
  24. assert(xout.equals(0));
  25. assert(yout.equals(1));
  26. });
  27. it("Should generate Same escalar mul", async () => {
  28. const w = circuit.calculateWitness({"e": 1});
  29. assert(circuit.checkWitness(w));
  30. const xout = w[circuit.getSignalIdx("main.out[0]")];
  31. const yout = w[circuit.getSignalIdx("main.out[1]")];
  32. assert(xout.equals(babyjub.Base8[0]));
  33. assert(yout.equals(babyjub.Base8[1]));
  34. });
  35. it("If multiply by order should return 0", async () => {
  36. const w = circuit.calculateWitness({"e": babyjub.subOrder });
  37. assert(circuit.checkWitness(w));
  38. const xout = w[circuit.getSignalIdx("main.out[0]")];
  39. const yout = w[circuit.getSignalIdx("main.out[1]")];
  40. assert(xout.equals(bigInt.zero));
  41. assert(yout.equals(bigInt.one));
  42. });
  43. });