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.

59 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 assert = chai.assert;
  6. const bigInt = snarkjs.bigInt;
  7. function print(circuit, w, s) {
  8. console.log(s + ": " + w[circuit.getSignalIdx(s)]);
  9. }
  10. describe("Escalarmul test", function () {
  11. let circuitEMulAny;
  12. this.timeout(100000);
  13. let g = [
  14. snarkjs.bigInt("17777552123799933955779906779655732241715742912184938656739573121738514868268"),
  15. snarkjs.bigInt("2626589144620713026669568689430873010625803728049924121243784502389097019475")
  16. ];
  17. before( async() => {
  18. const cirDefEMulAny = await compiler(path.join(__dirname, "circuits", "escalarmulany_test.circom"));
  19. circuitEMulAny = new snarkjs.Circuit(cirDefEMulAny);
  20. console.log("NConstrains Escalarmul any: " + circuitEMulAny.nConstraints);
  21. });
  22. it("Should generate Same escalar mul", async () => {
  23. const w = circuitEMulAny.calculateWitness({"e": 1, "p": g});
  24. assert(circuitEMulAny.checkWitness(w));
  25. const xout = w[circuitEMulAny.getSignalIdx("main.out[0]")];
  26. const yout = w[circuitEMulAny.getSignalIdx("main.out[1]")];
  27. assert(xout.equals(g[0]));
  28. assert(yout.equals(g[1]));
  29. });
  30. it("If multiply by order should return 0", async () => {
  31. const r = bigInt("2736030358979909402780800718157159386076813972158567259200215660948447373041");
  32. const w = circuitEMulAny.calculateWitness({"e": r, "p": g});
  33. assert(circuitEMulAny.checkWitness(w));
  34. const xout = w[circuitEMulAny.getSignalIdx("main.out[0]")];
  35. const yout = w[circuitEMulAny.getSignalIdx("main.out[1]")];
  36. assert(xout.equals(bigInt.zero));
  37. assert(yout.equals(bigInt.one));
  38. });
  39. });