You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5 KiB

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