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.
Re-exportsΒ§
use crate::fs;πuse crate::namespaced_storage;πuse alloy_chains::Chain;πuse alloy_primitives::Address;πuse alloy_primitives::map::AddressMap;πuse foundry_block_explorers::contract::Metadata;πuse foundry_compilers::artifacts::CompilerOutput;πuse foundry_compilers::artifacts::SolcInput;πuse foundry_compilers::artifacts::SolcLanguage;πuse foundry_compilers::artifacts::Source;πuse foundry_compilers::artifacts::Sources;πuse foundry_compilers::artifacts::StorageLayout;πuse foundry_compilers::artifacts::output_selection::OutputSelection;πuse foundry_compilers::solc::Solc;πuse foundry_config::Config;πuse serde::Deserialize;πuse serde::Deserialize;πuse serde::Serialize;πuse serde::Serialize;πuse std::io::Read;πuse std::io::Seek;πuse std::io::SeekFrom;πuse std::path::Path;πuse std::path::PathBuf;πuse std::process::Command;πuse std::process::Stdio;πuse std::sync::Arc;πuse std::sync::LazyLock;πuse std::sync::Mutex;πuse std::sync::MutexGuard;πuse std::sync::TryLockError;πuse std::sync::atomic::AtomicU64;πuse std::sync::atomic::Ordering;πuse std::time::Duration;πuse std::time::Instant;πuse wait_timeout::ChildExt;π
StructsΒ§
- Cached
Storage πLayout - Disk representation of a resolved lookup. Cleared by
forge cache clean.
ConstantsΒ§
- BASE_
PATH_ πSOLC - First solc release with
--base-pathsupport. - CACHE_
VERSION π - Current
CachedStorageLayoutformat. - MIN_
STORAGE_ πLAYOUT_ SOLC - First solc release that emits
storageLayout. Matches the floorcast storageenforces. - NO_
IMPORT_ πCALLBACK_ SOLC - First solc release with
--no-import-callbacksupport.
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
storageLayoutoutput enabled and extracts the layout. - extend_
external_ πstorage_ layout - Appends the ERC-7201 namespaces of contract
namein sourcepathto its solc layout. - fetch_
external_ storage_ layouts - Resolves the storage layouts of
addressesonchain, 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_layoutswith 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Β§
- External
Storage πLayout - A resolved storage layout, or
Noneif the contract has no layout we can use. - Lookup
Slot π - A single addressβ lookup slot:
Noneuntil the lookup completes, then its memoized result.