Skip to content
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
15 changes: 4 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ alloy-eips = { version = "1.0.34", default-features = false }
alloy-consensus = { version = "1.0.27", default-features = false }
alloy-primitives = { version = "1.0.0", default-features = false }
alloy-sol-types = { version = "1.0.0", default-features = false }
alloy-hardforks = { version = "0.4.2" }
alloy-hardforks = { version = "0.4.7" }
alloy-rpc-types-eth = { version = "1.0.27", default-features = false }
alloy-rpc-types-engine = { version = "1.0.27", default-features = false }

# op-alloy
alloy-op-hardforks = { version = "0.4.2" }
alloy-op-hardforks = { version = "0.4.7" }
op-alloy = { version = "0.23", default-features = false, features = [
"consensus",
] }

# revm
revm = { version = "33.0.0", default-features = false }
op-revm = { version = "14.0.0", default-features = false }
revm = { version = "34.0.0", default-features = false }
op-revm = { version = "15.0.0", default-features = false }

# misc
auto_impl = "1"
Expand All @@ -66,10 +66,3 @@ serde = { version = "1", default-features = false, features = ["derive"] }
thiserror = { version = "2.0.0", default-features = false }
serde_json = "1"
test-case = "3"

[patch.crates-io]
# revm = { git = "https://github.com/bluealloy/revm", rev = "11b16259" }
# op-revm = { git = "https://github.com/bluealloy/revm", rev = "11b16259" }

#alloy-hardforks = { git = "https://github.com/alloy-rs/hardforks", rev = "0fd230f5aa24c4f6a8c593918b7449df0c20f60a" }
#alloy-op-hardforks = { git = "https://github.com/alloy-rs/hardforks", rev = "0fd230f5aa24c4f6a8c593918b7449df0c20f60a" }
28 changes: 0 additions & 28 deletions crates/evm/src/block/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! State database abstraction.

use alloy_primitives::Address;
use revm::database::State;

/// A type which has the state of the blockchain.
Expand All @@ -9,44 +8,17 @@ use revm::database::State;
pub trait StateDB: revm::Database {
/// State clear EIP-161 is enabled in Spurious Dragon hardfork.
fn set_state_clear_flag(&mut self, has_state_clear: bool);

/// Iterates over received balances and increment all account balances.
///
/// **Note**: If account is not found inside cache state it will be loaded from database.
///
/// Update will create transitions for all accounts that are updated.
///
/// If using this to implement withdrawals, zero balances must be filtered out before calling
/// this function.
fn increment_balances(
&mut self,
balances: impl IntoIterator<Item = (Address, u128)>,
) -> Result<(), Self::Error>;
}

/// auto_impl unable to reconcile return associated type from supertrait
impl<T: StateDB> StateDB for &mut T {
fn set_state_clear_flag(&mut self, has_state_clear: bool) {
StateDB::set_state_clear_flag(*self, has_state_clear);
}

fn increment_balances(
&mut self,
balances: impl IntoIterator<Item = (Address, u128)>,
) -> Result<(), Self::Error> {
StateDB::increment_balances(*self, balances)
}
}

impl<DB: revm::Database> StateDB for State<DB> {
fn set_state_clear_flag(&mut self, has_state_clear: bool) {
self.cache.set_state_clear_flag(has_state_clear);
}

fn increment_balances(
&mut self,
balances: impl IntoIterator<Item = (Address, u128)>,
) -> Result<(), Self::Error> {
Self::increment_balances(self, balances)
}
}
5 changes: 3 additions & 2 deletions crates/evm/src/block/state_changes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! State changes that are not related to transactions.

use super::{calc, BlockExecutionError};
use alloc::boxed::Box;
use alloy_consensus::BlockHeader;
use alloy_eips::eip4895::{Withdrawal, Withdrawals};
use alloy_hardforks::EthereumHardforks;
Expand Down Expand Up @@ -127,9 +128,9 @@ where
*address,
Account {
info: account.clone(),
storage: Default::default(),
original_info: Box::new(account.clone()),
status: AccountStatus::Touched,
transaction_id: 0,
..Default::default()
},
))
};
Expand Down
8 changes: 7 additions & 1 deletion crates/evm/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ use revm::{
};

/// Container type that holds both the configuration and block environment for EVM execution.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EvmEnv<Spec = SpecId, BlockEnv = revm::context::BlockEnv> {
/// The configuration environment with handler settings
pub cfg_env: CfgEnv<Spec>,
/// The block environment containing block-specific data
pub block_env: BlockEnv,
}

impl<Spec: Default + Into<SpecId> + Clone, B: Default> Default for EvmEnv<Spec, B> {
fn default() -> Self {
Self { cfg_env: CfgEnv::new_with_spec(Spec::default()), block_env: B::default() }
}
}

impl<Spec, BlockEnv> EvmEnv<Spec, BlockEnv> {
/// Create a new `EvmEnv` from its components.
///
Expand Down
6 changes: 4 additions & 2 deletions crates/evm/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ use alloy_eips::{eip4895::Withdrawals, eip7685::Requests, Encodable2718};
use alloy_hardforks::EthereumHardfork;
use alloy_primitives::{Bytes, Log, B256};
use revm::{
context::Block, context_interface::result::ResultAndState, database::State, DatabaseCommit,
Inspector,
context::Block,
context_interface::result::ResultAndState,
database::{DatabaseCommitExt, State},
DatabaseCommit, Inspector,
};

/// Context for Ethereum block execution.
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct EthEvmBuilder<DB: Database, I = NoOpInspector> {

impl<DB: Database> EthEvmBuilder<DB, NoOpInspector> {
/// Creates a builder from the provided `EvmEnv` and database.
pub const fn new(db: DB, env: EvmEnv) -> Self {
pub fn new(db: DB, env: EvmEnv) -> Self {
Self {
db,
block_env: env.block_env,
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/op/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl EvmEnv<OpSpecId> {

fn for_op(input: EvmEnvInput, chain_spec: impl OpHardforks, chain_id: ChainId) -> Self {
let spec = crate::op::spec_by_timestamp_after_bedrock(&chain_spec, input.timestamp);
let cfg_env = CfgEnv::new().with_chain_id(chain_id).with_spec(spec);
let cfg_env = CfgEnv::new().with_chain_id(chain_id).with_spec_and_mainnet_gas_params(spec);

let blob_excess_gas_and_price = spec
.into_eth_spec()
Expand Down
5 changes: 3 additions & 2 deletions crates/evm/src/overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This module provides helper functions for RPC implementations, including:
//! - Block and state overrides

use alloc::collections::BTreeMap;
use alloc::{boxed::Box, collections::BTreeMap};
use alloy_primitives::{keccak256, map::HashMap, Address, B256, U256};
use alloy_rpc_types_eth::{
state::{AccountOverride, StateOverride},
Expand Down Expand Up @@ -144,7 +144,8 @@ where

// Create a new account marked as touched
let mut acc = revm::state::Account {
info,
info: info.clone(),
original_info: Box::new(info),
status: AccountStatus::Touched,
storage: Default::default(),
transaction_id: 0,
Expand Down
Loading