circomlib/circuit/escalarmulw4table.circom
circuit/escalarmulw4table.circomRaw
1function pointAdd(x1,y1,x2,y2) {
2 var a = 168700;
3 var d = 168696;
4
5 var res[2];
6 res[0] = (x1*y2 + y1*x2) / (1 + d*x1*x2*y1*y2);
7 res[1] = (y1*y2 - a*x1*x2) / (1 - d*x1*x2*y1*y2);
8 return res;
9}
10
11template EscalarMulW4Table(base, k) {
12 signal output out[16][2];
13
14 var i;
15 var p[2];
16
17 var dbl = base;
18
19 for (i=0; i<k*4; i++) {
20 dbl = pointAdd(dbl[0], dbl[1], dbl[0], dbl[1]);
21 }
22
23 out[0][0] <== 0;
24 out[0][1] <== 1;
25 for (i=1; i<16; i++) {
26 p = pointAdd(out[i-1][0], out[i-1][1], dbl[0], dbl[1]);
27 out[i][0] <== p[0];
28 out[i][1] <== p[1];
29 }
30}