diff --git a/Cargo.toml b/Cargo.toml index c09c2858..74bc91ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,9 @@ alloy-evm = { version = "0.27.0", path = "crates/evm", default-features = false alloy-op-evm = { version = "0.27.0", path = "crates/op-evm", default-features = false } # alloy + +alloy-eip7928 = { version = "0.3.0", default-features = false } + alloy-eip2124 = { version = "0.2", default-features = false } alloy-chains = { version = "0.2.0", default-features = false } alloy-eips = { version = "1.5.2", default-features = false } @@ -65,4 +68,13 @@ derive_more = { version = "2", default-features = false, features = ["full"] } serde = { version = "1", default-features = false, features = ["derive"] } thiserror = { version = "2.0.0", default-features = false } serde_json = "1" +tracing = { version = "0.1.41", default-features = false } test-case = "3" + +[patch.crates-io] +# revm = { git = "https://github.com/bluealloy/revm.git", branch = "rakita/bal" } +# op-revm = { git = "https://github.com/bluealloy/revm.git", branch = "rakita/bal" } +alloy-eips = { git = "https://github.com/Soubhik-10/alloy", branch = "bal-devnet-2" } +alloy-consensus = { git = "https://github.com/Soubhik-10/alloy", branch = "bal-devnet-2" } +alloy-rpc-types-eth = { git = "https://github.com/Soubhik-10/alloy", branch = "bal-devnet-2" } +alloy-rpc-types-engine = { git = "https://github.com/Soubhik-10/alloy", branch = "bal-devnet-2" } diff --git a/crates/evm/Cargo.toml b/crates/evm/Cargo.toml index 7491db42..260a1c11 100644 --- a/crates/evm/Cargo.toml +++ b/crates/evm/Cargo.toml @@ -30,6 +30,7 @@ op-alloy = { workspace = true, optional = true } auto_impl.workspace = true derive_more.workspace = true thiserror.workspace = true +tracing.workspace = true [dev-dependencies] alloy-primitives = { workspace = true, features = ["serde"] } @@ -38,10 +39,7 @@ test-case.workspace = true [features] default = ["std"] -secp256k1 = [ - "std", - "alloy-consensus/secp256k1", -] +secp256k1 = ["std", "alloy-consensus/secp256k1"] std = [ "alloy-primitives/std", "revm/std", @@ -53,11 +51,10 @@ std = [ "thiserror/std", "op-alloy?/std", "alloy-rpc-types-eth?/std", - "alloy-rpc-types-engine?/std" -] -gmp = [ - "revm/gmp", + "alloy-rpc-types-engine?/std", + "tracing/std", ] +gmp = ["revm/gmp"] op = ["op-revm", "op-alloy", "alloy-op-hardforks"] overrides = ["dep:alloy-rpc-types-eth"] call-util = ["overrides"] diff --git a/crates/evm/src/block/mod.rs b/crates/evm/src/block/mod.rs index 78fa6051..ce831050 100644 --- a/crates/evm/src/block/mod.rs +++ b/crates/evm/src/block/mod.rs @@ -3,7 +3,7 @@ use crate::{Database, Evm, EvmFactory, FromRecoveredTx, FromTxWithEncoded, RecoveredTx, ToTxEnv}; use alloc::{boxed::Box, vec::Vec}; use alloy_consensus::transaction::Recovered; -use alloy_eips::{eip2718::WithEncoded, eip7685::Requests}; +use alloy_eips::{eip2718::WithEncoded, eip7685::Requests, eip7928::BlockAccessList}; use revm::{ context::result::{ExecutionResult, ResultAndState}, context_interface::either::Either, @@ -39,6 +39,8 @@ pub struct BlockExecutionResult { pub gas_used: u64, /// Blob gas used by the block. pub blob_gas_used: u64, + /// Block Access List of the block + pub block_access_list: Option, } impl Default for BlockExecutionResult { @@ -48,6 +50,7 @@ impl Default for BlockExecutionResult { requests: Default::default(), gas_used: 0, blob_gas_used: 0, + block_access_list: None, } } } diff --git a/crates/evm/src/block/state_changes.rs b/crates/evm/src/block/state_changes.rs index 5587317d..06fd8acf 100644 --- a/crates/evm/src/block/state_changes.rs +++ b/crates/evm/src/block/state_changes.rs @@ -96,10 +96,8 @@ pub fn insert_post_block_withdrawals_balance_increments( if spec.is_shanghai_active_at_timestamp(block_timestamp) { if let Some(withdrawals) = withdrawals { for withdrawal in withdrawals { - if withdrawal.amount > 0 { - *balance_increments.entry(withdrawal.address).or_default() += - withdrawal.amount_wei().to::(); - } + *balance_increments.entry(withdrawal.address).or_default() += + withdrawal.amount_wei().to::(); } } } diff --git a/crates/evm/src/eth/block.rs b/crates/evm/src/eth/block.rs index e63524e0..4e5382da 100644 --- a/crates/evm/src/eth/block.rs +++ b/crates/evm/src/eth/block.rs @@ -17,7 +17,9 @@ use crate::{ }; use alloc::{borrow::Cow, boxed::Box, vec::Vec}; use alloy_consensus::{Header, Transaction, TransactionEnvelope, TxReceipt}; -use alloy_eips::{eip4895::Withdrawals, eip7685::Requests, Encodable2718}; +use alloy_eips::{ + eip4895::Withdrawals, eip7685::Requests, eip7928::BlockAccessList, Encodable2718, +}; use alloy_hardforks::EthereumHardfork; use alloy_primitives::{Bytes, Log, B256}; use revm::{ @@ -193,6 +195,8 @@ where cumulative_gas_used: self.gas_used, })); + self.evm.db_mut().bump_bal_index(); + // Commit the state changes. self.evm.db_mut().commit(state); @@ -202,6 +206,9 @@ where fn finish( mut self, ) -> Result<(Self::Evm, BlockExecutionResult), BlockExecutionError> { + // + self.evm.db_mut().bump_bal_index(); + let requests = if self .spec .is_prague_active_at_timestamp(self.evm.block().timestamp().saturating_to()) @@ -264,6 +271,23 @@ where }) })?; + let bal = if self + .spec + .is_amsterdam_active_at_timestamp(self.evm.block().timestamp().saturating_to()) + { + if let Some(mut alloy_bal) = self.evm.db_mut().take_built_alloy_bal() { + alloy_bal.sort_by_key(|ac| ac.address); + self.evm.db_mut().bal_state.bal_builder = Some(revm::state::bal::Bal::new()); + alloy_bal + } else { + ::tracing::debug!("No Block Access List found in revm db; using default"); + BlockAccessList::default() + } + } else { + BlockAccessList::default() + } + .to_vec(); + Ok(( self.evm, BlockExecutionResult { @@ -271,6 +295,7 @@ where requests, gas_used: self.gas_used, blob_gas_used: self.blob_gas_used, + block_access_list: Some(bal), }, )) } diff --git a/crates/evm/src/overrides.rs b/crates/evm/src/overrides.rs index a3f4ee9d..ddcf0b42 100644 --- a/crates/evm/src/overrides.rs +++ b/crates/evm/src/overrides.rs @@ -75,6 +75,7 @@ where random, base_fee, block_hash, + .. } = overrides; if let Some(block_hashes) = block_hash { diff --git a/crates/op-evm/src/block/mod.rs b/crates/op-evm/src/block/mod.rs index f282bcbe..efd25097 100644 --- a/crates/op-evm/src/block/mod.rs +++ b/crates/op-evm/src/block/mod.rs @@ -377,6 +377,7 @@ where requests: Default::default(), gas_used: legacy_gas_used, blob_gas_used: self.da_footprint_used, + block_access_list: None, }, )) }