Skip to main content

Module external_storage

Module external_storage 

Source
Expand description

Storage layouts for contracts that are not part of the local project.

When a forked test touches a contract that isn’t in the local artifacts, its storage slots can still be decoded by compiling the verified source a block explorer has for it.

Finding that source is the caller’s job β€” foundry-evm-traces already knows how to ask a block explorer for it. This module owns what happens next: compiling it for a storage layout, which costs a full solc invocation, and making sure that cost is paid once. forge test runs test contracts in parallel, so lookups are:

  • deduplicated process-wide by LOOKUPS, so concurrent tests touching the same contract compile it once instead of racing each other;
  • persisted to disk once resolved, so later runs skip straight to the layout.

Unverified responses are memoized only for this run so later runs can discover newly verified contracts.

StructsΒ§

CachedStorageLayout πŸ”’
Disk representation of a resolved lookup. Cleared by forge cache clean.

ConstantsΒ§

BASE_PATH_SOLC πŸ”’
First solc release with --base-path support.
CACHE_VERSION πŸ”’
Current CachedStorageLayout format.
MIN_STORAGE_LAYOUT_SOLC πŸ”’
First solc release that emits storageLayout. Matches the floor cast storage enforces.
NO_IMPORT_CALLBACK_SOLC πŸ”’
First solc release with --no-import-callback support.

StaticsΒ§

CACHE_TEMP_ID πŸ”’
Makes cache publication paths unique within one process; the PID separates processes.
COMPILER πŸ”’
Bounds expensive compiler installation and execution across parallel tests.
LOOKUPS πŸ”’
Per-(chain, address) lookup slots, shared across the whole process.

FunctionsΒ§

cache_path πŸ”’
Path of the cache entry for address.
compile_storage_layout πŸ”’
Compiles a verified source with storageLayout output enabled and extracts the layout.
fetch_external_storage_layouts
Resolves the storage layouts of addresses on chain, compiling verified sources as needed.
lock_until
Acquires a lock without exceeding the caller’s deadline.
read_cached_layout πŸ”’
Reads the layout a previous run resolved for address, if there is one.
resolve πŸ”’
fetch_external_storage_layouts with the cache location supplied, so tests can point it somewhere other than the user’s home directory.
run_solc πŸ”’
Runs solc in an empty directory and terminates it if the remaining lookup budget expires.
write_cached_layout πŸ”’
Persists a resolved layout so later runs can skip the fetch and the compile.

Type AliasesΒ§

ExternalStorageLayout πŸ”’
A resolved storage layout, or None if the contract has no layout we can use.
LookupSlot πŸ”’
A single address’ lookup slot: None until the lookup completes, then its memoized result.