I’ve been following along the ECDSA signing code and have come across what I think is an incorrect comment. In secp256k1_ecdsa_sig_sign
the code makes the following recommendation:
However, these two conditions are not actually checked before calling. The main call doesn’t:
Note that sigr
is the nonce (R)’s x coordinate reduced modulo q as a scalar. The caller is only checking properties of the secret nonce not sigr
(it doesn’t even compute the point for R). Maybe this code was meant to check the secret nonce that’s passed in instead?
There doesn’t seem to be any problem with sigr
overlfowing (the verification algorithm actually accounts for this possibility by adding the curve order to sigr
if it doesn’t work the first time!). sigr
being 0 is a problem but the probability of this happening is so low I wouldn’t bother accounting for it. I think this comment and VERIFY_CHECKS can be removed.
More generally there doesn’t seem to be a problem with the secret nonce overflowing either but the while loop in the caller enforces that and that it’s not 0.