Evm

Trait Evm 

Source
pub trait Evm {
    type DB;
    type Tx: IntoTxEnv<Self::Tx>;
    type Error: EvmError;
    type HaltReason: HaltReasonTr + Send + Sync + 'static;
    type Spec: Debug + Copy + Hash + Eq + Send + Sync + Default + 'static;
    type BlockEnv: BlockEnvironment;
    type Precompiles;
    type Inspector;

Show 20 methods // Required methods fn block(&self) -> &Self::BlockEnv; fn chain_id(&self) -> u64; fn transact_raw( &mut self, tx: Self::Tx, ) -> Result<ResultAndState<Self::HaltReason>, Self::Error>; fn transact_system_call( &mut self, caller: Address, contract: Address, data: Bytes, ) -> Result<ResultAndState<Self::HaltReason>, Self::Error>; fn finish(self) -> (Self::DB, EvmEnv<Self::Spec, Self::BlockEnv>) where Self: Sized; fn set_inspector_enabled(&mut self, enabled: bool); fn components(&self) -> (&Self::DB, &Self::Inspector, &Self::Precompiles); fn components_mut( &mut self, ) -> (&mut Self::DB, &mut Self::Inspector, &mut Self::Precompiles); // Provided methods fn transact( &mut self, tx: impl IntoTxEnv<Self::Tx>, ) -> Result<ResultAndState<Self::HaltReason>, Self::Error> { ... } fn db(&self) -> &Self::DB { ... } fn db_mut(&mut self) -> &mut Self::DB { ... } fn transact_commit( &mut self, tx: impl IntoTxEnv<Self::Tx>, ) -> Result<ExecutionResult<Self::HaltReason>, Self::Error> where Self::DB: DatabaseCommit { ... } fn into_db(self) -> Self::DB where Self: Sized { ... } fn into_env(self) -> EvmEnv<Self::Spec, Self::BlockEnv> where Self: Sized { ... } fn enable_inspector(&mut self) { ... } fn disable_inspector(&mut self) { ... } fn precompiles(&self) -> &Self::Precompiles { ... } fn precompiles_mut(&mut self) -> &mut Self::Precompiles { ... } fn inspector(&self) -> &Self::Inspector { ... } fn inspector_mut(&mut self) -> &mut Self::Inspector { ... }
}
Expand description

An instance of an ethereum virtual machine.

An EVM is commonly initialized with the corresponding block context and state and it’s only purpose is to execute transactions.

Executing a transaction will return the outcome of the transaction.

Required Associated Types§

Source

type DB

Database type held by the EVM.

Source

type Tx: IntoTxEnv<Self::Tx>

The transaction object that the EVM will execute.

This type represents the transaction environment that the EVM operates on internally. Typically this is revm::context::TxEnv, which contains all necessary transaction data like sender, gas limits, value, and calldata.

The EVM accepts flexible transaction inputs through the IntoTxEnv trait. This means that while the EVM internally works with Self::Tx (usually TxEnv), users can pass various transaction formats to Evm::transact, including:

This design allows the EVM to accept recovered consensus transactions seamlessly.

Source

type Error: EvmError

Error type returned by EVM. Contains either errors related to invalid transactions or internal irrecoverable execution errors.

Source

type HaltReason: HaltReasonTr + Send + Sync + 'static

Halt reason. Enum over all possible reasons for halting the execution. When execution halts, it means that transaction is valid, however, it’s execution was interrupted (e.g because of running out of gas or overflowing stack).

Source

type Spec: Debug + Copy + Hash + Eq + Send + Sync + Default + 'static

Identifier of the EVM specification. EVM is expected to use this identifier to determine which features are enabled.

Source

type BlockEnv: BlockEnvironment

Block environment used by the EVM.

Source

type Precompiles

Precompiles used by the EVM.

Source

type Inspector

Evm inspector.

Required Methods§

Source

fn block(&self) -> &Self::BlockEnv

Reference to Evm::BlockEnv.

Source

fn chain_id(&self) -> u64

Returns the chain ID of the environment.

Source

fn transact_raw( &mut self, tx: Self::Tx, ) -> Result<ResultAndState<Self::HaltReason>, Self::Error>

Executes a transaction and returns the outcome.

Source

fn transact_system_call( &mut self, caller: Address, contract: Address, data: Bytes, ) -> Result<ResultAndState<Self::HaltReason>, Self::Error>

Executes a system call.

Note: this will only keep the target contract in the state. This is done because revm is loading revm::context::Block::beneficiary into state by default, and we need to avoid it by also covering edge cases when beneficiary is set to the system contract address.

Source

fn finish(self) -> (Self::DB, EvmEnv<Self::Spec, Self::BlockEnv>)
where Self: Sized,

Consumes the EVM and returns the inner EvmEnv.

Source

fn set_inspector_enabled(&mut self, enabled: bool)

Determines whether additional transactions should be inspected or not.

See also EvmFactory::create_evm_with_inspector.

Source

fn components(&self) -> (&Self::DB, &Self::Inspector, &Self::Precompiles)

Provides immutable references to the database, inspector and precompiles.

Source

fn components_mut( &mut self, ) -> (&mut Self::DB, &mut Self::Inspector, &mut Self::Precompiles)

Provides mutable references to the database, inspector and precompiles.

Provided Methods§

Source

fn transact( &mut self, tx: impl IntoTxEnv<Self::Tx>, ) -> Result<ResultAndState<Self::HaltReason>, Self::Error>

Same as Evm::transact_raw, but takes any type implementing IntoTxEnv.

This is the primary method for executing transactions. It accepts flexible input types that can be converted to the EVM’s transaction environment, including:

The conversion happens automatically through the IntoTxEnv trait.

Source

fn db(&self) -> &Self::DB

Returns an immutable reference to the underlying database.

Source

fn db_mut(&mut self) -> &mut Self::DB

Returns a mutable reference to the underlying database.

Source

fn transact_commit( &mut self, tx: impl IntoTxEnv<Self::Tx>, ) -> Result<ExecutionResult<Self::HaltReason>, Self::Error>
where Self::DB: DatabaseCommit,

Executes a transaction and commits the state changes to the underlying database.

Source

fn into_db(self) -> Self::DB
where Self: Sized,

Consumes the EVM and returns the inner database.

Source

fn into_env(self) -> EvmEnv<Self::Spec, Self::BlockEnv>
where Self: Sized,

Consumes the EVM and returns the inner EvmEnv.

Source

fn enable_inspector(&mut self)

Enables the configured inspector.

All additional transactions will be inspected if enabled.

Source

fn disable_inspector(&mut self)

Disables the configured inspector.

Transactions will no longer be inspected.

Source

fn precompiles(&self) -> &Self::Precompiles

Getter of precompiles.

Source

fn precompiles_mut(&mut self) -> &mut Self::Precompiles

Mutable getter of precompiles.

Source

fn inspector(&self) -> &Self::Inspector

Getter of inspector.

Source

fn inspector_mut(&mut self) -> &mut Self::Inspector

Mutable getter of inspector.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<L, R> Evm for Either<L, R>
where L: Evm, R: Evm<DB = L::DB, Tx = L::Tx, Error = L::Error, HaltReason = L::HaltReason, Spec = L::Spec, BlockEnv = L::BlockEnv, Precompiles = L::Precompiles, Inspector = L::Inspector>,

Source§

type DB = <L as Evm>::DB

Source§

type Tx = <L as Evm>::Tx

Source§

type Error = <L as Evm>::Error

Source§

type HaltReason = <L as Evm>::HaltReason

Source§

type Spec = <L as Evm>::Spec

Source§

type BlockEnv = <L as Evm>::BlockEnv

Source§

type Precompiles = <L as Evm>::Precompiles

Source§

type Inspector = <L as Evm>::Inspector

Source§

fn block(&self) -> &Self::BlockEnv

Source§

fn chain_id(&self) -> u64

Source§

fn transact_raw( &mut self, tx: Self::Tx, ) -> Result<ResultAndState<Self::HaltReason>, Self::Error>

Source§

fn transact( &mut self, tx: impl IntoTxEnv<Self::Tx>, ) -> Result<ResultAndState<Self::HaltReason>, Self::Error>

Source§

fn transact_system_call( &mut self, caller: Address, contract: Address, data: Bytes, ) -> Result<ResultAndState<Self::HaltReason>, Self::Error>

Source§

fn transact_commit( &mut self, tx: impl IntoTxEnv<Self::Tx>, ) -> Result<ExecutionResult<Self::HaltReason>, Self::Error>
where Self::DB: DatabaseCommit,

Source§

fn finish(self) -> (Self::DB, EvmEnv<Self::Spec, Self::BlockEnv>)
where Self: Sized,

Source§

fn into_db(self) -> Self::DB
where Self: Sized,

Source§

fn into_env(self) -> EvmEnv<Self::Spec, Self::BlockEnv>
where Self: Sized,

Source§

fn set_inspector_enabled(&mut self, enabled: bool)

Source§

fn enable_inspector(&mut self)

Source§

fn disable_inspector(&mut self)

Source§

fn components(&self) -> (&Self::DB, &Self::Inspector, &Self::Precompiles)

Source§

fn components_mut( &mut self, ) -> (&mut Self::DB, &mut Self::Inspector, &mut Self::Precompiles)

Implementors§

Source§

impl<DB, I, PRECOMPILE> Evm for EthEvm<DB, I, PRECOMPILE>
where DB: Database, I: Inspector<EthEvmContext<DB>>, PRECOMPILE: PrecompileProvider<EthEvmContext<DB>, Output = InterpreterResult>,