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

EI-528 - Revert to go-ethereum for secp256k functionality (introduced… #33

Merged
merged 2 commits into from
Jan 7, 2022

Conversation

vtermanis
Copy link
Member

@vtermanis vtermanis commented Jan 5, 2022

… in 398057a)

Notes:

  • v1.16 compatible via go mod tidy -compat=1.17 -compat=1.16 Now v1.17 targeted, with go mod tidy -compat=1.17
  • Not a straight-up revert since keeping minor refactoring which also was in 398057a

… in 398057a)

- github.com/fomichev/secp256k1 has negative performance impact
- vulnerability associated with go-ethereum is not relevant (i.e. code not touched)
  See also ethereum/go-ethereum#23866
- Bump github.com/ethereum/go-ethereum to v1.10.14
- Update go.mod
- Update GH workflow
@vtermanis
Copy link
Member Author

I suggest we add open an issue with the following text to explain why the related CVE is a non-issue:


CVE-2021-43668 (github.com/ethereum/go-ethereum)

iotics-identity-go library uses go-ethereum but only a very small set of library functions from it, namely:

  • go-ethereum/crypto.UnmarshalPubkey() (code)
  • go-ethereum/crypto/secp256k1.BitCurve (tests only)

The aforementioned CVE affects only go-ethereum's geth executable and its use of github.com/syndtr/goleveldb . Because of this, iotics-identity-go is not affected by this security issue:

$ go mod why -m github.com/ethereum/go-ethereum
# github.com/ethereum/go-ethereum
github.com/Iotic-Labs/iotics-identity-go/pkg/crypto
github.com/ethereum/go-ethereum/crypto

$ go mod why -m github.com/syndtr/goleveldb
# github.com/syndtr/goleveldb
(main module does not need module github.com/syndtr/goleveldb)

Ticket references

@@ -49,7 +28,7 @@ func GetPublicKeysFromPrivateKey(privateKey *ecdsa.PrivateKey) ([]byte, string,
return nil, "", errors.New("error casting public key to ECDSA")
}

publicKeyDer := elliptic.Marshal(secp256k1.SECP256K1(), publicKeyECDSA.X, publicKeyECDSA.Y)
publicKeyDer := ethcrypto.FromECDSAPub(publicKeyECDSA)
Copy link
Member

@smartrics smartrics Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is simply

func FromECDSAPub(pub *ecdsa.PublicKey) []byte {
	if pub == nil || pub.X == nil || pub.Y == nil {
		return nil
	}
	return elliptic.Marshal(S256(), pub.X, pub.Y)
}

maybe we can inline it in our SDK being just a validation on the elliptic marshaller?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But: S256() is something which belongs to go-ethereum - what would the benefit be of in-lining this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha - i missed it

return nil, fmt.Errorf("invalid secp256k1 public key")
}
return &ecdsa.PublicKey{Curve: curve, X: x, Y: y}, nil
return ethcrypto.UnmarshalPubkey(publicKeyBytes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a utility method that's only wrapping someother code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's scope to inline it (copy/paste)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(As above - uses S256 which is a go-ethereum/crypto definition.) The point is that the general golang crypto methods don't implement secp256k1)

Copy link
Member

@smartrics smartrics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vtermanis if we were to copy paste the three methods we would not really dup any code since the methods are just utilities (there's no logic at all except validation)
we should then avoid go-ethereum altogether and make it simpler overall
this is preached on the basis that we're only reusing utilities rather than logic

@vtermanis
Copy link
Member Author

we should then avoid go-ethereum altogether and make it simpler overall

I don't think we do avoid it because of the usage of of S256 from here

@smartrics
Copy link
Member

Text in this comment looks good to me

@vtermanis vtermanis merged commit 90cce8a into main Jan 7, 2022
@vtermanis vtermanis deleted the ei-528 branch January 7, 2022 11:55
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

Successfully merging this pull request may close these issues.

2 participants