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