arnaucube
arnaucube/websnarkPublic Self-hosted repository
websnark/src/build_testg1.js
src/build_testg1.jsRaw
 1/*
 2    Copyright 2019 0KIMS association.
 3
 4    This file is part of websnark (Web Assembly zkSnark Prover).
 5
 6    websnark is a free software: you can redistribute it and/or modify it
 7    under the terms of the GNU General Public License as published by
 8    the Free Software Foundation, either version 3 of the License, or
 9    (at your option) any later version.
10
11    websnark is distributed in the hope that it will be useful, but WITHOUT
12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14    License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with websnark. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20const bigInt = require("big-integer");
21
22module.exports = function buildTestAddG1(module) {
23
24    function buildTestAddG1() {
25        const f = module.addFunction("testAddG1");
26        f.addParam("n", "i32");
27        f.addParam("pP", "i32");
28        f.addParam("pR", "i32");
29        f.addLocal("i", "i32");
30
31        const c = f.getCodeBuilder();
32
33        f.addCode(c.call("g1_zero", c.getLocal("pR")));
34
35        f.addCode(c.setLocal("i", c.getLocal("n")));
36        f.addCode(c.block(c.loop(
37            c.call("g1_add", c.getLocal("pP"), c.getLocal("pR"), c.getLocal("pR")),
38            c.setLocal("i", c.i32_sub(c.getLocal("i"), c.i32_const(1))),
39            c.br_if(1, c.i32_eqz ( c.getLocal("i") )),
40            c.br(0)
41        )));
42    }
43
44    buildTestAddG1();
45    module.exportFunction("testAddG1");
46};
47