Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 5 additions & 4 deletions crates/evm/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloy_evm::{
Database, Evm, EvmEnv, EvmFactory,
precompiles::PrecompilesMap,
revm::{
Context, ExecuteEvm, InspectEvm, Inspector, SystemCallEvm,
context::result::{EVMError, ResultAndState},
Expand All @@ -9,7 +8,9 @@ use alloy_evm::{
};
use alloy_primitives::{Address, Bytes, Log};
use morph_chainspec::hardfork::MorphHardfork;
use morph_revm::{MorphHaltReason, MorphInvalidTransaction, MorphTxEnv, evm::MorphContext};
use morph_revm::{
MorphHaltReason, MorphInvalidTransaction, MorphPrecompiles, MorphTxEnv, evm::MorphContext,
};
use reth_revm::MainContext;
use std::ops::{Deref, DerefMut};

Expand All @@ -28,7 +29,7 @@ impl EvmFactory for MorphEvmFactory {
type HaltReason = MorphHaltReason;
type Spec = MorphHardfork;
type BlockEnv = MorphBlockEnv;
type Precompiles = PrecompilesMap;
type Precompiles = MorphPrecompiles;

fn create_evm<DB: Database>(
&self,
Expand Down Expand Up @@ -142,7 +143,7 @@ where
type HaltReason = MorphHaltReason;
type Spec = MorphHardfork;
type BlockEnv = MorphBlockEnv;
type Precompiles = PrecompilesMap;
type Precompiles = MorphPrecompiles;
type Inspector = I;

fn block(&self) -> &Self::BlockEnv {
Expand Down
22 changes: 13 additions & 9 deletions crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::{MorphBlockEnv, MorphTxEnv};
use alloy_evm::{Database, precompiles::PrecompilesMap};
use crate::{MorphBlockEnv, MorphTxEnv, precompiles::MorphPrecompiles};
use alloy_evm::Database;
use alloy_primitives::Log;
use morph_chainspec::hardfork::MorphHardfork;
use revm::{
Context, Inspector,
context::{CfgEnv, ContextError, Evm, FrameStack},
handler::{
EthFrame, EthPrecompiles, EvmTr, FrameInitOrResult, FrameTr, ItemOrResult,
instructions::EthInstructions,
EthFrame, EvmTr, FrameInitOrResult, FrameTr, ItemOrResult, instructions::EthInstructions,
},
inspector::InspectorEvmTr,
interpreter::interpreter::EthInterpreter,
Expand All @@ -27,7 +26,7 @@ pub struct MorphEvm<DB: Database, I> {
MorphContext<DB>,
I,
EthInstructions<EthInterpreter, MorphContext<DB>>,
PrecompilesMap,
MorphPrecompiles,
EthFrame<EthInterpreter>,
>,
/// Preserved logs from the last transaction
Expand All @@ -36,8 +35,13 @@ pub struct MorphEvm<DB: Database, I> {

impl<DB: Database, I> MorphEvm<DB, I> {
/// Create a new Morph EVM.
///
/// The precompiles are automatically selected based on the hardfork spec
/// configured in the context's cfg.
pub fn new(ctx: MorphContext<DB>, inspector: I) -> Self {
let precompiles = PrecompilesMap::from_static(EthPrecompiles::default().precompiles);
// Get the current hardfork spec from context and create matching precompiles
let spec = ctx.cfg.spec;
let precompiles = MorphPrecompiles::new_with_spec(spec);

Self::new_inner(Evm {
ctx,
Expand All @@ -56,7 +60,7 @@ impl<DB: Database, I> MorphEvm<DB, I> {
MorphContext<DB>,
I,
EthInstructions<EthInterpreter, MorphContext<DB>>,
PrecompilesMap,
MorphPrecompiles,
EthFrame<EthInterpreter>,
>,
) -> Self {
Expand All @@ -74,7 +78,7 @@ impl<DB: Database, I> MorphEvm<DB, I> {
}

/// Consumes self and returns a new Evm type with given Precompiles.
pub fn with_precompiles(self, precompiles: PrecompilesMap) -> Self {
pub fn with_precompiles(self, precompiles: MorphPrecompiles) -> Self {
Self::new_inner(self.inner.with_precompiles(precompiles))
}

Expand All @@ -96,7 +100,7 @@ where
{
type Context = MorphContext<DB>;
type Instructions = EthInstructions<EthInterpreter, MorphContext<DB>>;
type Precompiles = PrecompilesMap;
type Precompiles = MorphPrecompiles;
type Frame = EthFrame<EthInterpreter>;

fn all(
Expand Down
16 changes: 9 additions & 7 deletions crates/revm/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ where
}

// Fetch token fee info from Token Registry
let token_fee_info = TokenFeeInfo::try_fetch(evm.ctx_mut().db_mut(), token_id, caller)?
.ok_or(MorphInvalidTransaction::TokenNotRegistered(token_id))?;
let spec = evm.ctx_ref().cfg().spec;
let token_fee_info =
TokenFeeInfo::try_fetch(evm.ctx_mut().db_mut(), token_id, caller, spec)?
.ok_or(MorphInvalidTransaction::TokenNotRegistered(token_id))?;

// Check if token is active
if !token_fee_info.is_active {
Expand Down Expand Up @@ -380,19 +382,19 @@ where
let caller_addr = tx.caller();
// Get coinbase address
let beneficiary = block.beneficiary();
// Get the current hardfork for L1 fee calculation
let hardfork = cfg.spec();

// Fetch token fee info from Token Registry
let token_fee_info = TokenFeeInfo::try_fetch(journal.db_mut(), token_id, caller_addr)?
.ok_or(MorphInvalidTransaction::TokenNotRegistered(token_id))?;
let token_fee_info =
TokenFeeInfo::try_fetch(journal.db_mut(), token_id, caller_addr, hardfork)?
.ok_or(MorphInvalidTransaction::TokenNotRegistered(token_id))?;

// Check if token is active
if !token_fee_info.is_active {
return Err(MorphInvalidTransaction::TokenNotActive(token_id).into());
}

// Get the current hardfork for L1 fee calculation
let hardfork = cfg.spec();

// Fetch L1 block info from the L1 Gas Price Oracle contract
let l1_block_info = L1BlockInfo::try_fetch(journal.db_mut(), hardfork)?;

Expand Down
2 changes: 2 additions & 0 deletions crates/revm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ pub mod evm;
pub mod exec;
pub mod handler;
pub mod l1block;
pub mod precompiles;
pub mod token_fee;
mod tx;

pub use block::MorphBlockEnv;
pub use error::{MorphHaltReason, MorphInvalidTransaction};
pub use evm::MorphEvm;
pub use l1block::{L1_GAS_PRICE_ORACLE_ADDRESS, L1BlockInfo};
pub use precompiles::MorphPrecompiles;
pub use token_fee::{L2_TOKEN_REGISTRY_ADDRESS, TokenFeeInfo, get_erc20_balance_with_evm};
pub use tx::{MorphTxEnv, MorphTxExt};
Loading
Loading