Skip to content
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

Issue in affineFromJacobian #1

Open
MariusVanDerWijden opened this issue Nov 17, 2020 · 0 comments
Open

Issue in affineFromJacobian #1

MariusVanDerWijden opened this issue Nov 17, 2020 · 0 comments

Comments

@MariusVanDerWijden
Copy link

Solution:

diff --git a/crypto/secp256k1/curve.go b/crypto/secp256k1/curve.go
index 5409ee1d2..c305f58da 100644
--- a/crypto/secp256k1/curve.go
+++ b/crypto/secp256k1/curve.go
@@ -116,6 +116,9 @@ func (BitCurve *BitCurve) IsOnCurve(x, y *big.Int) bool {
 // affineFromJacobian reverses the Jacobian transform. See the comment at the
 // top of the file.
 func (BitCurve *BitCurve) affineFromJacobian(x, y, z *big.Int) (xOut, yOut *big.Int) {
+       if z.Sign() == 0 {
+               return new(big.Int), new(big.Int)
+       }
        zinv := new(big.Int).ModInverse(z, BitCurve.P)
        zinvsq := new(big.Int).Mul(zinv, zinv)

Tests:

func TestAffine(t *testing.T) {
	x := new(big.Int)
	y := new(big.Int)
	z := new(big.Int)
	theCurve.affineFromJacobian(x, y, z)
}

func TestAdd(t *testing.T) {
	x := new(big.Int)
	y := new(big.Int)
	z := new(big.Int)
	w := new(big.Int)
	theCurve.Add(x, y, z, w)
}

see also: ethereum/go-ethereum#18419

@MariusVanDerWijden MariusVanDerWijden changed the title Critical issue in affineFromJacobian Issue in affineFromJacobian Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant