Skip to content

feat(sol-types): add strict ABI decoding - #1180

Merged
DaniPopes merged 18 commits into
mainfrom
dani/strict-abi-layout
Sep 2, 2026
Merged

DaniPopes merged 18 commits into
mainfrom
dani/strict-abi-layout

Conversation

@DaniPopes

@DaniPopes DaniPopes commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

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.

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.
@DaniPopes
DaniPopes marked this pull request as ready for review September 1, 2026 15:26
@DaniPopes
DaniPopes requested a review from mattsse as a code owner September 1, 2026 15:26
@decofe decofe mentioned this pull request Sep 1, 2026
3 tasks
DaniPopes and others added 8 commits September 1, 2026 17:45
Keep nested static composites from moving their containing strict tail
boundary backward.
Reject noncanonical bool words and validate indexed event topics when
decoder validation or strict mode is enabled.
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 tempoxyz-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️ 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_child are public and take shared borrows, while Drop writes the parent frontier. Please double-check the intended public contract for multiple live children; using max(existing, propagated) or documenting/enforcing a single-live-child invariant would reduce future false-accept/false-reject risk.
  • ⚡ Diagnostics on exhausted decoders: Debug for Decoder indexes body[self.offset / 32] and can panic when offset == 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 SolType paths but not the dynamic/JSON-ABI path most likely to decode third-party ABIs.

Comment thread crates/sol-types/src/abi/token.rs Resolved
Comment thread crates/sol-types/src/types/event/mod.rs Resolved
Comment thread crates/sol-types/src/abi/decoder.rs Resolved
Comment thread crates/sol-types/src/types/data_type.rs Resolved
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.
@github-project-automation github-project-automation Bot moved this to Reviewed in Alloy Sep 2, 2026

@tempoxyz-bot tempoxyz-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️ 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 rejects validate(true) even when the default implementation can still honor validation via existing SolType decode helpers. Prefer explicit get_strict() gating or derive equality from AbiDecoderConfig::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.

Comment thread crates/sol-types/src/abi/token.rs Resolved
Comment thread crates/sol-types/src/abi/token.rs Resolved
Comment thread crates/sol-types/src/errors.rs Resolved
Allow non-strict configs through legacy defaults, qualify generated
event dispatch, and validate strict dynamic elements before growing
the outer token buffer.
@DaniPopes
DaniPopes force-pushed the dani/strict-abi-layout branch 5 times, most recently from 8655b58 to eb84e6e Compare September 2, 2026 18:08
@DaniPopes
DaniPopes enabled auto-merge (squash) September 2, 2026 18:10
@DaniPopes
DaniPopes merged commit d459606 into main Sep 2, 2026
31 checks passed
@DaniPopes
DaniPopes deleted the dani/strict-abi-layout branch September 2, 2026 18:23
@github-project-automation github-project-automation Bot moved this from Reviewed to Done in Alloy Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants