fix(decode): reject address words with non-zero upper bytes - #90
Merged
Merged
Conversation
decode_address returned the last 20 bytes of the ABI word and silently discarded the upper 12, so a malformed response like 0xffff...ffff<20-byte-addr> was accepted as a valid address. That is inconsistent with the rest of the module, which deliberately rejects non-canonical words: decode_bool rejects values other than 0/1 and decode_u64 rejects overflow. Reject a non-zero upper 12 bytes with the same ValueError style. Add tests/test_decode.py covering the address fix alongside the existing bool/u64/word strictness guards.
onbjerg
approved these changes
Sep 14, 2026
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.
Summary
decode_addressreturned the last 20 bytes of the ABI word and silently discarded the upper 12, so a malformed word such as0xffff…ffff<20-byte-addr>was accepted as a valid address:This is inconsistent with the rest of
_decode.py, which deliberately rejects non-canonical words —decode_boolrejects values other than0/1, anddecode_u64rejects overflow. A canonical ABI address word left-pads the 20-byte address with 12 zero bytes, so non-zero upper bytes signal a malformed response and shouldn't be quietly dropped.Fix
Reject a non-zero upper 12 bytes with the same
ValueErrorstyle the sibling decoders use:Canonical words decode exactly as before.
Tests
Adds
tests/test_decode.py(these internal decoders had no dedicated test file): the address strictness fix — canonical word accepted, non-zero upper bytes rejected, wrong length rejected — plus sibling guards fordecode_bool/decode_u64/decode_word.pytestpasses (272 passed, 36 skipped; +6).ruff checkandruff format --checkare clean.