This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Fix encoding of ECDSA signatures and public keys#81
Merged
pipermerriam merged 1 commit intoethereum:masterfrom Aug 28, 2017
Merged
Fix encoding of ECDSA signatures and public keys#81pipermerriam merged 1 commit intoethereum:masterfrom
pipermerriam merged 1 commit intoethereum:masterfrom
Conversation
We were using the Bitcoin format when encoding signatures, with the recovery id (v) at the first byte. Also change decode_public_key() to accept only 64-bytes long public keys and encode_raw_public_key() to generate the 64-bytes version as well (without the \x04 prefix) as that's what we must use when generating addresses.
pipermerriam
approved these changes
Aug 28, 2017
Member
pipermerriam
left a comment
There was a problem hiding this comment.
Going to open an easy-pickins ticket to extract the public key validation function.
| def public_key_to_address(public_key): | ||
| return keccak(public_key[1:])[-20:] | ||
| if len(public_key) != 64: | ||
| raise ValueError( |
Member
There was a problem hiding this comment.
This strikes me as a good re-usable validation function since I bet we run into many more situations where we want to validate public keys.
I see this same code repeated in evm/utils/secp256k1.py.
| try: | ||
| backends.append(CoinCurveECCBackend()) | ||
| except ImportError: | ||
| pass |
Member
There was a problem hiding this comment.
This worries me as it could lead to a misconfiguration in CI leaving the coincurve backend untested because it simply gets skipped.
In the same vein, I dislike having coincurve be a development dependency because I want to be able to test the library without it installed to know that it isn't required. Not sure what the best approach here is.
Closed
pacrob
added a commit
to pacrob/py-evm
that referenced
this pull request
Dec 18, 2023
…m#81) * apply template updates found following merge with eth-typing * add build as a dev dependency * remove timeout from pytest.ini, it doesn't do anything without pytest-timeout as a dep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We were using the Bitcoin format when encoding signatures, with the recovery id (v) at the first byte.
https://github.com/ethereum/go-ethereum/blob/master/crypto/signature_nocgo.go#L55
Also change decode_public_key() to accept only 64-bytes long public keys and encode_raw_public_key() to generate the 64-bytes version as well (without the \x04 prefix) as that's what we must use when generating addresses.
At this point we don't have many places using the non-raw ECCBackend APIs, so it's probably ok to leave it as is but at some point I think it'd be nice to create custom types for public/private keys and signatures, with better docs and validation checks so that there's less room for mistakes and we get meaningful errors when things go wrong