Repository navigation
Conversation
The EIP-55 checksum path stripped every "0x" occurrence with str.replace before checking for 40 hex digits, so eth_address() accepted checksum addresses with no prefix, a doubled prefix, or "0x" inserted anywhere in the string. Match the full 0x-prefixed address first and drop only the leading prefix.
This branch has not been deployed
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #570.
The EIP-55 checksum path in eth_address() began with addr.replace("0x", ""), which strips every "0x" in the value, not just a leading prefix. As a result a mixed-case checksum address was accepted with no prefix at all, with a doubled prefix, or with "0x" inserted anywhere in the string, for example "0x5AEDA56215b1670x893e80B4fE645BA6d5Bab767DE". The lowercase and uppercase forms already required the prefix, so the behaviour was also inconsistent between the two paths.
This change matches the full value against 0x[0-9a-fA-F]{40} before computing the checksum and then drops only the first two characters. Every address that was valid before is still valid.
I added four invalid cases to tests/crypto_addresses/test_eth_address.py (no prefix, doubled prefix, "0x" in the middle, trailing "0x"). All four fail on master and pass with the change. The full suite passes locally (1520 passed, including doctests), and ruff check, ruff format --check and bandit report no issues. pyright reports the same four eth_hash import errors with and without this change in my environment, so nothing new there.