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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ serde = { version = "1", default-features = false, features = ["derive"] }
thiserror = { version = "2.0.0", default-features = false }
serde_json = "1"

#[patch.crates-io]
#revm = { git = "https://github.com/bluealloy/revm", rev = "11b16259" }
#op-revm = { git = "https://github.com/bluealloy/revm", rev = "11b16259" }
[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm", rev = "9008e93" }
op-revm = { git = "https://github.com/bluealloy/revm", rev = "9008e93" }
9 changes: 9 additions & 0 deletions crates/evm/src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ where
either::for_both!(self, evm => evm.transact(tx))
}

fn inspect_system_call(
&mut self,
caller: Address,
contract: Address,
data: Bytes,
) -> Result<revm::context::result::ResultAndState<Self::HaltReason>, Self::Error> {
either::for_both!(self, evm => evm.inspect_system_call(caller, contract, data))
}

fn transact_system_call(
&mut self,
caller: Address,
Expand Down
25 changes: 22 additions & 3 deletions crates/evm/src/eth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Ethereum EVM implementation.

use crate::{env::EvmEnv, evm::EvmFactory, precompiles::PrecompilesMap, Database, Evm};
use alloy_primitives::{Address, Bytes};
use alloy_primitives::{Address, Bytes, TxKind};
use core::{
fmt::Debug,
ops::{Deref, DerefMut},
Expand All @@ -14,7 +14,8 @@ use revm::{
interpreter::{interpreter::EthInterpreter, InterpreterResult},
precompile::{PrecompileSpecId, Precompiles},
primitives::hardfork::SpecId,
Context, ExecuteEvm, InspectEvm, Inspector, MainBuilder, MainContext, SystemCallEvm,
Context, ExecuteEvm, InspectEvm, InspectSystemCallEvm, Inspector, MainBuilder, MainContext,
SystemCallEvm,
};

mod block;
Expand Down Expand Up @@ -103,6 +104,9 @@ impl<DB: Database, I, PRECOMPILE> DerefMut for EthEvm<DB, I, PRECOMPILE> {
}
}

/// Transaction type identifier for Berachain POL transactions
pub const POL_TX_TYPE: u8 = 126;

impl<DB, I, PRECOMPILE> Evm for EthEvm<DB, I, PRECOMPILE>
where
DB: Database,
Expand All @@ -129,20 +133,35 @@ where
&mut self,
tx: Self::Tx,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
if tx.tx_type == POL_TX_TYPE && self.inspect {
return match tx.kind {
TxKind::Create => Err(EVMError::Custom("pol tx cannot be create".into())),
TxKind::Call(to) => self.inspect_system_call(tx.caller, to, tx.data),
};
}
if self.inspect {
self.inner.inspect_tx(tx)
} else {
self.inner.transact(tx)
}
}

fn inspect_system_call(
&mut self,
caller: Address,
contract: Address,
data: Bytes,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
self.inner.inspect_system_call_with_caller(caller, contract, data)
}

fn transact_system_call(
&mut self,
caller: Address,
contract: Address,
data: Bytes,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
self.inner.transact_system_call_with_caller_finalize(caller, contract, data)
self.inner.system_call_with_caller(caller, contract, data)
}

fn finish(self) -> (Self::DB, EvmEnv<Self::Spec>) {
Expand Down
12 changes: 12 additions & 0 deletions crates/evm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ pub trait Evm {
self.transact_raw(tx.into_tx_env())
}

/// Inspects a system call without committing state changes.
///
/// This method executes a system call with inspection enabled, allowing observation of the
/// execution without modifying the underlying state. Similar to [`Evm::transact_system_call`]
/// but returns the result with state changes that can be examined or discarded.
fn inspect_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
Expand Down
13 changes: 11 additions & 2 deletions crates/op-evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use revm::{
handler::{instructions::EthInstructions, PrecompileProvider},
inspector::NoOpInspector,
interpreter::{interpreter::EthInterpreter, InterpreterResult},
Context, ExecuteEvm, InspectEvm, Inspector, SystemCallEvm,
Context, ExecuteEvm, InspectEvm, InspectSystemCallEvm, Inspector, SystemCallEvm,
};

pub mod block;
Expand Down Expand Up @@ -116,13 +116,22 @@ where
}
}

fn inspect_system_call(
&mut self,
caller: Address,
contract: Address,
data: Bytes,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
self.inner.inspect_system_call_with_caller(caller, contract, data)
}

fn transact_system_call(
&mut self,
caller: Address,
contract: Address,
data: Bytes,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
self.inner.transact_system_call_with_caller_finalize(caller, contract, data)
self.inner.system_call_with_caller(caller, contract, data)
}

fn finish(self) -> (Self::DB, EvmEnv<Self::Spec>) {
Expand Down
Loading