Repository navigation
Conversation
DynSolEvent::decode_log_parts decoded the body data before fully validating the topic count. The up-front size_hint check only fires for exact-size iterators, so a log with a mismatched topic count supplied via a non-exact iterator (filter/map/streaming) reached the body decode and failed with a confusing Overrun instead of TopicLengthMismatch. This happens in practice because ERC-20 and ERC-721 Transfer share the same topic0: an ERC-721 transfer log (4 topics, empty data) decoded against the ERC-20 Transfer ABI displaced the body words and overran. Decode the indexed topics, then check the topic count, then decode the body. Too-few topics now also report TopicLengthMismatch rather than silently producing a short indexed list. Closes alloy-rs/alloy#2243
satyakwok
force-pushed
the
fix/dyn-abi-event-topic-count-before-body
branch
from
June 10, 2026 11:50
bc0dabf to
ff7bc47
Compare
DaniPopes
approved these changes
Jun 10, 2026
DaniPopes
enabled auto-merge (squash)
June 10, 2026 20:19
DaniPopes
disabled auto-merge
June 10, 2026 20:22
Contributor
Author
|
Thanks for the review and the clippy fix — should've run clippy with |
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 #1123.
Problem
DynSolEvent::decode_log_partsdecoded the body data before fully validating the topic count. The up-frontsize_hintcheck only fires for exact-size iterators, so a log whose topic count does not match the event — when the topics are supplied via a non-exact iterator (filter/map/streaming) — reached the body decode and failed with a confusingOverruninstead ofTopicLengthMismatch.This shows up in practice because ERC-20 and ERC-721
Transfershare the sametopic0(keccak("Transfer(address,address,uint256)")), so a topic-only filter matches both. Decoding an ERC-721 transfer log (4 topics, empty data) against the ERC-20TransferABI displaced the body words and overran:Fix
Decode the indexed topics, validate the topic count, then decode the body. Running out of topics now also reports
TopicLengthMismatchrather than silently producing a short indexed list. Valid logs are unaffected; the earlysize_hintfast-path is kept.No public API or error-variant changes (
TopicLengthMismatchalready exists).Tests
topic_count_is_validated_before_body— over-count via both exact and non-exact iterators (the reported bug).too_few_topics_is_a_length_mismatch— under-count via a non-exact iterator.it_decodes_logs_with_indexed_params.cargo test -p alloy-dyn-abi→ 160 passed;cargo fmt --checkclean;clippy --all-featureswith-D warningsclean.