-
Notifications
You must be signed in to change notification settings - Fork 20.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto/secp256k1: fix undefined behavior in BitCurve.Add #22621
Conversation
This commit fixes the behavior of (BitCurve).Add() to be more inline with btcd. It changes two different bugs that occured. 1) When adding a point at infinity to another point, the other point should be returned. While this is undefined behavior, it is better to be more inline with the go standard library. Thus (0,0) + (a, b) = (a,b) 2) Adding the same point to itself produced the point at infinity. This is incorrect, now doubleJacobian is used to correctly calculate it. This is also similar to the go standard library. Thus (a,b) + (a,b) == 2* (a,b) and not (0,0) anymore.
We need to find a way to not copy the code into the fuzzer. If it's absolutely not possible to build the fuzzer with cgo, we can do it with build tags in crypto/secp256k1. |
@fjl It's absolutely not possible to build it with cgo, see also dvyukov/go-fuzz#101 dvyukov/go-fuzz#171 We would need to either modify |
) This commit changes the behavior of BitCurve.Add to be more inline with btcd. It fixes two different bugs: 1) When adding a point at infinity to another point, the other point should be returned. While this is undefined behavior, it is better to be more inline with the go standard library. Thus (0,0) + (a, b) = (a,b) 2) Adding the same point to itself produced the point at infinity. This is incorrect, now doubleJacobian is used to correctly calculate it. Thus (a,b) + (a,b) == 2* (a,b) and not (0,0) anymore. The change also adds a differential fuzzer for Add, testing it against btcd. Co-authored-by: Felix Lange <[email protected]>
This PR fixes the behavior of (BitCurve).Add() to be more inline
with btcd and the standard library. It changes two different bugs that occured.
When adding a point at infinity to another point, the other point
should be returned. While this is undefined behavior, it is better
to be more inline with the go standard library.
Thus (0,0) + (a, b) = (a,b)
Adding the same point to itself produced the point at infinity.
This is incorrect, now doubleJacobian is used to correctly calculate it.
This is also similar to the go standard library.
Thus (a,b) + (a,b) == 2* (a,b) and not (0,0) anymore
It also adds a differential fuzzer to test it against btcd.