I wrote a solidity smart contract for elliptic curve point addition in Jacobian coordinates.
Jacobian coordinates: [X,Y,Z] Affine representation: [x,y]=[X/Z^2, Y/Z^3]
I used the following formulas: Link. My code seems to work fine however my questions are:
What is the additive inverse in Jacobian coordinates? Is it the point at infinity and the result therefore: P-P=[0,1,0]?
My elliptic curve multiplication function seems to have an error, any idea? I think I need to set the start value of R to "additive zero for points".
// function for elliptic curve multiplication in jacobian coordinates using Double-and-add method function ecmul(uint256[3] P, uint256 d) constant returns (uint256[3] R) { R[0]=0; R[1]=0; R[2]=0; //return (0,0) if d=0 or (x1,y1)=(0,0) if (d == 0 || ((P[0]==0) && (P[1]==0)) ) { return (R); } uint256[3] memory T; T[0]=P[0]; //x-coordinate temp T[1]=P[1]; //y-coordinate temp T[2]=P[2]; //z-coordiante temp while (d != 0) { if ((d & 1) == 1) { //if last bit is 1 add T to result R = ecadd(R,T); } T = ecdouble(T); //double temporary coordinates d=d/2; //"cut off" last bit } return R; }