Expand description
Foundry’s executor backend: RPC forks, persistent accounts, snapshots and cheatcode policy over evm2.
§Execution contract
Backend owns an ExecutionLifecycle: the accepted state of every execution context (the
local database and each fork), the active selection, persistent accounts and snapshots. It does
not implement a database trait; executions run on [evm2::Evm]s built from it:
Backend::create_evmbuilds an EVM over the active context. The EVM does not borrow the backend: it reads the context’s accepted state through a shared view.- While the EVM runs, the backend is free. Inspectors that implement cheatcodes hold
&mut Backend(or aCowBackend) for the duration of the execution, and call its operations with the&mut Evmthey receive from their hooks. Operations that act on the running transaction, such as fork selection, snapshots,vm.transactor account refreshes, take that EVM explicitly together with theExecutionPhase; operations between executions, such asBackend::insert_account_info, do not. - After a committed execution,
Backend::parkaccepts the EVM’s state, environment and network state back into the active context. Dropping the EVM instead discards everything it did, as for calls.
Backend::inspect_commit wraps these steps for executions that need no backend access from
their inspector.
Re-exports§
use crate::constants::CALLER;🔒use crate::constants::CHEATCODE_ADDRESS;🔒use crate::constants::DEFAULT_CREATE2_DEPLOYER;🔒use crate::evm::BackingDb;🔒use crate::evm::BlockContext;🔒use crate::evm::ChainFor;🔒use crate::evm::EthEvmNetwork;🔒use crate::evm::EvmEnvFor;🔒use crate::evm::EvmFactoryFor;🔒use crate::evm::ExecutedNested;🔒use crate::evm::ExecutionLifecycle;🔒use crate::evm::ExecutionPhase;🔒use crate::evm::ForkDb;🔒use crate::evm::ForkInfo;🔒use crate::evm::ForkPosition;🔒use crate::evm::FoundryDatabase;🔒use crate::evm::FoundryEvmExt;🔒use crate::evm::FoundryEvmFactory;🔒use crate::evm::FoundryEvmFor;🔒use crate::evm::FoundryEvmNetwork;🔒use crate::evm::FoundryExecutionHooks;🔒use crate::evm::FoundryTxConversion;🔒use crate::evm::PersistentWrite;🔒use crate::evm::PreparedTx;🔒use crate::evm::SpecFor;🔒use crate::evm::StoredExt;🔒use crate::evm::TransactionRequestFor;🔒use crate::evm::TxFor;🔒use crate::evm::TxResultFor;🔒use crate::evm::TypesFor;🔒use crate::evm::block_txs;🔒use crate::evm::evm_env;🔒use crate::evm::full_transactions;🔒use crate::evm::merge_untracked_nested_changes;🔒use crate::fork::BlockEnv;🔒use crate::fork::CreateFork;🔒use crate::fork::Fork as RemoteFork;🔒use crate::fork::ForkId;🔒use crate::fork::ForkResult;🔒use crate::fork::MultiFork;🔒use crate::opts::EvmOpts;🔒use crate::opts::ExecutionSpecContext;🔒use crate::utils::apply_chain_and_block_specific_env_changes_for_chain;🔒use crate::utils::apply_chain_specific_tx_replay_env_changes_for_chain;🔒use crate::utils::block_env_from_header;🔒use alloy_chains::Chain;🔒use alloy_chains::NamedChain;🔒use alloy_consensus::BlockHeader;🔒use alloy_consensus::Transaction as _;🔒use alloy_consensus::Typed2718;🔒use alloy_consensus::transaction::Recovered;🔒use alloy_eips::BlockNumHash;🔒use alloy_genesis::GenesisAccount;🔒use alloy_network::AnyNetwork;🔒use alloy_network::AnyRpcBlock;🔒use alloy_network::AnyRpcTransaction;🔒use alloy_network::TransactionResponse;🔒use alloy_primitives::Address;🔒use alloy_primitives::B256;🔒use alloy_primitives::Bytes;🔒use alloy_primitives::ChainId;🔒use alloy_primitives::KECCAK256_EMPTY;🔒use alloy_primitives::TxKind;🔒use alloy_primitives::U256;🔒use alloy_primitives::keccak256;🔒use alloy_primitives::map::AddressMap;🔒use alloy_primitives::map::AddressSet;🔒use alloy_primitives::map::HashSet;🔒use alloy_rpc_types::BlockNumberOrTag;🔒use alloy_rpc_types::BlockTransactions;🔒use evm2::EvmFeatures;🔒use evm2::Inspector;🔒use evm2::bytecode::Bytecode;🔒use evm2::evm::AccountInfo;🔒use evm2::evm::Cache;🔒use evm2::evm::DbResult;🔒use evm2::evm::DynDatabase;🔒use evm2::evm::EmptyDB;🔒use evm2::evm::InMemoryDB;🔒use evm2::evm::PendingState;🔒use evm2::evm::State;🔒use evm2::evm::StateSnapshot;🔒use evm2::evm::bal::Bal;🔒use evm2::evm::bal::BlockAccessIndex;🔒use eyre::WrapErr;🔒use foundry_common::SYSTEM_TRANSACTION_TYPE;🔒use foundry_common::is_known_system_sender;🔒use foundry_evm_networks::NetworkConfigs;🔒use std::collections::BTreeMap;🔒use std::mem;🔒use std::sync::Arc;🔒use std::time::Instant;🔒
Modules§
- bal 🔒
- Block access list (BAL) reads for executing one transaction against its parent block’s state.
- cow 🔒
- A clone-on-write wrapper around
Backendused for fuzzing. - diagnostic 🔒
- error 🔒
- snapshot 🔒
- Snapshot retention policy.
Structs§
- Backend
- Foundry’s executor backend.
- Blockchain
Db - A shareable Block database
- Blockchain
DbMeta - relevant identifying markers in the context of BlockchainDb
- CowBackend
- A clone-on-write
Backend. - Fork
Block - A block number and hash that identify the exact root of a fork.
- Shared
Backend - A cloneable backend type that shares access to the backend data with all its clones.
- Transaction
Fork 🔒Target - Block data required to execute or position a fork at a transaction.
- Transaction
Validation Error - A transaction evm2 rejected, with Foundry’s wording of the reason. The evm2 error stays available to callers that downcast the report.
Enums§
- Account
Fetch Policy - Policy for loading remote account balances, nonces, and code.
- Backend
Error - Errors of
Backendoperations. - Database
Error - Errors encountered while loading fork state.
- Fork
Account Field - Account field changed by an out-of-band fork RPC mutation.
- Revert
Diagnostic - Represents possible diagnostic cases on revert
- Revert
State Snapshot Action - What to do when reverting a state snapshot.
Constants§
- DEFAULT_
PERSISTENT_ 🔒ACCOUNTS - All accounts that will have persistent storage across fork swaps.
- GLOBAL_
FAIL_ SLOT bytes32("failed"), as a storage slot key intoCHEATCODE_ADDRESS.
Traits§
- Fork
Block Env - Marker trait for block environment types that can be used with the forking backend.
Functions§
- account_
fetch_ policy_ for_ source - Returns the account-loading policy required by a fork source.
- block_
context 🔒 - Returns the transactions of
blockand its two ancestors, fetched throughbackend. - block_
cursor 🔒 - Returns network state retaining the block cursor at
position, whose block’s transactions and ancestors arecontext. - handler_
error - Returns a report for a transaction evm2 rejected or failed to execute, wrapped in an “EVM error” context.
- is_
contract 🔒 - Returns whether
accounthas code. A zero code hash, which no code hashes to, is not code. - parent_
block 🔒 - Fetches the parent of
block, orNonefor genesis. - transaction_
error - Returns a report for a transaction evm2 rejected or failed to execute.
Type Aliases§
- Backend
Result - Database
Result - Result alias with
DatabaseErroras error - Local
Fork Id - Represents a numeric
ForkIdvalid only for the existence of theBackend. - RpcFork
Db - Backing database of an RPC fork: the shared fork cache, read by evm2.