It is possible, by using the value β from the endomorphism optimization, to obtain two points P = x : y : z and Q = βx : -y : z which are both on the curve. If you attempt to add these points using secp256k1_gej_add_ge
, it incorrectly returns infinity, since it sees that the z-coordinates match and the y-coordinates are negative.
Specifically, it computes the value M = Y_1 * Z_2^3 + Y_2 * Z_1^3, and sets the returned z-coordinate to 2 * M * z_1z_2, and of course M will be zero for these two points. So it is not a simple matter of fixing how the infinity flag is set, the algebra actually does not compute the complete group law. This is derived in the paper “Eric Brier and Marc Joye, Weierstrass Elliptic Curves and Side-Channel Attacks” in Proposition 1, which explicitly assumes that the points P and Q don’t happen.
The current secp256k1 API does not use this function except in one place, secp256k1_ecmult_gen
, where it is impossible to get such an input to the function, so right now this bug is harmless. However https://github.com/bitcoin/secp256k1/pull/252 exposes it more directly, since when the endomorphism optimization is turned on roughly half of all scalars produce a bad pair P, Q in the wNAF ladder.