circomlib/test/escalarmulany.js
test/escalarmulany.jsRaw
1const chai = require("chai");
2const path = require("path");
3const snarkjs = require("snarkjs");
4const compiler = require("circom");
5
6const assert = chai.assert;
7
8const bigInt = snarkjs.bigInt;
9
10
11function print(circuit, w, s) {
12 console.log(s + ": " + w[circuit.getSignalIdx(s)]);
13}
14
15describe("Escalarmul test", function () {
16 let circuitEMulAny;
17
18 this.timeout(100000);
19
20 let g = [
21 snarkjs.bigInt("17777552123799933955779906779655732241715742912184938656739573121738514868268"),
22 snarkjs.bigInt("2626589144620713026669568689430873010625803728049924121243784502389097019475")
23 ];
24
25 before( async() => {
26 const cirDefEMulAny = await compiler(path.join(__dirname, "circuits", "escalarmulany_test.circom"));
27 circuitEMulAny = new snarkjs.Circuit(cirDefEMulAny);
28 console.log("NConstrains Escalarmul any: " + circuitEMulAny.nConstraints);
29 });
30
31 it("Should generate Same escalar mul", async () => {
32
33 const w = circuitEMulAny.calculateWitness({"e": 1, "p": g});
34
35 assert(circuitEMulAny.checkWitness(w));
36
37 const xout = w[circuitEMulAny.getSignalIdx("main.out[0]")];
38 const yout = w[circuitEMulAny.getSignalIdx("main.out[1]")];
39
40 assert(xout.equals(g[0]));
41 assert(yout.equals(g[1]));
42 });
43
44 it("If multiply by order should return 0", async () => {
45
46 const r = bigInt("2736030358979909402780800718157159386076813972158567259200215660948447373041");
47 const w = circuitEMulAny.calculateWitness({"e": r, "p": g});
48
49 assert(circuitEMulAny.checkWitness(w));
50
51 const xout = w[circuitEMulAny.getSignalIdx("main.out[0]")];
52 const yout = w[circuitEMulAny.getSignalIdx("main.out[1]")];
53
54 assert(xout.equals(bigInt.zero));
55 assert(yout.equals(bigInt.one));
56 });
57
58});
59