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.

30 lines
619 B

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