You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
eth_address() accepts checksum addresses without the 0x prefix or with extra "0x" inserted #570
On current master (22786cc), eth_address() accepts strings that are not Ethereum addresses as long as they contain a valid EIP-55 mixed-case address once every "0x" is removed. The all-lowercase and all-uppercase forms are correctly required to start with 0x, but the mixed-case checksum path is not.
Reproduction, with the crypto-eth-addresses extra installed:
importvalidatorsa="0x5AEDA56215b167893e80B4fE645BA6d5Bab767DE"# valid, from the test suitevalidators.eth_address(a) # True (expected)validators.eth_address(a[2:]) # True, no 0x prefixvalidators.eth_address("0x0x"+a[2:]) # True, doubled prefixvalidators.eth_address(a[:16] +"0x"+a[16:]) # True, "0x" in the middlevalidators.eth_address(a+"0x") # True, trailing "0x"validators.eth_address(a.lower()[2:]) # ValidationError, so the unprefixed form is not meant to be accepted
All of the True results after the first one should be ValidationError. The 44-character values are not addresses in any format, and an application that stores or forwards the value as given (for example to a wallet or RPC call) ends up with a string the rest of the stack will reject or misread.
The cause is the first line of _validate_eth_checksum_address in src/validators/crypto_addresses/eth_address.py, which does addr.replace("0x", ""). That removes every occurrence of "0x" rather than only the leading prefix, and it also lets a value with no prefix through. Matching the whole value against 0x[0-9a-fA-F]{40} first and then dropping the first two characters fixes it without changing any currently valid input. I have a small patch with regression tests if that is useful.
I searched existing issues and PRs (eth_address, ethereum, eth checksum, 0x prefix); #466 and #509 tightened other parts of this validator but did not touch the prefix handling.
Activity