Skip to content
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
gsalgado:fix-ecdsa
Aug 28, 2017
Merged

Fix encoding of ECDSA signatures and public keys#81
pipermerriam merged 1 commit intoethereum:masterfrom
gsalgado:fix-ecdsa

Conversation

@gsalgado
Copy link
Contributor

@gsalgado gsalgado commented Aug 23, 2017

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

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.
Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

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

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(
Copy link
Member

Choose a reason for hiding this comment

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

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
Copy link
Member

Choose a reason for hiding this comment

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

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.

@pipermerriam pipermerriam merged commit 6ffb7f7 into ethereum:master Aug 28, 2017
@gsalgado gsalgado mentioned this pull request Aug 28, 2017
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants