arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/test/escalarmulfix.js
test/escalarmulfix.jsRaw
 1const chai = require("chai");
 2const path = require("path");
 3const tester = require("circom").tester;
 4const babyjub = require("../src/babyjub");
 5const Fr = require("ffjavascript").bn128.Fr;
 6
 7const assert = chai.assert;
 8
 9function print(circuit, w, s) {
10    console.log(s + ": " + w[circuit.getSignalIdx(s)]);
11}
12
13describe("Escalarmul test", function () {
14    let circuit;
15
16    this.timeout(100000);
17
18    before( async() => {
19        circuit = await tester(path.join(__dirname, "circuits", "escalarmulfix_test.circom"));
20    });
21
22    it("Should generate Same escalar mul", async () => {
23
24        const w = await circuit.calculateWitness({"e": 0});
25
26        await circuit.checkConstraints(w);
27
28        await circuit.assertOut(w, {out: [0,1]}, true);
29
30    });
31
32    it("Should generate Same escalar mul", async () => {
33
34        const w = await circuit.calculateWitness({"e": 1}, true);
35
36        await circuit.checkConstraints(w);
37
38        await circuit.assertOut(w, {out: babyjub.Base8});
39
40    });
41
42    it("Should generate scalar mul of a specific constant", async () => {
43
44        const s = Fr.e("2351960337287830298912035165133676222414898052661454064215017316447594616519");
45        const base8 = [
46            Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
47            Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
48        ];
49
50        const w = await circuit.calculateWitness({"e": s}, true);
51
52        await circuit.checkConstraints(w);
53
54        const expectedRes = babyjub.mulPointEscalar(base8, s);
55
56        await circuit.assertOut(w, {out: expectedRes});
57
58    });
59
60    it("Should generate scalar mul of the firsts 50 elements", async () => {
61
62        const base8 = [
63            Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
64            Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
65        ];
66
67        for (let i=0; i<50; i++) {
68            const s = Fr.e(i);
69
70            const w = await circuit.calculateWitness({"e": s}, true);
71
72            await circuit.checkConstraints(w);
73
74            const expectedRes = babyjub.mulPointEscalar(base8, s);
75
76            await circuit.assertOut(w, {out: expectedRes});
77        }
78    });
79
80    it("If multiply by order should return 0", async () => {
81
82        const w = await circuit.calculateWitness({"e": babyjub.subOrder }, true);
83
84        await circuit.checkConstraints(w);
85
86        await circuit.assertOut(w, {out: [0,1]});
87    });
88
89});
90