grapevine-sonobe/circom/node_modules/circomlib/test/escalarmulfix.js
circom/node_modules/circomlib/test/escalarmulfix.jsRaw
1const chai = require("chai");
2const path = require("path");
3const wasm_tester = require("circom_tester").wasm;
4const buildBabyjub = require("circomlibjs").buildBabyjub;
5const Scalar = require("ffjavascript").Scalar;
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 babyJub;
15 let Fr;
16 let circuit;
17
18 this.timeout(100000);
19
20
21 before( async() => {
22 babyJub = await buildBabyjub();
23 Fr = babyJub.F;
24 circuit = await wasm_tester(path.join(__dirname, "circuits", "escalarmulfix_test.circom"));
25 });
26
27 it("Should generate Same escalar mul", async () => {
28
29 const w = await circuit.calculateWitness({"e": 0});
30
31 await circuit.checkConstraints(w);
32
33 await circuit.assertOut(w, {out: [0,1]}, true);
34
35 });
36
37 it("Should generate Same escalar mul", async () => {
38
39 const w = await circuit.calculateWitness({"e": 1}, true);
40
41 await circuit.checkConstraints(w);
42
43 await circuit.assertOut(w, {out: [Fr.toObject(babyJub.Base8[0]), Fr.toObject(babyJub.Base8[1])]});
44
45 });
46
47 it("Should generate scalar mul of a specific constant", async () => {
48
49 const s = Scalar.e("2351960337287830298912035165133676222414898052661454064215017316447594616519");
50 const base8 = [
51 Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
52 Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
53 ];
54
55 const w = await circuit.calculateWitness({"e": s}, true);
56
57 await circuit.checkConstraints(w);
58
59 const expectedRes = babyJub.mulPointEscalar(base8, s);
60
61 await circuit.assertOut(w, {out: [Fr.toObject(expectedRes[0]), Fr.toObject(expectedRes[1])]});
62
63 });
64
65 it("Should generate scalar mul of the firsts 50 elements", async () => {
66
67 const base8 = [
68 Fr.e("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
69 Fr.e("16950150798460657717958625567821834550301663161624707787222815936182638968203")
70 ];
71
72 for (let i=0; i<50; i++) {
73 const s = Scalar.e(i);
74
75 const w = await circuit.calculateWitness({"e": s}, true);
76
77 await circuit.checkConstraints(w);
78
79 const expectedRes = babyJub.mulPointEscalar(base8, s);
80
81 await circuit.assertOut(w, {out: [Fr.toObject(expectedRes[0]), Fr.toObject(expectedRes[1])]});
82 }
83 });
84
85 it("If multiply by order should return 0", async () => {
86
87 const w = await circuit.calculateWitness({"e": babyJub.subOrder }, true);
88
89 await circuit.checkConstraints(w);
90
91 await circuit.assertOut(w, {out: [0,1]});
92 });
93
94});
95