grapevine-sonobe/circom/node_modules/circomlib/circuits/escalarmulw4table.circom
circom/node_modules/circomlib/circuits/escalarmulw4table.circomRaw
1/*
2 Copyright 2018 0KIMS association.
3
4 This file is part of circom (Zero Knowledge Circuit Compiler).
5
6 circom 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 circom 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 circom. If not, see <https://www.gnu.org/licenses/>.
18*/
19pragma circom 2.0.0;
20
21function pointAdd(x1,y1,x2,y2) {
22 var a = 168700;
23 var d = 168696;
24
25 var res[2];
26 res[0] = (x1*y2 + y1*x2) / (1 + d*x1*x2*y1*y2);
27 res[1] = (y1*y2 - a*x1*x2) / (1 - d*x1*x2*y1*y2);
28 return res;
29}
30
31function EscalarMulW4Table(base, k) {
32 var out[16][2];
33
34 var i;
35 var p[2];
36
37 var dbl[2] = base;
38
39 for (i=0; i<k*4; i++) {
40 dbl = pointAdd(dbl[0], dbl[1], dbl[0], dbl[1]);
41 }
42
43 out[0][0] = 0;
44 out[0][1] = 1;
45 for (i=1; i<16; i++) {
46 p = pointAdd(out[i-1][0], out[i-1][1], dbl[0], dbl[1]);
47 out[i][0] = p[0];
48 out[i][1] = p[1];
49 }
50
51 return out;
52}