arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/test/escalarmulfix.js
test/escalarmulfix.jsRaw
 1const chai = require("chai");
 2const path = require("path");
 3const bigInt = require("big-integer");
 4const tester = require("circom").tester;
 5const babyjub = require("../src/babyjub");
 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        // TODO
27        // assert(circuit.checkWitness(w));
28
29        await circuit.assertOut(w, {out: [0,1]});
30
31    });
32
33    it("Should generate Same escalar mul", async () => {
34
35        const w = await circuit.calculateWitness({"e": 1});
36
37        // TODO
38        // assert(circuit.checkWitness(w));
39
40        await circuit.assertOut(w, {out: babyjub.Base8});
41
42    });
43
44    it("Should generate scalar mul of a specific constant", async () => {
45
46        const s = bigInt("2351960337287830298912035165133676222414898052661454064215017316447594616519");
47        const base8 = [
48            bigInt("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
49            bigInt("16950150798460657717958625567821834550301663161624707787222815936182638968203")
50        ];
51
52        const w = await circuit.calculateWitness({"e": s});
53
54        // TODO
55        // assert(circuit.checkWitness(w));
56
57        const expectedRes = babyjub.mulPointEscalar(base8, s);
58
59        await circuit.assertOut(w, {out: expectedRes});
60
61    });
62
63    it("Should generate scalar mul of the firsts 50 elements", async () => {
64
65        const base8 = [
66            bigInt("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
67            bigInt("16950150798460657717958625567821834550301663161624707787222815936182638968203")
68        ];
69
70        for (let i=0; i<50; i++) {
71            const s = bigInt(i);
72
73            const w = await circuit.calculateWitness({"e": s});
74
75            // TODO
76            // assert(circuit.checkWitness(w));
77
78            const expectedRes = babyjub.mulPointEscalar(base8, s);
79
80            await circuit.assertOut(w, {out: expectedRes});
81        }
82    });
83
84    it("If multiply by order should return 0", async () => {
85
86        const w = await circuit.calculateWitness({"e": babyjub.subOrder });
87
88        // TODO
89        // assert(circuit.checkWitness(w));
90
91        await circuit.assertOut(w, {out: [0,1]});
92    });
93
94});
95