pub struct Trevm<Db, Insp = NoOpInspector, TrevmState = NeedsCfg>{ /* private fields */ }
Expand description
Trevm provides a type-safe interface to the EVM, using the typestate pattern.
See the crate-level documentation for more information.
Implementations§
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn inner_mut_unchecked(&mut self) -> &mut Evm<Db, Insp>
pub fn inner_mut_unchecked(&mut self) -> &mut Evm<Db, Insp>
Get a mutable reference to the current Evm
. This should be used with
caution, as modifying the EVM may lead to inconsistent Trevmstate or
invalid execution.
Sourcepub fn into_inner(self) -> Box<Evm<Db, Insp>>
pub fn into_inner(self) -> Box<Evm<Db, Insp>>
Destructure the Trevm
into its inner EVM.
Sourcepub fn into_db(self) -> Db
pub fn into_db(self) -> Db
Deconstruct the Trevm
into the backing DB, dropping all other types.
Sourcepub fn inspector_mut(&mut self) -> &mut Insp
pub fn inspector_mut(&mut self) -> &mut Insp
Get a mutable reference to the inspector.
Sourcepub fn replace_inspector(self, inspector: Insp) -> Self
pub fn replace_inspector(self, inspector: Insp) -> Self
Replace the current inspector with a new inspector of the same type.
Sourcepub fn layer_inspector<Insp2>(
self,
inspector: Insp2,
) -> Trevm<Db, Layered<Insp2, Insp>, TrevmState>
pub fn layer_inspector<Insp2>( self, inspector: Insp2, ) -> Trevm<Db, Layered<Insp2, Insp>, TrevmState>
Layer a new inspector on top of the current one.
Sourcepub fn take_inspector(self) -> (Insp, Trevm<Db, NoOpInspector, TrevmState>)
pub fn take_inspector(self) -> (Insp, Trevm<Db, NoOpInspector, TrevmState>)
Take the inspector out of the Trevm, replacing it with a
NoOpInspector
.
Sourcepub fn set_inspector<Insp2>(
self,
inspector: Insp2,
) -> Trevm<Db, Insp2, TrevmState>
pub fn set_inspector<Insp2>( self, inspector: Insp2, ) -> Trevm<Db, Insp2, TrevmState>
Replace the current inspector with a new one, dropping the old one.
Sourcepub fn with_inspector<Insp2, F, NewState>(
self,
inspector: Insp2,
f: F,
) -> Trevm<Db, Insp, NewState>
pub fn with_inspector<Insp2, F, NewState>( self, inspector: Insp2, f: F, ) -> Trevm<Db, Insp, NewState>
Run the closure with a different inspector, then restore the previous one.
Sourcepub fn try_with_inspector<F, Insp2, NewState, E>(
self,
inspector: Insp2,
f: F,
) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>
pub fn try_with_inspector<F, Insp2, NewState, E>( self, inspector: Insp2, f: F, ) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>
Run a fallible function with the provided inspector, then restore the
previous inspector. If the function returns an error, it will be
wrapped in an EvmErrored
along with the current EVM state.
Sourcepub fn set_spec_id(&mut self, spec_id: SpecId)
pub fn set_spec_id(&mut self, spec_id: SpecId)
Set the SpecId, modifying the EVM handlers accordingly. This function should be called at hardfork boundaries when running multi-block trevm flows.
Sourcepub fn with_spec_id<F, NewState>(
self,
spec_id: SpecId,
f: F,
) -> Trevm<Db, Insp, NewState>
pub fn with_spec_id<F, NewState>( self, spec_id: SpecId, f: F, ) -> Trevm<Db, Insp, NewState>
Run a closure with a different SpecId, then restore the previous setting.
Sourcepub fn errored<E>(self, error: E) -> EvmErrored<Db, Insp, E>
pub fn errored<E>(self, error: E) -> EvmErrored<Db, Insp, E>
Convert self into EvmErrored
by supplying an error
Sourcepub fn apply_state_overrides(
self,
overrides: &StateOverride,
) -> Result<Self, EVMError<<Db as Database>::Error>>where
Db: DatabaseCommit,
pub fn apply_state_overrides(
self,
overrides: &StateOverride,
) -> Result<Self, EVMError<<Db as Database>::Error>>where
Db: DatabaseCommit,
Apply StateOverride
s to the current state. Errors if the overrides
contain invalid bytecode.
Sourcepub fn maybe_apply_state_overrides(
self,
overrides: Option<&StateOverride>,
) -> Result<Self, EVMError<<Db as Database>::Error>>where
Db: DatabaseCommit,
pub fn maybe_apply_state_overrides(
self,
overrides: Option<&StateOverride>,
) -> Result<Self, EVMError<<Db as Database>::Error>>where
Db: DatabaseCommit,
Apply StateOverride
s to the current state, if they are provided.
Sourcepub fn override_opcode(
&mut self,
opcode: u8,
handler: Instruction<Db>,
) -> Instruction<Db>
pub fn override_opcode( &mut self, opcode: u8, handler: Instruction<Db>, ) -> Instruction<Db>
Overide an opcode with a custom handler. Returns the previous instruction handler for the opcode.
Sourcepub fn disable_opcode(&mut self, opcode: u8) -> Instruction<Db>
pub fn disable_opcode(&mut self, opcode: u8) -> Instruction<Db>
Disable an opcode by replacing it with unknown opcode behavior. This is
a shortcut for Self::override_opcode
with crate::helpers::forbidden
.
Sourcepub fn with_opcode_override<F, NewState>(
self,
opcode: u8,
handler: Instruction<Db>,
f: F,
) -> Trevm<Db, Insp, NewState>
pub fn with_opcode_override<F, NewState>( self, opcode: u8, handler: Instruction<Db>, f: F, ) -> Trevm<Db, Insp, NewState>
Run some closure with an opcode override, then restore the previous setting.
Sourcepub fn disable_prevrandao(&mut self) -> Instruction<Db>
pub fn disable_prevrandao(&mut self) -> Instruction<Db>
Disable the prevrandao opcode, by replacing it with unknown opcode behavior. This is useful for block simulation, where the prevrandao opcode may produce incorrect results.
Sourcepub fn enable_prevrandao(&mut self) -> Instruction<Db>
pub fn enable_prevrandao(&mut self) -> Instruction<Db>
Enable the prevrandao opcode. If the prevrandao opcode was not previously disabled or replaced, this will have no effect on behavior.
Sourcepub fn without_prevrandao<F, NewState>(self, f: F) -> Trevm<Db, Insp, NewState>
pub fn without_prevrandao<F, NewState>(self, f: F) -> Trevm<Db, Insp, NewState>
Run some code with the prevrandao opcode disabled, then restore the previous setting. This is useful for block simulation, where the prevrandao opcode may produce incorrect results.
Sourcepub fn override_precompiles(
&mut self,
precompiles: EthPrecompiles,
) -> EthPrecompiles
pub fn override_precompiles( &mut self, precompiles: EthPrecompiles, ) -> EthPrecompiles
Set the precompiles for the EVM. This will replace the current precompiles with the provided ones.
Sourcepub fn with_precompiles<F, NewState>(
self,
precompiles: EthPrecompiles,
f: F,
) -> Trevm<Db, Insp, NewState>
pub fn with_precompiles<F, NewState>( self, precompiles: EthPrecompiles, f: F, ) -> Trevm<Db, Insp, NewState>
Run a closure with a different set of precompiles, then restore the previous setting.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn try_read_account(
&mut self,
address: Address,
) -> Result<Option<AccountInfo>, <Db as Database>::Error>
pub fn try_read_account( &mut self, address: Address, ) -> Result<Option<AccountInfo>, <Db as Database>::Error>
Get the current account info for a specific address.
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn try_read_nonce(
&mut self,
address: Address,
) -> Result<u64, <Db as Database>::Error>
pub fn try_read_nonce( &mut self, address: Address, ) -> Result<u64, <Db as Database>::Error>
Get the current nonce for a specific address
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn try_read_balance(
&mut self,
address: Address,
) -> Result<U256, <Db as Database>::Error>
pub fn try_read_balance( &mut self, address: Address, ) -> Result<U256, <Db as Database>::Error>
Get the current nonce for a specific address
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn try_read_storage(
&mut self,
address: Address,
slot: U256,
) -> Result<U256, <Db as Database>::Error>
pub fn try_read_storage( &mut self, address: Address, slot: U256, ) -> Result<U256, <Db as Database>::Error>
Get the value of a storage slot.
Note: due to revm’s DB model, this requires a mutable pointer.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn try_read_account_ref(
&self,
address: Address,
) -> Result<Option<AccountInfo>, <Db as DatabaseRef>::Error>
pub fn try_read_account_ref( &self, address: Address, ) -> Result<Option<AccountInfo>, <Db as DatabaseRef>::Error>
Get the current account info for a specific address.
Sourcepub fn try_read_nonce_ref(
&self,
address: Address,
) -> Result<u64, <Db as DatabaseRef>::Error>
pub fn try_read_nonce_ref( &self, address: Address, ) -> Result<u64, <Db as DatabaseRef>::Error>
Get the current nonce for a specific address
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn try_read_balance_ref(
&self,
address: Address,
) -> Result<U256, <Db as DatabaseRef>::Error>
pub fn try_read_balance_ref( &self, address: Address, ) -> Result<U256, <Db as DatabaseRef>::Error>
Get the current nonce for a specific address
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn try_read_storage_ref(
&self,
address: Address,
slot: U256,
) -> Result<U256, <Db as DatabaseRef>::Error>
pub fn try_read_storage_ref( &self, address: Address, slot: U256, ) -> Result<U256, <Db as DatabaseRef>::Error>
Get the value of a storage slot.
Sourcepub fn try_read_code_ref(
&self,
address: Address,
) -> Result<Option<Bytecode>, <Db as DatabaseRef>::Error>
pub fn try_read_code_ref( &self, address: Address, ) -> Result<Option<Bytecode>, <Db as DatabaseRef>::Error>
Get the code at the given account, if any.
Sourcepub fn try_gas_allowance_ref(
&self,
caller: Address,
gas_price: U256,
) -> Result<u64, <Db as DatabaseRef>::Error>
pub fn try_gas_allowance_ref( &self, caller: Address, gas_price: U256, ) -> Result<u64, <Db as DatabaseRef>::Error>
Get the gas allowance for a specific caller and gas price.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn read_account(&mut self, address: Address) -> Option<AccountInfo>
pub fn read_account(&mut self, address: Address) -> Option<AccountInfo>
Get the current account info for a specific address.
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn read_nonce(&mut self, address: Address) -> u64
pub fn read_nonce(&mut self, address: Address) -> u64
Get the current nonce for a specific address
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn read_balance(&mut self, address: Address) -> U256
pub fn read_balance(&mut self, address: Address) -> U256
Get the current nonce for a specific address
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn read_storage(&mut self, address: Address, slot: U256) -> U256
pub fn read_storage(&mut self, address: Address, slot: U256) -> U256
Get the value of a storage slot.
Note: due to revm’s DB model, this requires a mutable pointer.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn read_account_ref(&self, address: Address) -> Option<AccountInfo>
pub fn read_account_ref(&self, address: Address) -> Option<AccountInfo>
Get the current account info for a specific address.
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn read_nonce_ref(&self, address: Address) -> u64
pub fn read_nonce_ref(&self, address: Address) -> u64
Get the current nonce for a specific address
Sourcepub fn read_balance_ref(&self, address: Address) -> U256
pub fn read_balance_ref(&self, address: Address) -> U256
Get the current nonce for a specific address
Sourcepub fn read_storage_ref(&self, address: Address, slot: U256) -> U256
pub fn read_storage_ref(&self, address: Address, slot: U256) -> U256
Get the value of a storage slot.
Note: due to revm’s DB model, this requires a mutable pointer.
Sourcepub fn read_code_ref(&self, address: Address) -> Option<Bytecode>
pub fn read_code_ref(&self, address: Address) -> Option<Bytecode>
Get the code at the given account, if any.
Note: due to revm’s DB model, this requires a mutable pointer.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn commit_unchecked(&mut self, state: EvmState)where
Db: DatabaseCommit,
pub fn commit_unchecked(&mut self, state: EvmState)where
Db: DatabaseCommit,
Commit a set of state changes to the database. This is a low-level API, and is not intended for general use. Regular users should prefer executing a transaction.
Sourcepub fn try_modify_account_unchecked<F: FnOnce(&mut AccountInfo)>(
&mut self,
address: Address,
f: F,
) -> Result<AccountInfo, <Db as Database>::Error>where
Db: DatabaseCommit,
pub fn try_modify_account_unchecked<F: FnOnce(&mut AccountInfo)>(
&mut self,
address: Address,
f: F,
) -> Result<AccountInfo, <Db as Database>::Error>where
Db: DatabaseCommit,
Modify an account with a closure and commit the modified account. This is a low-level API, and is not intended for general use.
Sourcepub fn try_set_nonce_unchecked(
&mut self,
address: Address,
nonce: u64,
) -> Result<u64, <Db as Database>::Error>where
Db: DatabaseCommit,
pub fn try_set_nonce_unchecked(
&mut self,
address: Address,
nonce: u64,
) -> Result<u64, <Db as Database>::Error>where
Db: DatabaseCommit,
Set the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.
Sourcepub fn try_increment_nonce_unchecked(
&mut self,
address: Address,
) -> Result<u64, <Db as Database>::Error>where
Db: DatabaseCommit,
pub fn try_increment_nonce_unchecked(
&mut self,
address: Address,
) -> Result<u64, <Db as Database>::Error>where
Db: DatabaseCommit,
Increment the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.
If the nonce is already at the maximum value, it will not be incremented.
Sourcepub fn try_decrement_nonce_unchecked(
&mut self,
address: Address,
) -> Result<u64, <Db as Database>::Error>where
Db: DatabaseCommit,
pub fn try_decrement_nonce_unchecked(
&mut self,
address: Address,
) -> Result<u64, <Db as Database>::Error>where
Db: DatabaseCommit,
Decrement the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.
If the nonce is already 0, it will not be decremented.
Sourcepub fn try_set_storage_unchecked(
&mut self,
address: Address,
slot: U256,
value: U256,
) -> Result<U256, <Db as Database>::Error>where
Db: DatabaseCommit,
pub fn try_set_storage_unchecked(
&mut self,
address: Address,
slot: U256,
value: U256,
) -> Result<U256, <Db as Database>::Error>where
Db: DatabaseCommit,
Set the EVM storage at a slot. This is a low-level API, and is not intended for general use.
Sourcepub fn try_set_bytecode_unchecked(
&mut self,
address: Address,
bytecode: Bytecode,
) -> Result<Option<Bytecode>, <Db as Database>::Error>where
Db: DatabaseCommit,
pub fn try_set_bytecode_unchecked(
&mut self,
address: Address,
bytecode: Bytecode,
) -> Result<Option<Bytecode>, <Db as Database>::Error>where
Db: DatabaseCommit,
Set the bytecode at a specific address, returning the previous bytecode at that address. This is a low-level API, and is not intended for general use.
Sourcepub fn try_increase_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> Result<U256, <Db as Database>::Error>where
Db: DatabaseCommit,
pub fn try_increase_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> Result<U256, <Db as Database>::Error>where
Db: DatabaseCommit,
Increase the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.
If this would cause an overflow, the balance will be increased to the maximum value.
Sourcepub fn try_decrease_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> Result<U256, <Db as Database>::Error>where
Db: DatabaseCommit,
pub fn try_decrease_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> Result<U256, <Db as Database>::Error>where
Db: DatabaseCommit,
Decrease the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.
If this would cause an underflow, the balance will be decreased to 0.
Sourcepub fn try_set_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> Result<U256, <Db as Database>::Error>where
Db: DatabaseCommit,
pub fn try_set_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> Result<U256, <Db as Database>::Error>where
Db: DatabaseCommit,
Set the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn modify_account_unchecked(
&mut self,
address: Address,
f: impl FnOnce(&mut AccountInfo),
) -> AccountInfowhere
Db: DatabaseCommit,
pub fn modify_account_unchecked(
&mut self,
address: Address,
f: impl FnOnce(&mut AccountInfo),
) -> AccountInfowhere
Db: DatabaseCommit,
Modify an account with a closure and commit the modified account. This is a low-level API, and is not intended for general use.
Sourcepub fn set_nonce_unchecked(&mut self, address: Address, nonce: u64) -> u64where
Db: DatabaseCommit,
pub fn set_nonce_unchecked(&mut self, address: Address, nonce: u64) -> u64where
Db: DatabaseCommit,
Set the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.
Sourcepub fn increment_nonce_unchecked(&mut self, address: Address) -> u64where
Db: DatabaseCommit,
pub fn increment_nonce_unchecked(&mut self, address: Address) -> u64where
Db: DatabaseCommit,
Increment the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.
If this would cause the nonce to overflow, the nonce will be set to the maximum value.
Sourcepub fn decrement_nonce_unchecked(&mut self, address: Address) -> u64where
Db: DatabaseCommit,
pub fn decrement_nonce_unchecked(&mut self, address: Address) -> u64where
Db: DatabaseCommit,
Decrement the nonce of an account, returning the previous nonce. This is a low-level API, and is not intended for general use.
If this would cause the nonce to underflow, the nonce will be set to 0.
Sourcepub fn set_storage_unchecked(
&mut self,
address: Address,
slot: U256,
value: U256,
) -> U256where
Db: DatabaseCommit,
pub fn set_storage_unchecked(
&mut self,
address: Address,
slot: U256,
value: U256,
) -> U256where
Db: DatabaseCommit,
Set the EVM storage at a slot. This is a low-level API, and is not intended for general use.
Sourcepub fn set_bytecode_unchecked(
&mut self,
address: Address,
bytecode: Bytecode,
) -> Option<Bytecode>where
Db: DatabaseCommit,
pub fn set_bytecode_unchecked(
&mut self,
address: Address,
bytecode: Bytecode,
) -> Option<Bytecode>where
Db: DatabaseCommit,
Set the bytecode at a specific address, returning the previous bytecode at that address. This is a low-level API, and is not intended for general use.
Sourcepub fn increase_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> U256where
Db: DatabaseCommit,
pub fn increase_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> U256where
Db: DatabaseCommit,
Increase the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.
Sourcepub fn decrease_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> U256where
Db: DatabaseCommit,
pub fn decrease_balance_unchecked(
&mut self,
address: Address,
amount: U256,
) -> U256where
Db: DatabaseCommit,
Decrease the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.
Sourcepub fn set_balance_unchecked(&mut self, address: Address, amount: U256) -> U256where
Db: DatabaseCommit,
pub fn set_balance_unchecked(&mut self, address: Address, amount: U256) -> U256where
Db: DatabaseCommit,
Set the balance of an account. Returns the previous balance. This is a low-level API, and is not intended for general use.
Source§impl<Db, Outer, Inner, TrevmState> Trevm<Db, Layered<Outer, Inner>, TrevmState>
impl<Db, Outer, Inner, TrevmState> Trevm<Db, Layered<Outer, Inner>, TrevmState>
Sourcepub fn take_outer(self) -> (Outer, Trevm<Db, Inner, TrevmState>)
pub fn take_outer(self) -> (Outer, Trevm<Db, Inner, TrevmState>)
Remove the outer-layer inspector, leaving the inner-layer inspector in place.
Sourcepub fn remove_outer(self) -> Trevm<Db, Inner, TrevmState>
pub fn remove_outer(self) -> Trevm<Db, Inner, TrevmState>
Remove the outer-layer inspector, leaving the inner-layer inspector in place.
Sourcepub fn take_inner(self) -> (Inner, Trevm<Db, Outer, TrevmState>)
pub fn take_inner(self) -> (Inner, Trevm<Db, Outer, TrevmState>)
Remove the inner-layer inspector, leaving the outer-layer inspector in place.
Sourcepub fn remove_inner(self) -> Trevm<Db, Outer, TrevmState>
pub fn remove_inner(self) -> Trevm<Db, Outer, TrevmState>
Remove the inner-layer inspector, leaving the outer-layer inspector in place.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn set_state_clear_flag(&mut self, flag: bool)
pub fn set_state_clear_flag(&mut self, flag: bool)
Set the [EIP-161] state clear flag, activated in the Spurious Dragon hardfork.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn try_set_state_clear_flag(
&mut self,
flag: bool,
) -> Result<(), <Db as TryStateAcc>::Error>
pub fn try_set_state_clear_flag( &mut self, flag: bool, ) -> Result<(), <Db as TryStateAcc>::Error>
Fallibly set the [EIP-161] state clear flag, activated in the Spurious
Dragon hardfork. This function is intended to be used by shared states,
where mutable access may fail, e.g. an Arc<Db>
.
Prefer Self::set_state_clear_flag
when available.
Source§impl<Db, Insp, E> Trevm<Db, Insp, ErroredState<E>>
impl<Db, Insp, E> Trevm<Db, Insp, ErroredState<E>>
Sourcepub fn inspect_err<F, T>(&self, f: F) -> T
pub fn inspect_err<F, T>(&self, f: F) -> T
Inspect the error with a closure.
Sourcepub fn discard_error(self) -> EvmNeedsTx<Db, Insp>
pub fn discard_error(self) -> EvmNeedsTx<Db, Insp>
Discard the error and return the EVM.
Sourcepub fn into_error(self) -> E
pub fn into_error(self) -> E
Convert the error into an EVMError
.
Sourcepub fn take_err(self) -> (E, EvmNeedsTx<Db, Insp>)
pub fn take_err(self) -> (E, EvmNeedsTx<Db, Insp>)
Reset the EVM, returning the error and the EVM ready for the next transaction.
Sourcepub fn err_into<NewErr: From<E>>(self) -> EvmErrored<Db, Insp, NewErr>
pub fn err_into<NewErr: From<E>>(self) -> EvmErrored<Db, Insp, NewErr>
Transform the error into a new error type.
Sourcepub fn map_err<F, NewErr>(self, f: F) -> EvmErrored<Db, Insp, NewErr>where
F: FnOnce(E) -> NewErr,
pub fn map_err<F, NewErr>(self, f: F) -> EvmErrored<Db, Insp, NewErr>where
F: FnOnce(E) -> NewErr,
Map the error to a new error type.
Source§impl<Db, Insp> Trevm<Db, Insp, ErroredState<EVMError<<Db as Database>::Error>>>
impl<Db, Insp> Trevm<Db, Insp, ErroredState<EVMError<<Db as Database>::Error>>>
Sourcepub const fn is_transaction_error(&self) -> bool
pub const fn is_transaction_error(&self) -> bool
Check if the error is a transaction error. This is provided as a convenience function for common cases, as Transaction errors should usually be discarded.
Sourcepub const fn as_transaction_error(&self) -> Option<&InvalidTransaction>
pub const fn as_transaction_error(&self) -> Option<&InvalidTransaction>
Fallible cast to a InvalidTransaction
.
Sourcepub fn discard_transaction_error(self) -> Result<EvmNeedsTx<Db, Insp>, Self>
pub fn discard_transaction_error(self) -> Result<EvmNeedsTx<Db, Insp>, Self>
Discard the error if it is a transaction error, returning the EVM. If the error is not a transaction error, return self
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn block_gas_limit(&self) -> u64
pub fn block_gas_limit(&self) -> u64
Get the current block gas limit.
Sourcepub fn block_number(&self) -> U256
pub fn block_number(&self) -> U256
Get the current block number.
Sourcepub fn block_timestamp(&self) -> U256
pub fn block_timestamp(&self) -> U256
Get the current block timestamp.
Sourcepub fn beneficiary(&self) -> Address
pub fn beneficiary(&self) -> Address
Get the block beneficiary address.
Sourcepub fn with_block<B, F, NewState>(
self,
b: &B,
f: F,
) -> Trevm<Db, Insp, NewState>
pub fn with_block<B, F, NewState>( self, b: &B, f: F, ) -> Trevm<Db, Insp, NewState>
Run a function with the provided block, then restore the previous block.
Sourcepub fn try_with_block<B, F, NewState, E>(
self,
b: &B,
f: F,
) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>where
F: FnOnce(Self) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>,
B: Block,
NewState: HasBlock,
pub fn try_with_block<B, F, NewState, E>(
self,
b: &B,
f: F,
) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>where
F: FnOnce(Self) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>,
B: Block,
NewState: HasBlock,
Run a fallible function with the provided block, then restore the previous block.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn set_code_size_limit(&mut self, limit: usize) -> Option<usize>
pub fn set_code_size_limit(&mut self, limit: usize) -> Option<usize>
Set the [EIP-170] contract code size limit. By default this is set to
0x6000 bytes (~25KiB). Contracts whose bytecode is larger than this
limit cannot be deployed and will produce a CreateInitCodeSizeLimit
error.
Sourcepub fn disable_code_size_limit(&mut self) -> Option<usize>
pub fn disable_code_size_limit(&mut self) -> Option<usize>
Disable the [EIP-170] contract code size limit, returning the previous setting.
Sourcepub fn without_code_size_limit<F, NewState: HasCfg>(
self,
f: F,
) -> Trevm<Db, Insp, NewState>
pub fn without_code_size_limit<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
Run a closure with the code size limit disabled, then restore the previous setting.
Sourcepub fn set_default_code_size_limit(&mut self) -> Option<usize>
pub fn set_default_code_size_limit(&mut self) -> Option<usize>
Set the [EIP-170] contract code size limit to the default value of
0x6000 bytes (~25KiB), returning the previous setting. Contracts whose
bytecode is larger than this limit cannot be deployed and will produce
a CreateInitCodeSizeLimit
error.
Sourcepub fn disable_chain_id_check(&mut self)
pub fn disable_chain_id_check(&mut self)
Disable the [EIP-155] chain ID check.
Sourcepub fn enable_chain_id_check(&mut self)
pub fn enable_chain_id_check(&mut self)
Enable the [EIP-155] chain ID check.
Sourcepub fn without_chain_id_check<F, NewState: HasCfg>(
self,
f: F,
) -> Trevm<Db, Insp, NewState>
pub fn without_chain_id_check<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
Run a closure with the chain ID check disabled, then restore the previous setting.
Sourcepub fn with_cfg<C, F, NewState>(
self,
cfg: &C,
f: F,
) -> Trevm<Db, Insp, NewState>
pub fn with_cfg<C, F, NewState>( self, cfg: &C, f: F, ) -> Trevm<Db, Insp, NewState>
Run a function with the provided configuration, then restore the previous configuration. This will not affect the block and tx, if those have been filled.
Sourcepub fn try_with_cfg<C, F, NewState, E>(
self,
cfg: &C,
f: F,
) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>where
C: Cfg,
F: FnOnce(Self) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>,
NewState: HasCfg,
pub fn try_with_cfg<C, F, NewState, E>(
self,
cfg: &C,
f: F,
) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>where
C: Cfg,
F: FnOnce(Self) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>,
NewState: HasCfg,
Run a fallible function with the provided configuration, then restore the previous configuration. This will not affect the block and tx, if those have been filled.
Sourcepub fn disable_eip3607(&mut self)
Available on crate feature optional_eip3607
only.
pub fn disable_eip3607(&mut self)
optional_eip3607
only.Disable EIP-3607. This allows transactions to originate from accounts that contain code. This is useful for simulating smart-contract calls.
Sourcepub fn enable_eip3607(&mut self)
Available on crate feature optional_eip3607
only.
pub fn enable_eip3607(&mut self)
optional_eip3607
only.Enable EIP-3607. See Self::disable_eip3607
.
Sourcepub fn without_eip3607<F, NewState: HasCfg>(
self,
f: F,
) -> Trevm<Db, Insp, NewState>
Available on crate feature optional_eip3607
only.
pub fn without_eip3607<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
optional_eip3607
only.Run a closure with [EIP-3607] disabled, then restore the previous setting.
Sourcepub fn disable_base_fee(&mut self)
Available on crate feature optional_no_base_fee
only.
pub fn disable_base_fee(&mut self)
optional_no_base_fee
only.Disables EIP-1559 base fee checks. This is useful for testing method calls with zero gas price.
Sourcepub fn enable_base_fee(&mut self)
Available on crate feature optional_no_base_fee
only.
pub fn enable_base_fee(&mut self)
optional_no_base_fee
only.Enable EIP-1559 base fee checks. See Self::disable_base_fee
.
Sourcepub fn without_base_fee<F, NewState: HasCfg>(
self,
f: F,
) -> Trevm<Db, Insp, NewState>
Available on crate feature optional_no_base_fee
only.
pub fn without_base_fee<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
optional_no_base_fee
only.Run a closure with EIP-1559 base fee checks disabled, then restore the previous setting.
Sourcepub fn disable_nonce_check(&mut self)
pub fn disable_nonce_check(&mut self)
Disable nonce checks. This allows transactions to be sent with incorrect nonces, and is useful for things like system transactions.
Sourcepub fn enable_nonce_check(&mut self)
pub fn enable_nonce_check(&mut self)
Enable nonce checks. See Self::disable_nonce_check
.
Sourcepub fn without_nonce_check<F, NewState: HasCfg>(
self,
f: F,
) -> Trevm<Db, Insp, NewState>
pub fn without_nonce_check<F, NewState: HasCfg>( self, f: F, ) -> Trevm<Db, Insp, NewState>
Run a closure with nonce checks disabled, then restore the previous setting. This will not affect the block and tx, if those have been filled.
Source§impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Trevm<Db, Insp, TrevmState>
Sourcepub fn is_transfer(&self) -> bool
pub fn is_transfer(&self) -> bool
True if the transaction is a simple transfer.
Sourcepub fn input(&self) -> &Bytes
pub fn input(&self) -> &Bytes
Get a reference to the transaction input data, which will be used as calldata or initcode during EVM execution.
Sourcepub fn caller_account(
&mut self,
) -> Result<AccountInfo, EVMError<<Db as Database>::Error>>
pub fn caller_account( &mut self, ) -> Result<AccountInfo, EVMError<<Db as Database>::Error>>
Get the account of the caller. Error if the DB errors.
Sourcepub fn callee(&self) -> Option<Address>
pub fn callee(&self) -> Option<Address>
Get the address of the callee. None
if Self::is_create
is true.
Sourcepub fn callee_account(
&mut self,
) -> Result<Option<AccountInfo>, EVMError<<Db as Database>::Error>>
pub fn callee_account( &mut self, ) -> Result<Option<AccountInfo>, EVMError<<Db as Database>::Error>>
Get the account of the callee.
Returns as follows:
- if
Self::is_create
is true,Ok(None)
- if the callee account does not exist,
Ok(AccountInfo::default())
- if the DB errors,
Err(EVMError::Database(err))
Sourcepub fn callee_account_ref(
&self,
) -> Result<Option<AccountInfo>, <Db as DatabaseRef>::Error>where
Db: DatabaseRef,
pub fn callee_account_ref(
&self,
) -> Result<Option<AccountInfo>, <Db as DatabaseRef>::Error>where
Db: DatabaseRef,
Get the account of the callee. None
if Self::is_create
is true,
error if the DB errors.
Sourcepub fn with_tx<T, F, NewState>(self, t: &T, f: F) -> Trevm<Db, Insp, NewState>
pub fn with_tx<T, F, NewState>(self, t: &T, f: F) -> Trevm<Db, Insp, NewState>
Run a function with the provided transaction, then restore the previous transaction.
Sourcepub fn try_with_tx<T, F, NewState, E>(
self,
t: &T,
f: F,
) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>where
T: Tx,
F: FnOnce(Self) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>,
NewState: HasTx,
pub fn try_with_tx<T, F, NewState, E>(
self,
t: &T,
f: F,
) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>where
T: Tx,
F: FnOnce(Self) -> Result<Trevm<Db, Insp, NewState>, EvmErrored<Db, Insp, E>>,
NewState: HasTx,
Run a fallible function with the provided transaction, then restore the previous transaction.
Sourcepub fn caller_gas_allowance(
&mut self,
) -> Result<u64, EVMError<<Db as Database>::Error>>
pub fn caller_gas_allowance( &mut self, ) -> Result<u64, EVMError<<Db as Database>::Error>>
Return the maximum gas that the caller can purchase. This is the balance of the caller divided by the gas price.
Sourcepub fn cap_tx_gas_to_allowance(
&mut self,
) -> Result<u64, EVMError<<Db as Database>::Error>>
pub fn cap_tx_gas_to_allowance( &mut self, ) -> Result<u64, EVMError<<Db as Database>::Error>>
This function caps the gas limit of the transaction to the allowance of the caller.
This is useful for e.g. call simulation, where the exact amount of gas used is less important than ensuring that the call succeeds and returns a meaningful result.
§Returns
The gas limit after the operation.
Sourcepub fn cap_tx_gas_to_block_limit(&mut self) -> u64
pub fn cap_tx_gas_to_block_limit(&mut self) -> u64
Cap the gas limit of the transaction to the minimum of the block gas limit and the transaction’s gas limit.
This is useful for ensuring that the transaction does not exceed the block gas limit, e.g. during call simulation.
§Returns
The gas limit after the operation.
Sourcepub fn cap_tx_gas(&mut self) -> Result<u64, EVMError<<Db as Database>::Error>>
pub fn cap_tx_gas(&mut self) -> Result<u64, EVMError<<Db as Database>::Error>>
This function caps the gas limit of the transaction to the minimum of the block limit and the caller’s gas allowance.
This is equivalent to calling Self::cap_tx_gas_to_block_limit
and
Self::cap_tx_gas_to_allowance
in sequence.
§Returns
The gas limit after the operation.
Source§impl<Db, Insp> Trevm<Db, Insp, NeedsBlock>
impl<Db, Insp> Trevm<Db, Insp, NeedsBlock>
Sourcepub fn drive_block<D>(self, driver: &mut D) -> DriveBlockResult<D, Db, Insp>where
D: BlockDriver<Db, Insp>,
Db: DatabaseCommit,
pub fn drive_block<D>(self, driver: &mut D) -> DriveBlockResult<D, Db, Insp>where
D: BlockDriver<Db, Insp>,
Db: DatabaseCommit,
Open a block, apply some logic, and return the EVM ready for the next block.
Sourcepub fn drive_chain<D>(self, driver: &mut D) -> DriveChainResult<D, Db, Insp>where
D: ChainDriver<Db, Insp>,
Db: DatabaseCommit,
pub fn drive_chain<D>(self, driver: &mut D) -> DriveChainResult<D, Db, Insp>where
D: ChainDriver<Db, Insp>,
Db: DatabaseCommit,
Sourcepub fn fill_block<B: Block>(self, filler: &B) -> EvmNeedsTx<Db, Insp>
pub fn fill_block<B: Block>(self, filler: &B) -> EvmNeedsTx<Db, Insp>
Fill a block and return the EVM ready for a transaction.
This does not perform any pre- or post-block logic. To manage block
lifecycles, use Self::drive_block
or Self::drive_chain
instead.
Source§impl<Db, Insp> Trevm<Db, Insp, NeedsBlock>
impl<Db, Insp> Trevm<Db, Insp, NeedsBlock>
Sourcepub fn finish(self) -> BundleState
pub fn finish(self) -> BundleState
Finish execution and return the outputs.
If the State has not been built with
revm::database::StateBuilder::with_bundle_update then the returned
BundleState
will be meaningless.
Source§impl<Db, Insp> Trevm<Db, Insp, NeedsBlock>
impl<Db, Insp> Trevm<Db, Insp, NeedsBlock>
Sourcepub fn try_finish(
self,
) -> Result<BundleState, EvmErrored<Db, Insp, <Db as TryStateAcc>::Error>>
pub fn try_finish( self, ) -> Result<BundleState, EvmErrored<Db, Insp, <Db as TryStateAcc>::Error>>
Fallibly finish execution and return the outputs. This function is
intended to be used by shared states, where mutable access may fail, e.
g. an Arc<Db>
. Prefer Self::finish
when available.
If the State has not been built with
revm::database::StateBuilder::with_bundle_update then the returned
BundleState
will be meaningless.
Source§impl<Db, Insp> Trevm<Db, Insp>
impl<Db, Insp> Trevm<Db, Insp>
Sourcepub fn fill_cfg<T: Cfg>(self, filler: &T) -> EvmNeedsBlock<Db, Insp>
pub fn fill_cfg<T: Cfg>(self, filler: &T) -> EvmNeedsBlock<Db, Insp>
Fill the configuration environment.
Source§impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
Sourcepub fn close_block(self) -> EvmNeedsBlock<Db, Insp>
pub fn close_block(self) -> EvmNeedsBlock<Db, Insp>
Close the current block, returning the EVM ready for the next block.
Sourcepub fn drive_bundle<D>(self, driver: &mut D) -> DriveBundleResult<D, Db, Insp>where
D: BundleDriver<Db, Insp>,
Db: DatabaseCommit,
pub fn drive_bundle<D>(self, driver: &mut D) -> DriveBundleResult<D, Db, Insp>where
D: BundleDriver<Db, Insp>,
Db: DatabaseCommit,
Drive a bundle to completion, apply some post-bundle logic, and return the EVM ready for the next bundle or tx.
Sourcepub fn fill_tx<T: Tx>(self, filler: &T) -> EvmReady<Db, Insp>
pub fn fill_tx<T: Tx>(self, filler: &T) -> EvmReady<Db, Insp>
Fill the transaction environment.
Sourcepub fn run_tx<T: Tx>(
self,
filler: &T,
) -> Result<EvmTransacted<Db, Insp>, EvmErrored<Db, Insp>>
pub fn run_tx<T: Tx>( self, filler: &T, ) -> Result<EvmTransacted<Db, Insp>, EvmErrored<Db, Insp>>
Execute a transaction. Shortcut for fill_tx(tx).run()
.
Sourcepub fn call_tx<T: Tx>(
self,
filler: &T,
) -> Result<(ExecutionResult, Self), EvmErrored<Db, Insp>>
Available on crate feature call
only.
pub fn call_tx<T: Tx>( self, filler: &T, ) -> Result<(ExecutionResult, Self), EvmErrored<Db, Insp>>
call
only.Simulate the transaction, and return the ExecutionResult
. The
following modifications are made to the environment while simulating.
- EIP-3607 is disabled.
- Base fee checks are disabled.
- Nonce checks are disabled.
Sourcepub fn estimate_tx_gas<T: Tx>(
self,
filler: &T,
) -> Result<(EstimationResult, EvmReady<Db, Insp>), EvmErrored<Db, Insp>>
Available on crate feature estimate_gas
only.
pub fn estimate_tx_gas<T: Tx>( self, filler: &T, ) -> Result<(EstimationResult, EvmReady<Db, Insp>), EvmErrored<Db, Insp>>
estimate_gas
only.Estimate the gas cost of a transaction. Shortcut for fill_tx(tx). estimate()
. Returns an EstimationResult
and the EVM populated with
the transaction.
Source§impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
Sourcepub fn apply_block_overrides(self, overrides: &BlockOverrides) -> Self
pub fn apply_block_overrides(self, overrides: &BlockOverrides) -> Self
Apply block overrides to the current block.
Note that this is NOT reversible. The overrides are applied directly to
the underlying state and these changes cannot be removed. If it is
important that you have access to the pre-change state, you should wrap
the existing DB in a new State
and apply the overrides to that.
Sourcepub fn maybe_apply_block_overrides(
self,
overrides: Option<&BlockOverrides>,
) -> Self
pub fn maybe_apply_block_overrides( self, overrides: Option<&BlockOverrides>, ) -> Self
Apply block overrides to the current block, if they are provided.
Note that this is NOT reversible. The overrides are applied directly to
the underlying state and these changes cannot be removed. If it is
important that you have access to the pre-change state, you should wrap
the existing DB in a new State
and apply the overrides to that.
Source§impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
Sourcepub fn try_apply_block_overrides(
self,
overrides: &BlockOverrides,
) -> Result<Self, EvmErrored<Db, Insp, <Db as TryStateAcc>::Error>>
pub fn try_apply_block_overrides( self, overrides: &BlockOverrides, ) -> Result<Self, EvmErrored<Db, Insp, <Db as TryStateAcc>::Error>>
Apply block overrides to the current block. This function is
intended to be used by shared states, where mutable access may fail, e.
g. an Arc<Db>
. Prefer Self::apply_block_overrides
when
available.
Note that this is NOT reversible. The overrides are applied directly to
the underlying state and these changes cannot be removed. If it is
important that you have access to the pre-change state, you should wrap
the existing DB in a new State
and apply the overrides to that.
Sourcepub fn try_maybe_apply_block_overrides(
self,
overrides: Option<&BlockOverrides>,
) -> Result<Self, EvmErrored<Db, Insp, <Db as TryStateAcc>::Error>>
pub fn try_maybe_apply_block_overrides( self, overrides: Option<&BlockOverrides>, ) -> Result<Self, EvmErrored<Db, Insp, <Db as TryStateAcc>::Error>>
Apply block overrides to the current block, if they are provided. This
function is intended to be used by shared states, where mutable access
may fail, e.g. an Arc<Db>
.Prefer
Self::maybe_apply_block_overrides
when available.
Note that this is NOT reversible. The overrides are applied directly to
the underlying state and these changes cannot be removed. If it is
important that you have access to the pre-change state, you should wrap
the existing DB in a new State
and apply the overrides to that.
Source§impl<Db, Insp> Trevm<Db, Insp, Ready>
impl<Db, Insp> Trevm<Db, Insp, Ready>
Sourcepub fn clear_tx(self) -> EvmNeedsTx<Db, Insp>
pub fn clear_tx(self) -> EvmNeedsTx<Db, Insp>
Clear the current transaction environment.
Sourcepub fn run(self) -> Result<EvmTransacted<Db, Insp>, EvmErrored<Db, Insp>>
pub fn run(self) -> Result<EvmTransacted<Db, Insp>, EvmErrored<Db, Insp>>
Execute the loaded transaction. This is a wrapper around
InspectEvm::inspect_tx
and produces either EvmTransacted
or
EvmErrored
.
Sourcepub fn call(
self,
) -> Result<(ExecutionResult, EvmNeedsTx<Db, Insp>), EvmErrored<Db, Insp>>
Available on crate feature call
only.
pub fn call( self, ) -> Result<(ExecutionResult, EvmNeedsTx<Db, Insp>), EvmErrored<Db, Insp>>
call
only.Simulate the transaction, and return the ExecutionResult
. The
following modifications are made to the environment while simulating.
- EIP-3607 is disabled.
- Base fee checks are disabled.
- Nonce checks are disabled.
Sourcepub fn calculate_initial_gas(&self) -> u64
pub fn calculate_initial_gas(&self) -> u64
Calculate the minimum gas required to start EVM execution.
This uses calculate_initial_tx_gas_for_tx
to calculate the initial
gas. Its output is dependent on
- the EVM spec
- the input data
- whether the transaction is a contract creation or a call
- the EIP-2930 access list
- the number of EIP-7702 authorizations
Sourcepub fn estimate_gas(
self,
) -> Result<(EstimationResult, Self), EvmErrored<Db, Insp>>
Available on crate feature estimate_gas
only.
pub fn estimate_gas( self, ) -> Result<(EstimationResult, Self), EvmErrored<Db, Insp>>
estimate_gas
only.Implements gas estimation. This will output an estimate of the minimum amount of gas that the transaction will consume, calculated via iterated simulation.
In the worst case this will perform a binary search, resulting in
O(log(n))
simulations.
§Returns
An EstimationResult
and the EVM with the transaction populated.
Like with the remainder of the API, an EVM revert or an EVM halt is
NOT an error. An Err
is returned only if the EVM encounters a
condition of use violation or a DB access fails.
§Estimation Algorithm
This function is largely based on the reth RPC estimation algorithm, which can be found here. The algorithm is as follows:
- Disable eip-3607, allowing estimation from contract accounts.
- Disable base fee checks.
- Check if the transaction is a simple transfer
- Is there input data empty? If yes, proceed to regular estimation
- Is the callee a contract? If yes, proceed to regular estimation
- Otherwise, shortcut return success with
MIN_TRANSACTION_GAS
.
- Simulate the transaction with the maximum possible gas limit.
- If the simulation fails, shortcut return the failure.
- If succesful, store the gas used as the search minimum.
- Simulate the transaction with an “optimistic” gas limit.
- If the simulation fails, shortcut return the failure.
- If succesful, begin the binary search around that range.
- Binary search loop:
- If the search range is small enough, break the loop and return the current estimate.
- Calculate a new gas limit based on the midpoint of the search range.
- Simulate the transaction with the new gas limit.
- Adjust the search range based on the simulation result:
- If the result is a success, pull the search max down to the limit.
- If the result is a revert, push the search min up to the limit.
- If the result is a halt, check if the halt is potentially a
gas-dynamic halt.
- If it is, treat it as a revert.
- If it is not, shortcut return the halt.
- Loop.
Source§impl<Db, Insp> Trevm<Db, Insp, TransactedState>
impl<Db, Insp> Trevm<Db, Insp, TransactedState>
Sourcepub fn result(&self) -> &ExecutionResult
pub fn result(&self) -> &ExecutionResult
Get a reference to the result.
Sourcepub const fn result_mut_unchecked(&mut self) -> &mut ExecutionResult
pub const fn result_mut_unchecked(&mut self) -> &mut ExecutionResult
Get a mutable reference to the result. Modification of the result is discouraged, as it may lead to inconsistent state.
This is primarily intended for use in SystemTx
execution.
Sourcepub const fn state_mut_unchecked(&mut self) -> &mut EvmState
pub const fn state_mut_unchecked(&mut self) -> &mut EvmState
Get a mutable reference to the state. Modification of the state is discouraged, as it may lead to inconsistent state.
Sourcepub fn result_and_state(&self) -> &ResultAndState
pub fn result_and_state(&self) -> &ResultAndState
Get a reference to the result and state.
Sourcepub const fn result_and_state_mut_unchecked(&mut self) -> &mut ResultAndState
pub const fn result_and_state_mut_unchecked(&mut self) -> &mut ResultAndState
Get a mutable reference to the result and state. Modification of the result and state is discouraged, as it may lead to inconsistent state.
This is primarily intended for use in SystemTx
execution.
Sourcepub fn output(&self) -> Option<&Bytes>
pub fn output(&self) -> Option<&Bytes>
Get the output of the transaction. This is the return value of the outermost callframe.
Sourcepub fn output_sol<T: SolCall>(
&self,
validate: bool,
) -> Option<Result<T::Return>>
pub fn output_sol<T: SolCall>( &self, validate: bool, ) -> Option<Result<T::Return>>
Get the output of the transaction, and decode it as the return value of
a SolCall
. If validate
is true, the output will be type- and
range-checked.
Sourcepub fn reject(self) -> EvmNeedsTx<Db, Insp>
pub fn reject(self) -> EvmNeedsTx<Db, Insp>
Discard the state changes and return the EVM.
Sourcepub fn into_result_and_state(self) -> ResultAndState
pub fn into_result_and_state(self) -> ResultAndState
Take the ResultAndState
and return the EVM.
Sourcepub fn take_result_and_state(self) -> (ResultAndState, EvmNeedsTx<Db, Insp>)
pub fn take_result_and_state(self) -> (ResultAndState, EvmNeedsTx<Db, Insp>)
Take the ResultAndState
and return the EVM.
Sourcepub fn take_result(self) -> (ExecutionResult, EvmNeedsTx<Db, Insp>)
pub fn take_result(self) -> (ExecutionResult, EvmNeedsTx<Db, Insp>)
Take the ExecutionResult
, discard the EvmState
and return the
EVM.
Sourcepub fn accept(self) -> (ExecutionResult, EvmNeedsTx<Db, Insp>)where
Db: DatabaseCommit,
pub fn accept(self) -> (ExecutionResult, EvmNeedsTx<Db, Insp>)where
Db: DatabaseCommit,
Accept the state changes, commiting them to the database, and return the
EVM with the ExecutionResult
.
Sourcepub fn try_accept(
self,
) -> Result<(ExecutionResult, EvmNeedsTx<Db, Insp>), EvmErrored<Db, Insp, <Db as TryDatabaseCommit>::Error>>where
Db: TryDatabaseCommit,
pub fn try_accept(
self,
) -> Result<(ExecutionResult, EvmNeedsTx<Db, Insp>), EvmErrored<Db, Insp, <Db as TryDatabaseCommit>::Error>>where
Db: TryDatabaseCommit,
Try to accept the state changes, commiting them to the database, and
return the EVM with the ExecutionResult
. If the commit fails, return
the EVM with the error, discarding the state changes. This is a fallible
version of Self::accept
, intended for use with databases that can
fail to commit. Prefer Self::accept
when possible.
Sourcepub fn accept_state(self) -> EvmNeedsTx<Db, Insp>where
Db: DatabaseCommit,
pub fn accept_state(self) -> EvmNeedsTx<Db, Insp>where
Db: DatabaseCommit,
Accept the state changes, commiting them to the database, dropping the
ExecutionResult
.
Sourcepub fn try_accept_state(
self,
) -> Result<EvmNeedsTx<Db, Insp>, EvmErrored<Db, Insp, <Db as TryDatabaseCommit>::Error>>where
Db: TryDatabaseCommit,
pub fn try_accept_state(
self,
) -> Result<EvmNeedsTx<Db, Insp>, EvmErrored<Db, Insp, <Db as TryDatabaseCommit>::Error>>where
Db: TryDatabaseCommit,
Try to accept the state changes, commiting them to the database. If the
commit fails, return the EVM with the error, discarding the state
changes. This is a fallible version of Self::accept_state
, intended
for use with databases that can fail to commit. Prefer
Self::accept_state
when possible.
Sourcepub fn estimation(&self) -> EstimationResult
Available on crate feature estimate_gas
only.
pub fn estimation(&self) -> EstimationResult
estimate_gas
only.Create an EstimationResult
from the transaction ExecutionResult
.
Sourcepub fn take_estimation(self) -> (EstimationResult, EvmReady<Db, Insp>)
Available on crate feature estimate_gas
only.
pub fn take_estimation(self) -> (EstimationResult, EvmReady<Db, Insp>)
estimate_gas
only.Take the EstimationResult
and return it and the EVM. This discards
pending state changes, but leaves the EVM ready to execute the same
transaction again.
Source§impl<Db: Database, Insp> Trevm<Db, Insp>where
Insp: InspectorWithOutput<Ctx<Db>>,
impl<Db: Database, Insp> Trevm<Db, Insp>where
Insp: InspectorWithOutput<Ctx<Db>>,
Sourcepub fn take_output(&mut self) -> Insp::Output
pub fn take_output(&mut self) -> Insp::Output
Take the output value from the inspector.
This will also reset the output value in the inspector.
Source§impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
impl<Db, Insp> Trevm<Db, Insp, NeedsTx>
Sourcepub fn apply_withdrawals<'b>(
&mut self,
withdrawals: impl IntoIterator<Item = &'b Withdrawal>,
) -> Result<(), EVMError<Db::Error>>
pub fn apply_withdrawals<'b>( &mut self, withdrawals: impl IntoIterator<Item = &'b Withdrawal>, ) -> Result<(), EVMError<Db::Error>>
Apply the withdrawals to the EVM state.
Trait Implementations§
Auto Trait Implementations§
impl<Db, Insp, TrevmState> Freeze for Trevm<Db, Insp, TrevmState>where
TrevmState: Freeze,
impl<Db, Insp = NoOpInspector, TrevmState = NeedsCfg> !RefUnwindSafe for Trevm<Db, Insp, TrevmState>
impl<Db, Insp = NoOpInspector, TrevmState = NeedsCfg> !Send for Trevm<Db, Insp, TrevmState>
impl<Db, Insp = NoOpInspector, TrevmState = NeedsCfg> !Sync for Trevm<Db, Insp, TrevmState>
impl<Db, Insp, TrevmState> Unpin for Trevm<Db, Insp, TrevmState>where
TrevmState: Unpin,
impl<Db, Insp = NoOpInspector, TrevmState = NeedsCfg> !UnwindSafe for Trevm<Db, Insp, TrevmState>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.