Repository navigation
feat(sol-types): add strict ABI decoding - #1180
Conversation
Initialize the root dynamic-array zone before following its offset. Reject trailing strict input and cover both paths with regression tests.
Cover dynamic fixed arrays and empty dynamic tails in strict decoding.
Show that strict decoding rejects aliased nested tails within a linear memory budget, before the permissive cubic allocation path.
Co-authored-by: Derek Cofausper <[email protected]>
Keep nested static composites from moving their containing strict tail boundary backward.
…i/strict-abi-layout
Co-authored-by: Derek Cofausper <[email protected]>
Reject noncanonical bool words and validate indexed event topics when decoder validation or strict mode is enabled.
…i/strict-abi-layout
Forward decoder configuration through generated event interfaces so strict mode validates indexed topics and event data.
Route default event decoding through its configured counterpart and share generated event-interface dispatch.
tempoxyz-bot
left a comment
There was a problem hiding this comment.
👁️ Cyclops Review
VULNERABILITY_FOUND: PR #1180 adds strict/configured ABI decoding, but several verified gaps remain around paths that do not participate in the new strict protocol or allocate after decoder accounting ends. Inline comments cover the diff-local issues.
Body-only findings
🚨 [SECURITY] Strict validation errors re-encode and hex-encode full tokens outside memory_limit
Severity: Low
File: crates/sol-types/src/errors.rs:166
strict(true) now implies type validation, but validation failures call Error::type_check_fail_token, which re-encodes the entire token and hex-encodes the result after Decoder accounting is gone. Large invalid strings/arrays/structs/calls/errors can exceed the configured memory boundary on the error path and retain a two-bytes-per-byte hex dump.
Recommended Fix: Make TypeCheckFail bounded (expected type plus length/hash/small prefix), or charge/fallibly allocate diagnostic data against the configured budget.
⚠️ [ISSUE] alloy-dyn-abi has not adopted the new strict decoder protocol
Severity: Medium
File: crates/dyn-abi/src/dynamic/token.rs:142
The strict protocol requires each composite decoder zone to seed Decoder::strict_next_offset with set_strict_head_words() before following dynamic offsets. The static token decoder was updated, but alloy-dyn-abi has a parallel decoder loop using take_indirection()/raw_child() with no set_strict_head_words() calls. Today strict/configured decoding is unavailable for the dynamic JSON-ABI path; if config plumbing is added later, canonical dynamic inputs would fail with ReserMismatch.
Recommended Fix: Implement the strict-zone protocol in alloy-dyn-abi before exposing configured dynamic decoding, or centralize the protocol inside Decoder so parallel decoders cannot forget it.
Reviewer Callouts
- ⚡ Drop-based strict frontier:
Decoder::child/raw_childare public and take shared borrows, whileDropwrites the parent frontier. Please double-check the intended public contract for multiple live children; usingmax(existing, propagated)or documenting/enforcing a single-live-child invariant would reduce future false-accept/false-reject risk. - ⚡ Diagnostics on exhausted decoders:
Debug for Decoderindexesbody[self.offset / 32]and can panic whenoffset == buf.len(). The PR makes exhausted child decoders a normal terminal state, so this is worth fixing if strict-mode diagnostics will print decoders. - ⚡ Dynamic ABI hardening coverage: The strict feature currently protects compile-time-known
SolTypepaths but not the dynamic/JSON-ABI path most likely to decode third-party ABIs.
Bound zero-sized dynamic arrays, diagnostics, and generated log errors. Reject unsupported custom configs on legacy interfaces and prepare the dynamic ABI decoder for strict offset checks.
Defer candidate resource errors until every anonymous event has been tried so a later matching event can decode within the configured limit.
tempoxyz-bot
left a comment
There was a problem hiding this comment.
👁️ Cyclops Review
VULNERABILITY_FOUND: PR #1180 adds strict/configured ABI decoding and closes several previously reported strict-mode gaps, but verified regressions remain in memory accounting, public default-trait compatibility, generated event-interface dispatch, and zero-sized/dynamic-array strict handling. Inline comments cover the diff-local issues.
Body-only findings
🚨 [SECURITY] Detokenization allocations bypass AbiDecoderConfig::memory_limit
Severity: Medium
File: crates/sol-types/src/types/data_type.rs:547 (token-stage accounting at crates/sol-types/src/abi/token.rs:461)
The decoder accounts only for temporary ABI token allocations while constructing DynSeqToken. After abi::decode_with_config returns, SolType::abi_decode_with_config detokenizes into owned Rust values after the shared decoder budget has been dropped. A canonical strict bytes[] with 1,024 empty elements succeeds with a 16,384-byte memory limit, then Array<Bytes>::detokenize allocates a Vec<Bytes> backing buffer of at least 32,768 bytes outside the configured limit.
Recommended Fix: Keep memory-budget state alive through validation and detokenization, and charge allocations for destination Rust collections/conversions, not just temporary token storage. Add regressions asserting that bytes[]/String detokenization cannot allocate beyond a small configured limit.
Reviewer Callouts
- ⚡
is_default()as a capability gate: it re-encodes default values and rejectsvalidate(true)even when the default implementation can still honor validation via existingSolTypedecode helpers. Prefer explicitget_strict()gating or derive equality fromAbiDecoderConfig::new(). - ⚡ Anonymous event fan-out: each anonymous candidate decode gets a fresh decoder budget, so worst-case allocation churn can scale with the number of anonymous variants. Consider whether resource accounting should be shared across a generated interface decode attempt.
Allow non-strict configs through legacy defaults, qualify generated event dispatch, and validate strict dynamic elements before growing the outer token buffer.
8655b58 to
eb84e6e
Compare
Add an opt-in strict ABI decoder that requires each dynamic tail to begin at the next canonical offset. The decoder checks offsets before following child decoders or reserving memory, so aliased nested tails cannot repeatedly expand allocations.
Strict mode also enables type validation, rejects non-zero dynamic-byte padding, and rejects gaps and trailing data. Validation now rejects noncanonical bool values and dirty indexed topics. The tests cover canonical nested values, aliases, direct dynamic-array sequences, dynamic fixed arrays, and empty dynamic tails.