Skip to main content

Module backend

Module backend 

Source
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:

  1. Backend::create_evm builds an EVM over the active context. The EVM does not borrow the backend: it reads the context’s accepted state through a shared view.
  2. While the EVM runs, the backend is free. Inspectors that implement cheatcodes hold &mut Backend (or a CowBackend) for the duration of the execution, and call its operations with the &mut Evm they receive from their hooks. Operations that act on the running transaction, such as fork selection, snapshots, vm.transact or account refreshes, take that EVM explicitly together with the ExecutionPhase; operations between executions, such as Backend::insert_account_info, do not.
  3. After a committed execution, Backend::park accepts 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 Backend used for fuzzing.
diagnostic 🔒
error 🔒
snapshot 🔒
Snapshot retention policy.

Structs§

Backend
Foundry’s executor backend.
BlockchainDb
A shareable Block database
BlockchainDbMeta
relevant identifying markers in the context of BlockchainDb
CowBackend
A clone-on-write Backend.
ForkBlock
A block number and hash that identify the exact root of a fork.
SharedBackend
A cloneable backend type that shares access to the backend data with all its clones.
TransactionForkTarget 🔒
Block data required to execute or position a fork at a transaction.
TransactionValidationError
A transaction evm2 rejected, with Foundry’s wording of the reason. The evm2 error stays available to callers that downcast the report.

Enums§

AccountFetchPolicy
Policy for loading remote account balances, nonces, and code.
BackendError
Errors of Backend operations.
DatabaseError
Errors encountered while loading fork state.
ForkAccountField
Account field changed by an out-of-band fork RPC mutation.
RevertDiagnostic
Represents possible diagnostic cases on revert
RevertStateSnapshotAction
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 into CHEATCODE_ADDRESS.

Traits§

ForkBlockEnv
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 block and its two ancestors, fetched through backend.
block_cursor 🔒
Returns network state retaining the block cursor at position, whose block’s transactions and ancestors are context.
handler_error
Returns a report for a transaction evm2 rejected or failed to execute, wrapped in an “EVM error” context.
is_contract 🔒
Returns whether account has code. A zero code hash, which no code hashes to, is not code.
parent_block 🔒
Fetches the parent of block, or None for genesis.
transaction_error
Returns a report for a transaction evm2 rejected or failed to execute.

Type Aliases§

BackendResult
DatabaseResult
Result alias with DatabaseError as error
LocalForkId
Represents a numeric ForkId valid only for the existence of the Backend.
RpcForkDb
Backing database of an RPC fork: the shared fork cache, read by evm2.