Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/evm/src/block/system_calls/eip2935.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use alloc::string::ToString;
use alloy_eips::eip2935::HISTORY_STORAGE_ADDRESS;
use alloy_hardforks::EthereumHardforks;
use alloy_primitives::B256;
use revm::context_interface::result::ResultAndState;
use revm::{context_interface::result::ResultAndState, state::EvmState};

/// Applies the pre-block call to the [EIP-2935] blockhashes contract, using the given block,
/// chain specification, and EVM.
Expand All @@ -23,11 +23,11 @@ use revm::context_interface::result::ResultAndState;
///
/// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935
#[inline]
pub(crate) fn transact_blockhashes_contract_call<Halt>(
pub(crate) fn transact_blockhashes_contract_call<Halt, State: Into<EvmState>>(
spec: impl EthereumHardforks,
parent_block_hash: B256,
evm: &mut impl Evm<HaltReason = Halt>,
) -> Result<Option<ResultAndState<Halt>>, BlockExecutionError> {
evm: &mut impl Evm<HaltReason = Halt, State = State>,
) -> Result<Option<ResultAndState<Halt, State>>, BlockExecutionError> {
if !spec.is_prague_active_at_timestamp(evm.block().timestamp.saturating_to()) {
return Ok(None);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/evm/src/block/system_calls/eip4788.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use alloc::{boxed::Box, string::ToString};
use alloy_eips::eip4788::BEACON_ROOTS_ADDRESS;
use alloy_hardforks::EthereumHardforks;
use alloy_primitives::B256;
use revm::context_interface::result::ResultAndState;
use revm::{context_interface::result::ResultAndState, state::EvmState};

/// Applies the pre-block call to the [EIP-4788] beacon block root contract, using the given block,
/// chain spec, EVM.
Expand All @@ -20,11 +20,11 @@ use revm::context_interface::result::ResultAndState;
///
/// [EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788
#[inline]
pub(crate) fn transact_beacon_root_contract_call<Halt>(
pub(crate) fn transact_beacon_root_contract_call<Halt, State: Into<EvmState>>(
spec: impl EthereumHardforks,
parent_beacon_block_root: Option<B256>,
evm: &mut impl Evm<HaltReason = Halt>,
) -> Result<Option<ResultAndState<Halt>>, BlockExecutionError> {
evm: &mut impl Evm<HaltReason = Halt, State = State>,
) -> Result<Option<ResultAndState<Halt, State>>, BlockExecutionError> {
if !spec.is_cancun_active_at_timestamp(evm.block().timestamp.saturating_to()) {
return Ok(None);
}
Expand Down
11 changes: 7 additions & 4 deletions crates/evm/src/block/system_calls/eip7002.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ use alloc::format;
use alloy_eips::eip7002::WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS;
use alloy_primitives::Bytes;
use core::fmt::Debug;
use revm::context_interface::result::{ExecutionResult, ResultAndState};
use revm::{
context_interface::result::{ExecutionResult, ResultAndState},
state::EvmState,
};

/// Applies the post-block call to the EIP-7002 withdrawal requests contract.
///
/// If Prague is not active at the given timestamp, then this is a no-op.
///
/// Note: this does not commit the state changes to the database, it only transact the call.
#[inline]
pub(crate) fn transact_withdrawal_requests_contract_call<Halt>(
evm: &mut impl Evm<HaltReason = Halt>,
) -> Result<ResultAndState<Halt>, BlockExecutionError> {
pub(crate) fn transact_withdrawal_requests_contract_call<Halt, State: Into<EvmState>>(
evm: &mut impl Evm<HaltReason = Halt, State = State>,
) -> Result<ResultAndState<Halt, State>, BlockExecutionError> {
// Execute EIP-7002 withdrawal requests contract message data.
//
// This requirement for the withdrawal requests contract call defined by
Expand Down
11 changes: 7 additions & 4 deletions crates/evm/src/block/system_calls/eip7251.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use alloc::format;
use alloy_eips::eip7251::CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS;
use alloy_primitives::Bytes;
use core::fmt::Debug;
use revm::context_interface::result::{ExecutionResult, ResultAndState};
use revm::{
context_interface::result::{ExecutionResult, ResultAndState},
state::EvmState,
};

/// Applies the post-block call to the EIP-7251 consolidation requests contract.
///
Expand All @@ -17,9 +20,9 @@ use revm::context_interface::result::{ExecutionResult, ResultAndState};
///
/// Note: this does not commit the state changes to the database, it only transact the call.
#[inline]
pub(crate) fn transact_consolidation_requests_contract_call<Halt>(
evm: &mut impl Evm<HaltReason = Halt>,
) -> Result<ResultAndState<Halt>, BlockExecutionError> {
pub(crate) fn transact_consolidation_requests_contract_call<Halt, State: Into<EvmState>>(
evm: &mut impl Evm<HaltReason = Halt, State = State>,
) -> Result<ResultAndState<Halt, State>, BlockExecutionError> {
// Execute EIP-7251 consolidation requests contract message data.
//
// This requirement for the consolidation requests contract call defined by
Expand Down
20 changes: 12 additions & 8 deletions crates/evm/src/block/system_calls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ where
eip2935::transact_blockhashes_contract_call(&self.spec, parent_block_hash, evm)?;

if let Some(res) = result_and_state {
let evm_state = res.state.into();
if let Some(hook) = &mut self.hook {
hook.on_state(
StateChangeSource::PreBlock(StateChangePreBlockSource::BlockHashesContract),
&res.state,
&evm_state,
);
}
evm.db_mut().commit(res.state);
evm.db_mut().commit(evm_state);
}

Ok(())
Expand All @@ -115,13 +116,14 @@ where
eip4788::transact_beacon_root_contract_call(&self.spec, parent_beacon_block_root, evm)?;

if let Some(res) = result_and_state {
let evm_state = res.state.into();
if let Some(hook) = &mut self.hook {
hook.on_state(
StateChangeSource::PreBlock(StateChangePreBlockSource::BeaconRootContract),
&res.state,
&evm_state,
);
}
evm.db_mut().commit(res.state);
evm.db_mut().commit(evm_state);
}

Ok(())
Expand All @@ -134,15 +136,16 @@ where
) -> Result<Bytes, BlockExecutionError> {
let result_and_state = eip7002::transact_withdrawal_requests_contract_call(evm)?;

let evm_state = result_and_state.state.into();
if let Some(ref mut hook) = &mut self.hook {
hook.on_state(
StateChangeSource::PostBlock(
StateChangePostBlockSource::WithdrawalRequestsContract,
),
&result_and_state.state,
&evm_state,
);
}
evm.db_mut().commit(result_and_state.state);
evm.db_mut().commit(evm_state);

eip7002::post_commit(result_and_state.result)
}
Expand All @@ -154,15 +157,16 @@ where
) -> Result<Bytes, BlockExecutionError> {
let result_and_state = eip7251::transact_consolidation_requests_contract_call(evm)?;

let evm_state = result_and_state.state.into();
if let Some(ref mut hook) = &mut self.hook {
hook.on_state(
StateChangeSource::PostBlock(
StateChangePostBlockSource::ConsolidationRequestsContract,
),
&result_and_state.state,
&evm_state,
);
}
evm.db_mut().commit(result_and_state.state);
evm.db_mut().commit(evm_state);

eip7251::post_commit(result_and_state.result)
}
Expand Down
11 changes: 8 additions & 3 deletions crates/evm/src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ where
Spec = L::Spec,
Precompiles = L::Precompiles,
Inspector = L::Inspector,
State = L::State,
>,
{
type DB = L::DB;
Expand All @@ -22,6 +23,7 @@ where
type Spec = L::Spec;
type Precompiles = L::Precompiles;
type Inspector = L::Inspector;
type State = L::State;

fn block(&self) -> &BlockEnv {
either::for_both!(self, evm => evm.block())
Expand All @@ -34,14 +36,16 @@ where
fn transact_raw(
&mut self,
tx: Self::Tx,
) -> Result<revm::context::result::ResultAndState<Self::HaltReason>, Self::Error> {
) -> Result<revm::context::result::ResultAndState<Self::HaltReason, Self::State>, Self::Error>
{
either::for_both!(self, evm => evm.transact_raw(tx))
}

fn transact(
&mut self,
tx: impl crate::IntoTxEnv<Self::Tx>,
) -> Result<revm::context::result::ResultAndState<Self::HaltReason>, Self::Error> {
) -> Result<revm::context::result::ResultAndState<Self::HaltReason, Self::State>, Self::Error>
{
either::for_both!(self, evm => evm.transact(tx))
}

Expand All @@ -50,7 +54,8 @@ where
caller: Address,
contract: Address,
data: Bytes,
) -> Result<revm::context::result::ResultAndState<Self::HaltReason>, Self::Error> {
) -> Result<revm::context::result::ResultAndState<Self::HaltReason, Self::State>, Self::Error>
{
either::for_both!(self, evm => evm.transact_system_call(caller, contract, data))
}

Expand Down
9 changes: 6 additions & 3 deletions crates/evm/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ where
return Ok(None);
}

self.system_caller.on_state(StateChangeSource::Transaction(self.receipts.len()), &state);
let evm_state = state.into();

self.system_caller
.on_state(StateChangeSource::Transaction(self.receipts.len()), &evm_state);

let gas_used = result.gas_used();

Expand All @@ -144,12 +147,12 @@ where
tx: tx.tx(),
evm: &self.evm,
result,
state: &state,
state: &evm_state,
cumulative_gas_used: self.gas_used,
}));

// Commit the state changes.
self.evm.db_mut().commit(state);
self.evm.db_mut().commit(evm_state);

Ok(Some(gas_used))
}
Expand Down
2 changes: 2 additions & 0 deletions crates/evm/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use revm::{
interpreter::{interpreter::EthInterpreter, InterpreterResult},
precompile::{PrecompileSpecId, Precompiles},
primitives::hardfork::SpecId,
state::EvmState,
Context, ExecuteEvm, InspectEvm, Inspector, MainBuilder, MainContext, SystemCallEvm,
};

Expand Down Expand Up @@ -200,6 +201,7 @@ where
type Spec = SpecId;
type Precompiles = PRECOMPILE;
type Inspector = I;
type State = EvmState;

fn block(&self) -> &BlockEnv {
&self.block
Expand Down
11 changes: 7 additions & 4 deletions crates/evm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use revm::{
ContextTr,
},
inspector::{JournalExt, NoOpInspector},
state::EvmState,
DatabaseCommit, Inspector,
};

Expand Down Expand Up @@ -57,6 +58,8 @@ pub trait Evm {
type Precompiles;
/// Evm inspector.
type Inspector;
/// State of the EVM.
type State: Into<EvmState>;

/// Reference to [`BlockEnv`].
fn block(&self) -> &BlockEnv;
Expand All @@ -68,7 +71,7 @@ pub trait Evm {
fn transact_raw(
&mut self,
tx: Self::Tx,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error>;
) -> Result<ResultAndState<Self::HaltReason, Self::State>, Self::Error>;

/// Same as [`Evm::transact_raw`], but takes any type implementing [`IntoTxEnv`].
///
Expand All @@ -84,7 +87,7 @@ pub trait Evm {
fn transact(
&mut self,
tx: impl IntoTxEnv<Self::Tx>,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
) -> Result<ResultAndState<Self::HaltReason, Self::State>, Self::Error> {
self.transact_raw(tx.into_tx_env())
}

Expand All @@ -98,7 +101,7 @@ pub trait Evm {
caller: Address,
contract: Address,
data: Bytes,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error>;
) -> Result<ResultAndState<Self::HaltReason, Self::State>, Self::Error>;

/// Returns an immutable reference to the underlying database.
fn db(&self) -> &Self::DB {
Expand All @@ -119,7 +122,7 @@ pub trait Evm {
Self::DB: DatabaseCommit,
{
let ResultAndState { result, state } = self.transact(tx)?;
self.db_mut().commit(state);
self.db_mut().commit(state.into());

Ok(result)
}
Expand Down
5 changes: 3 additions & 2 deletions crates/evm/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ where
return None;
};
let mut was_fused = false;
let evm_state = state.into();
let output = (self.hook)(TracingCtx {
tx,
result,
state: &state,
state: &evm_state,
inspector,
db,
fused_inspector: &*fused_inspector,
Expand All @@ -171,7 +172,7 @@ where
// Only commit next transaction if `skip_last_commit` is disabled or there is a next
// transaction.
if !self.skip_last_commit || self.txs.peek().is_some() {
db.commit(state);
db.commit(evm_state);
}

if self.fuse && !was_fused {
Expand Down
8 changes: 5 additions & 3 deletions crates/op-evm/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ where
return Ok(None);
}

self.system_caller.on_state(StateChangeSource::Transaction(self.receipts.len()), &state);
let evm_state = state.into();
self.system_caller
.on_state(StateChangeSource::Transaction(self.receipts.len()), &evm_state);

let gas_used = result.gas_used();

Expand All @@ -179,7 +181,7 @@ where
result,
cumulative_gas_used: self.gas_used,
evm: &self.evm,
state: &state,
state: &evm_state,
}) {
Ok(receipt) => receipt,
Err(ctx) => {
Expand Down Expand Up @@ -209,7 +211,7 @@ where
},
);

self.evm.db_mut().commit(state);
self.evm.db_mut().commit(evm_state);

Ok(Some(gas_used))
}
Expand Down
2 changes: 2 additions & 0 deletions crates/op-evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use revm::{
handler::{instructions::EthInstructions, PrecompileProvider},
inspector::NoOpInspector,
interpreter::{interpreter::EthInterpreter, InterpreterResult},
state::EvmState,
Context, ExecuteEvm, InspectEvm, Inspector, SystemCallEvm,
};

Expand Down Expand Up @@ -96,6 +97,7 @@ where
type Spec = OpSpecId;
type Precompiles = P;
type Inspector = I;
type State = EvmState;

fn block(&self) -> &BlockEnv {
&self.block
Expand Down