Skip to content

fix(decode): reject address words with non-zero upper bytes - #90

Merged
onbjerg merged 1 commit into
tempoxyz:mainfrom
devorun:fix/decode-address-upper-bytes
Sep 14, 2026
Merged

onbjerg merged 1 commit into
tempoxyz:mainfrom
devorun:fix/decode-address-upper-bytes

Conversation

@devorun

@devorun devorun commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

decode_address returned the last 20 bytes of the ABI word and silently discarded the upper 12, so a malformed word such as 0xffff…ffff<20-byte-addr> was accepted as a valid address:

return to_checksum_address(decode_word(result, name)[-20:])

This is inconsistent with the rest of _decode.py, which deliberately rejects non-canonical words — decode_bool rejects values other than 0/1, and decode_u64 rejects 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 ValueError style the sibling decoders use:

word = decode_word(result, name)
if word[:12] != b"\x00" * 12:
    raise ValueError(f"{name} result has non-zero upper bytes for a 20-byte address")
return to_checksum_address(word[-20:])

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 for decode_bool / decode_u64 / decode_word.

pytest passes (272 passed, 36 skipped; +6). ruff check and ruff format --check are clean.

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
onbjerg merged commit ead6c34 into tempoxyz:main Sep 14, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants