Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: relax a generic trait #12

Merged
merged 8 commits into from
Feb 13, 2025
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ serde = { version = "1", default-features = false, features = ["derive"] }

[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm", rev = "b67ca3e" }
revm-optimism = { git = "https://github.com/bluealloy/revm", rev = "b67ca3e" }
revm-optimism = { git = "https://github.com/bluealloy/revm", rev = "b67ca3e" }
47 changes: 37 additions & 10 deletions crates/evm/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,45 @@ use core::{
ops::{Deref, DerefMut},
};
use revm::{
context::{BlockEnv, CfgEnv, TxEnv},
context::{BlockEnv, CfgEnv, Evm as RevmEvm, TxEnv},
context_interface::result::{EVMError, HaltReason, ResultAndState},
handler::{Inspector, NoOpInspector},
Context, ExecuteEvm, InspectEvm, MainBuilder, MainContext, MainnetEvm,
handler::{
instructions::EthInstructions, EthPrecompiles, Inspector, NoOpInspector, PrecompileProvider,
},
interpreter::{interpreter::EthInterpreter, InterpreterResult},
Context, ExecuteEvm, InspectEvm, MainBuilder, MainContext,
};

/// The Ethereum EVM context type.
pub type EthEvmContext<DB> = Context<BlockEnv, TxEnv, CfgEnv, DB>;

/// Ethereum EVM implementation.
#[expect(missing_debug_implementations)]
pub struct EthEvm<DB: Database, I>(MainnetEvm<EthEvmContext<DB>, I>);
pub struct EthEvm<DB: Database, I, PRECOMPILE = EthPrecompiles<EthEvmContext<DB>>>(
RevmEvm<EthEvmContext<DB>, I, EthInstructions<EthInterpreter, EthEvmContext<DB>>, PRECOMPILE>,
);
Comment on lines +25 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there no mainnet evm anymore?

isn't this intended as a wrapper around the plain L1 evm?

imo this shouldn't require this much setup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I think this is so that this specific EthEvm type can be reused

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will likely be a common use case so worth thinking how we can simplify this setup out of the box

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I think this is so that this specific EthEvm type can be reused

Yes, so we can change precompiles as in reth precompile example.

As the default value for Precompiles is EthPrecompile it will be the same as the previous Mainnet type.

We could use Box<dyn Precompiles> that would remove generic from it.


impl<DB: Database, I, PRECOMPILE> EthEvm<DB, I, PRECOMPILE> {
/// Creates a new Ethereum EVM instance.
pub const fn new(
evm: RevmEvm<
EthEvmContext<DB>,
I,
EthInstructions<EthInterpreter, EthEvmContext<DB>>,
PRECOMPILE,
>,
) -> Self {
Self(evm)
}

/// Consumes self and return the inner EVM instance.
pub fn into_inner(
self,
) -> RevmEvm<EthEvmContext<DB>, I, EthInstructions<EthInterpreter, EthEvmContext<DB>>, PRECOMPILE>
{
self.0
}

impl<DB: Database, I> EthEvm<DB, I> {
/// Provides a reference to the EVM context.
pub const fn ctx(&self) -> &EthEvmContext<DB> {
&self.0.data.ctx
Expand All @@ -33,7 +58,7 @@ impl<DB: Database, I> EthEvm<DB, I> {
}
}

impl<DB: Database, I> Deref for EthEvm<DB, I> {
impl<DB: Database, I, PRECOMPILE> Deref for EthEvm<DB, I, PRECOMPILE> {
type Target = EthEvmContext<DB>;

#[inline]
Expand All @@ -42,17 +67,18 @@ impl<DB: Database, I> Deref for EthEvm<DB, I> {
}
}

impl<DB: Database, I> DerefMut for EthEvm<DB, I> {
impl<DB: Database, I, PRECOMPILE> DerefMut for EthEvm<DB, I, PRECOMPILE> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
self.ctx_mut()
}
}

impl<DB, I> EthEvm<DB, I>
impl<DB, I, PRECOMPILE> EthEvm<DB, I, PRECOMPILE>
where
DB: Database,
I: Inspector<EthEvmContext<DB>>,
PRECOMPILE: PrecompileProvider<Context = EthEvmContext<DB>, Output = InterpreterResult>,
{
fn transact(&mut self, tx: TxEnv) -> Result<ResultAndState, EVMError<DB::Error>> {
if self.0.enabled_inspection {
Expand All @@ -64,10 +90,11 @@ where
}
}

impl<DB, I> Evm for EthEvm<DB, I>
impl<DB, I, PRECOMPILE> Evm for EthEvm<DB, I, PRECOMPILE>
where
DB: Database,
I: Inspector<EthEvmContext<DB>>,
PRECOMPILE: PrecompileProvider<Context = EthEvmContext<DB>, Output = InterpreterResult>,
{
type DB = DB;
type Tx = TxEnv;
Expand All @@ -79,7 +106,7 @@ where
}

fn transact(&mut self, tx: Self::Tx) -> Result<ResultAndState, Self::Error> {
self.transact(tx)
self.0.transact(tx)
}

fn transact_system_call(
Expand Down
2 changes: 1 addition & 1 deletion crates/op-evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
}

fn transact(&mut self, tx: Self::Tx) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
self.transact(tx)
self.0.transact(tx)
}

fn transact_system_call(
Expand Down
Loading