circomlib/circuits/escalarmulw4table.circom
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*/
19
20function pointAdd(x1,y1,x2,y2) {
21 var a = 168700;
22 var d = 168696;
23
24 var res[2];
25 res[0] = (x1*y2 + y1*x2) / (1 + d*x1*x2*y1*y2);
26 res[1] = (y1*y2 - a*x1*x2) / (1 - d*x1*x2*y1*y2);
27 return res;
28}
29
30function EscalarMulW4Table(base, k) {
31 var out[16][2];
32
33 var i;
34 var p[2];
35
36 var dbl = base;
37
38 for (i=0; i<k*4; i++) {
39 dbl = pointAdd(dbl[0], dbl[1], dbl[0], dbl[1]);
40 }
41
42 out[0][0] = 0;
43 out[0][1] = 1;
44 for (i=1; i<16; i++) {
45 p = pointAdd(out[i-1][0], out[i-1][1], dbl[0], dbl[1]);
46 out[i][0] = p[0];
47 out[i][1] = p[1];
48 }
49
50 return out;
51}