Skip to main content

Module evm

Module evm 

Source
Expand description

Foundry’s execution stack on evm2.

FoundryEvmNetwork binds an Alloy network to a FoundryEvmFactory, which owns the network’s evm2 type family ([EvmTypesHost]): spec, transaction, block and result extensions, the transaction registry and the precompiles. One marker exists per network family: EthEvmNetwork, OpEvmNetwork, BaseEvmNetwork, MonadEvmNetwork and TempoEvmNetwork.

Transactions stay network-native until execution (see tx). ExecutionLifecycle owns the accepted state that evm2’s State does not.

crate::backend::Backend layers RPC forks and Foundry’s cheatcode policy on top of the lifecycle.

Re-exports§

use alloy_consensus::SignableTransaction; 🔒
use alloy_consensus::Signed; 🔒
use alloy_consensus::transaction::SignerRecoverable; 🔒
use alloy_eips::Typed2718; 🔒
use alloy_network::Network; 🔒
use alloy_primitives::Signature; 🔒
use alloy_rlp::Decodable; 🔒
use evm2::Evm; 🔒
use evm2::EvmTypes; 🔒
use evm2::ExecutionConfig; 🔒
use evm2::TxResult; 🔒
use evm2::Version; 🔒
use evm2::env::BlockEnv; 🔒
use evm2::evm::precompile::PrecompileProvider; 🔒
use evm2::registry::TxRegistry; 🔒
use foundry_common::FoundryReceiptResponse; 🔒
use foundry_common::FoundryTransactionBuilder; 🔒
use foundry_common::fmt::UIfmt; 🔒
use foundry_evm_hardforks::ExecutionSpec; 🔒
use foundry_evm_networks::NetworkConfigs; 🔒
use serde::Deserialize; 🔒
use serde::Deserialize; 🔒
use serde::Serialize; 🔒
use serde::Serialize; 🔒
use std::fmt::Debug; 🔒
use std::fmt::Debug; 🔒
pub use base::BaseEvmNetwork;base
pub use monad::MonadEvmNetwork;monad
pub use op::OpEvmNetwork;optimism
pub use tempo::TempoEvmNetwork;
pub use eth::*;

Modules§

basebase
Base on evm2, using base-evm2.
db 🔒
Backing databases.
env 🔒
Execution environments and network extension state.
eth
Ethereum on evm2.
fork 🔒
Fork registry: which backing databases exist, which one is active, and the accepted state each inactive one resumes with.
lifecycle 🔒
Foundry’s execution lifecycle over evm2: fork switching, snapshots and nested execution.
monadmonad
Monad on evm2, using monad-evm2.
opoptimism
OP Stack on evm2, using op-evm2.
snapshot 🔒
User-visible state snapshots.
tempo
Tempo execution integration.
tx 🔒
Network-native transactions.

Structs§

AcceptedView
A context’s accepted state layered over its backing database, shared without copying.
BlockContext
Transactions of a block and its two ancestors, for network state that depends on the block position of a transaction (see FoundryEvmExt::for_block).
DestructedAccount
The state a nested transaction left an account in before the transaction ended and destroyed it, which the running transaction keeps until it ends itself.
EvmEnv
The spec, runtime version and block an EVM is built with.
ExecutedNested
The outcome of a PreparedTx, to store with ExecutionLifecycle::store_executed.
ExecutionLifecycle
Fork, snapshot and nested-execution lifecycle for one EVM network family.
ForkCode
Converts accounts of the fork cache, which holds raw code, into evm2 accounts.
ForkDb
A remote fork’s backing database: Foundry’s RPC-backed fork cache, read by evm2.
ForkEntry
A registered fork.
ForkInfo
Identity of a fork as Foundry users see it: its RPC endpoint and pinned block.
ForkRegistry
Registered forks, the local context, the active selection and persistent accounts.
LaterWrites
The persistent writes recorded since a restoration.
LifecycleSnapshot
Everything a snapshot revert restores.
Parked
An execution context that is not running: its backing database, environment, network extension state and accepted state.
PreparedTx
A transaction prepared to execute as a nested transaction of the running one, such as for vm.transact, whose inspector may hold the lifecycle’s owner while it runs.
ReplacedState
A running state a restoration replaced.
RestoreFrame
SnapshotRestores
Running states replaced by snapshot restorations inside the open frames of a transaction.
StoredExt
Network extension state stored outside a running EVM, such as by a parked context or a snapshot.
Suspended
What a running transaction carries from a suspended context into the next one.

Enums§

ExecutionPhase
Whether a lifecycle operation runs between transactions or inside one, such as from a cheatcode.
ForkPosition
Canonical chain position of a fork’s accepted state.
PersistentWrite
A write that must survive reverts of the enclosing calls, such as a cheatcode’s state edit. It is applied as a journaled write, and the owner replays it after each enclosing call that reverts. Balance and nonce writes replay as deltas, so they compose with value transfers and nonce bumps undone by the revert, saturating at their bounds, unless their Replay mode says otherwise.
Replay
How a balance or nonce PersistentWrite replays, ordered by precedence when combined.
TxPayload
What an execution-time transaction is priced and validated as.

Constants§

FOUNDRY_POLICY_FEATURES
Features Foundry toggles independently of the fork.

Traits§

BackingDb
A shareable backing database: every fork and every nested transaction reads through its own handle to the same source.
FoundryDatabase
Database view the factory needs at construction time.
FoundryEvmExt
Per-EVM network state, such as OP L1 block info or Monad’s reserve-balance context.
FoundryEvmFactory
Builds Foundry-configured EVMs for one evm2 [EvmTypesHost] family.
FoundryEvmNetwork
Binds an Alloy network to an evm2 factory.
FoundryExecutionHooks
Execution-family hooks for state Foundry changes outside ordinary EVM execution.
FoundryTxConversion
Converts an Alloy network’s native transactions into an evm2 execution family’s transactions.
FoundryTxResultExt
Network-only transaction outcome flags.
SendableExt
Network extension state that can be copied without sharing thread-unsafe state.

Functions§

apply_account
Sets the account at address in state to info, or to no account, and writes slots to its storage after wiping it if wiped, as journaled writes, also recorded in persistent if given. Fields that already hold their value are left alone; code is only built when the code hash changes.
block_txs
Converts every transaction of a full RPC block.
carry_execution_policy
Returns next with Foundry’s execution policy carried over from current.
cold_account_warm_slots
Returns the warm slots of the persistent accounts the running transaction in state loaded but holds cold, such as the test contract after an isolated static call cooled it.
copy_account
Copies the account info and code of address from source into target, if source holds the account.
destructed_accounts
Returns the accounts the running transaction in state self-destructed, with their state before the transaction ends and destroys them, such as at the end of the root frame of a nested transaction.
eth_envelope_from_any_rpc
Returns the Ethereum envelope of a transaction fetched over RPC.
eth_tx
Converts a signed Ethereum envelope into evm2’s Ethereum transaction.
eth_tx_from_request
Converts a complete unsigned Ethereum request into a simulated evm2 transaction.
eth_unsigned_tx
Converts an unsigned Ethereum transaction into evm2’s Ethereum transaction.
evm_env
Returns the environment evm currently executes with.
existing_account
Returns account, which a database reports as an existing empty account when it does not hold it, as an execution applying EIP-161 or not loads it. Under EIP-161 an empty account does not exist, so it is loaded as absent.
fatal
fetch_parent
Fetches the parent of block, or None for genesis.
full_transactions
Returns the transactions of block, which must contain full transactions.
loaded_slots
Returns the accounts state loaded with their loaded slots.
merge_changes
Applies a nested transaction’s changes to the accounts selected by filter to state as journaled writes, also recorded in persistent if given.
merge_pending_changes
Applies the changes of a nested transaction detached into pending to the running transaction’s state as journaled writes, so they revert with the enclosing call.
merge_untracked_nested_changes
Applies a nested transaction’s changes to the running transaction’s state as journaled writes and returns them as PersistentWrites, for the caller to replay when an enclosing call reverts, such as for broadcastRawTransaction.
merge_untracked_pending_changes_with_warmth
Applies the changes of a nested transaction that child ran and detached into pending to the running transaction’s state like merge_untracked_nested_changes, and also warms the accounts and slots the nested transaction left warm, such as for executeTransaction.
placeholder_signature
Placeholder signature used to put an unsigned request into its network’s envelope.
put_transient
Writes transient storage taken with take_transient into the running transaction in state.
rebase_loaded_accounts
Replaces the accounts the running transaction in state loaded, except persistent ones, with their accepted state in source, as journaled writes: info and loaded storage slots.
release_inspector⚠
Clears evm’s inspector and returns the EVM without the borrows the inspector held, such as to park an EVM whose inspector borrowed the lifecycle’s owner.
restore_access_warmth
Undoes, without journaling, the warmth that the running transaction in state gained since checkpoint, keeping all other warmth, including unjournaled changes made since.
restore_originals
Turns the accepted values of the slots of originals in the fresh state back into pending writes of the running transaction over their transaction-start values.
take_transient
Removes and returns the transient storage of the running transaction in state, as address, key and value, sorted so writing it back is deterministic.
unknown_transaction_type
Returns the error for an RPC transaction whose envelope target cannot represent.
unloaded_changes
Returns the changes to accounts and storage slots the running transaction in state has not loaded, as a pending state to accept. Accounts that were created, self-destructed, wiped or given code are left out.
warm_accounts
Returns the accounts the running transaction in state loaded and that are warm, with their warm slots.
warm_set
Returns the warmth of the running transaction in state: its base warm set and the accounts and slots it warmed, for a transaction that continues in a replaced state.
with_eip7702_delegations 🔒
Enables EIP-7702 delegation resolution on version.

Type Aliases§

BlockEnvFor
ChainFor
EvmEnvFor
EvmFactoryFor
Convenience type aliases for accessing associated types through FoundryEvmNetwork.
ForkCursor
A fork’s canonical position and the network state retaining its block cursor.
FoundryEvmFor
InterpreterFor
Ledger
Persistent writes with the depth and journal length they were recorded at.
MessageFor
MessageResultFor
NetworkFor
SpecFor
SpecOf
TransactionRequestFor
TxEnvelopeFor
TxFor
TxResultFor
TypesFor