Skip to content

feat(common): decoding external contracts - #16766

Open
sakulstra wants to merge 18 commits into
foundry-rs:masterfrom
sakulstra:feat/decoding-external-contracts
Open

feat(common): decoding external contracts#16766
sakulstra wants to merge 18 commits into
foundry-rs:masterfrom
sakulstra:feat/decoding-external-contracts

Conversation

@sakulstra

Copy link
Copy Markdown
Contributor

Motivation

A couple months ago i started #13417 and while i completely forgot about that pr, seems like multiple other ppl would appreciate it as well #13304 (comment) so trying to revive it against current foundry.

Adding state decoding for external contracts in storage diffs. This features is incredibly handy when simulating complex contract upgrades or when simulating complex transactions (or even for seemingly trivial ones).

Solution

Introducing a new flag decode_external_storage that fetches external contract sources from explorers, so we can render a rich diff in json state diff.

PR Checklist

  • Added Tests
  • Added ~Documentation
  • No breaking changes

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

✅ Changelog found

The deterministic check will validate the changed entry.

Decode storage writes with the recorded bytecode address and chain
instead
of following current explorer proxy hints. Reuse local layouts only when
the recorded chain and fork match the active context, prefer exact
bytecode
matches over proxy heuristics, and omit ambiguous layouts.

Bound explorer requests, lock waits, compiler installation, and solc
execution by lookup deadlines without replenishing the shared
identifier's
cumulative budget. Compile inline verified sources in an empty working
directory, disable import callbacks where supported, and kill timed-out
compiler processes.

Preserve contract and enum array dimensions, publish layout cache
entries
through unique temporary files, and leave transient explorer errors
unresolved. Keep unverified results memoized only for the current run.

Cover array parsing, cumulative budgets, cache behavior, compiler
timeouts,
and delegated storage decoding with regression tests.

@mablr mablr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @sakulstra,

Reviewed your PR and applied some fixes, please have a look to 38d18ee.

@mablr mablr changed the title feat: decoding external contracts feat(common): decoding external contracts Sep 10, 2026
Comment thread crates/common/src/compile.rs
Comment thread crates/common/src/external_storage.rs
/// Walks the proxy chain of every address, fetching the metadata of each link as it goes.
///
/// Returns one [`ProxyChain`] per input address, in the same order.
async fn resolve_proxy_chains(&mut self, addresses: &[Address]) -> Vec<ProxyChain> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

optional scope cleanup: could we keep the existing get_abis proxy traversal and leave this refactor out? get_metadata deliberately fetches exact addresses and never uses resolve_proxy_chains, so the new ProxyChain/Stop machinery expands the review surface without serving the storage-layout feature.

Normalize in-root parent components without allowing remappings to escape the source root. Leave expired storage-layout compilations unresolved so later lookups can retry with a fresh budget.

AI-assisted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants