From 6b86b5e494e045d1f221cd32165376670445220a Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Mon, 26 Aug 2024 12:33:00 +0200 Subject: [PATCH 1/3] feat: use system call to update blockhashes --- Cargo.lock | 1 - crates/ethereum/evm/src/execute.rs | 15 ++- crates/ethereum/payload/src/lib.rs | 25 ++-- crates/evm/execution-errors/src/lib.rs | 8 +- crates/evm/src/system_calls.rs | 107 +++++++++++++++++- crates/revm/Cargo.toml | 3 - crates/revm/src/state_change.rs | 78 +------------ .../rpc-eth-api/src/helpers/pending_block.rs | 20 ++-- crates/rpc/rpc-eth-types/src/pending_block.rs | 38 +------ crates/rpc/rpc/src/debug.rs | 12 +- 10 files changed, 161 insertions(+), 146 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3eeca2328d07..ec239fc52d6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8284,7 +8284,6 @@ dependencies = [ name = "reth-revm" version = "1.0.5" dependencies = [ - "alloy-eips", "reth-chainspec", "reth-consensus-common", "reth-ethereum-forks", diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index d0d3414cb6ac..88b9f032cefa 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -13,8 +13,8 @@ use reth_evm::{ BlockExecutorProvider, BlockValidationError, Executor, ProviderError, }, system_calls::{ - apply_beacon_root_contract_call, apply_consolidation_requests_contract_call, - apply_withdrawal_requests_contract_call, + apply_beacon_root_contract_call, apply_blockhashes_contract_call, + apply_consolidation_requests_contract_call, apply_withdrawal_requests_contract_call, }, ConfigureEvm, }; @@ -24,10 +24,8 @@ use reth_primitives::{ }; use reth_prune_types::PruneModes; use reth_revm::{ - batch::BlockBatchRecord, - db::states::bundle_state::BundleRetention, - state_change::{apply_blockhashes_update, post_block_balance_increments}, - Evm, State, + batch::BlockBatchRecord, db::states::bundle_state::BundleRetention, + state_change::post_block_balance_increments, Evm, State, }; use revm_primitives::{ db::{Database, DatabaseCommit}, @@ -156,12 +154,13 @@ where block.parent_beacon_block_root, &mut evm, )?; - apply_blockhashes_update( - evm.db_mut(), + apply_blockhashes_contract_call( + &self.evm_config, &self.chain_spec, block.timestamp, block.number, block.parent_hash, + &mut evm, )?; // execute transactions diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index e853cb1ad12c..ca1029f7d81b 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -17,6 +17,7 @@ use reth_errors::RethError; use reth_evm::{ system_calls::{ post_block_withdrawal_requests_contract_call, pre_block_beacon_root_contract_call, + pre_block_blockhashes_contract_call, }, ConfigureEvm, }; @@ -35,7 +36,7 @@ use reth_primitives::{ U256, }; use reth_provider::StateProviderFactory; -use reth_revm::{database::StateProviderDatabase, state_change::apply_blockhashes_update}; +use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::{BestTransactionsAttributes, TransactionPool}; use revm::{ db::states::bundle_state::BundleRetention, @@ -137,13 +138,17 @@ where })?; // apply eip-2935 blockhashes update - apply_blockhashes_update( + pre_block_blockhashes_contract_call( &mut db, + &self.evm_config, &chain_spec, - initialized_block_env.timestamp.to::(), + &initialized_cfg, + &initialized_block_env, block_number, + attributes.timestamp, parent_block.hash(), - ).map_err(|err| { + ) + .map_err(|err| { warn!(target: "payload_builder", parent_hash=%parent_block.hash(), %err, "failed to update blockhashes for empty payload"); PayloadBuilderError::Internal(err.into()) })?; @@ -316,14 +321,20 @@ where })?; // apply eip-2935 blockhashes update - apply_blockhashes_update( + pre_block_blockhashes_contract_call( &mut db, + &evm_config, &chain_spec, - initialized_block_env.timestamp.to::(), + &initialized_cfg, + &initialized_block_env, block_number, + attributes.timestamp, parent_block.hash(), ) - .map_err(|err| PayloadBuilderError::Internal(err.into()))?; + .map_err(|err| { + warn!(target: "payload_builder", parent_hash=%parent_block.hash(), %err, "failed to update blockhashes for empty payload"); + PayloadBuilderError::Internal(err.into()) + })?; let mut receipts = Vec::new(); while let Some(pool_tx) = best_txs.next() { diff --git a/crates/evm/execution-errors/src/lib.rs b/crates/evm/execution-errors/src/lib.rs index 2a8cb50bf401..1c3c8fa4d091 100644 --- a/crates/evm/execution-errors/src/lib.rs +++ b/crates/evm/execution-errors/src/lib.rs @@ -90,10 +90,14 @@ pub enum BlockValidationError { /// The error message. message: String, }, - /// Provider error during the [EIP-2935] block hash account loading. + /// EVM error during [EIP-2935] blockhash contract call. /// /// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935 - BlockHashAccountLoadingFailed(ProviderError), + #[display("failed to apply blockhash contract call: {message}")] + BlockHashContractCall { + /// The error message. + message: String, + }, /// EVM error during withdrawal requests contract call [EIP-7002] /// /// [EIP-7002]: https://eips.ethereum.org/EIPS/eip-7002 diff --git a/crates/evm/src/system_calls.rs b/crates/evm/src/system_calls.rs index 142a763abcce..5fdb65cc8eb2 100644 --- a/crates/evm/src/system_calls.rs +++ b/crates/evm/src/system_calls.rs @@ -10,6 +10,7 @@ use { use crate::ConfigureEvm; use alloy_eips::{ + eip2935::HISTORY_STORAGE_ADDRESS, eip4788::BEACON_ROOTS_ADDRESS, eip7002::{WithdrawalRequest, WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS}, eip7251::{ConsolidationRequest, CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS}, @@ -23,9 +24,113 @@ use revm_primitives::{ ResultAndState, B256, }; +/// Apply the [EIP-2935](https://eips.ethereum.org/EIPS/eip-2935) pre block contract call. +/// +/// This constructs a new [`Evm`] with the given database and environment ([`CfgEnvWithHandlerCfg`] +/// and [`BlockEnv`]) to execute the pre block contract call. +/// +/// This uses [`apply_blockhashes_contract_call`] to ultimately apply the blockhash contract state +/// change. +#[allow(clippy::too_many_arguments)] +pub fn pre_block_blockhashes_contract_call( + db: &mut DB, + evm_config: &EvmConfig, + chain_spec: &ChainSpec, + initialized_cfg: &CfgEnvWithHandlerCfg, + initialized_block_env: &BlockEnv, + block_number: u64, + block_timestamp: u64, + parent_block_hash: B256, +) -> Result<(), BlockExecutionError> +where + DB: Database + DatabaseCommit, + DB::Error: Display, + EvmConfig: ConfigureEvm, +{ + // Apply the pre-block EIP-2935 contract call + let mut evm_pre_block = Evm::builder() + .with_db(db) + .with_env_with_handler_cfg(EnvWithHandlerCfg::new_with_cfg_env( + initialized_cfg.clone(), + initialized_block_env.clone(), + Default::default(), + )) + .build(); + + apply_blockhashes_contract_call( + evm_config, + chain_spec, + block_timestamp, + block_number, + parent_block_hash, + &mut evm_pre_block, + ) +} + +/// Applies the pre-block call to the [EIP-2935] blockhashes contract, using the given block, +/// [`ChainSpec`], and EVM. +/// +/// If Prague is not activated, or the block is the genesis block, then this is a no-op, and no +/// state changes are made. +/// +/// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935 +#[inline] +pub fn apply_blockhashes_contract_call( + evm_config: &EvmConfig, + chain_spec: &ChainSpec, + block_timestamp: u64, + block_number: u64, + parent_block_hash: B256, + evm: &mut Evm<'_, EXT, DB>, +) -> Result<(), BlockExecutionError> +where + DB: Database + DatabaseCommit, + DB::Error: core::fmt::Display, + EvmConfig: ConfigureEvm, +{ + if !chain_spec.is_prague_active_at_timestamp(block_timestamp) { + return Ok(()) + } + + // if the block number is zero (genesis block) then no system transaction may occur as per + // EIP-2935 + if block_number == 0 { + return Ok(()) + } + + // get previous env + let previous_env = Box::new(evm.context.env().clone()); + + // modify env for pre block call + evm_config.fill_tx_env_system_contract_call( + &mut evm.context.evm.env, + alloy_eips::eip4788::SYSTEM_ADDRESS, + HISTORY_STORAGE_ADDRESS, + parent_block_hash.0.into(), + ); + + let mut state = match evm.transact() { + Ok(res) => res.state, + Err(e) => { + evm.context.evm.env = previous_env; + return Err(BlockValidationError::BlockHashContractCall { message: e.to_string() }.into()) + } + }; + + state.remove(&alloy_eips::eip4788::SYSTEM_ADDRESS); + state.remove(&evm.block().coinbase); + + evm.context.evm.db.commit(state); + + // re-set the previous env + evm.context.evm.env = previous_env; + + Ok(()) +} + /// Apply the [EIP-4788](https://eips.ethereum.org/EIPS/eip-4788) pre block contract call. /// -/// This constructs a new [Evm] with the given DB, and environment +/// This constructs a new [`Evm`] with the given DB, and environment /// ([`CfgEnvWithHandlerCfg`] and [`BlockEnv`]) to execute the pre block contract call. /// /// This uses [`apply_beacon_root_contract_call`] to ultimately apply the beacon root contract state diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 8dd8ba397a36..b25417229318 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -25,9 +25,6 @@ reth-trie = { workspace = true, optional = true } # revm revm.workspace = true -# alloy -alloy-eips.workspace = true - [dev-dependencies] reth-trie.workspace = true reth-ethereum-forks.workspace = true diff --git a/crates/revm/src/state_change.rs b/crates/revm/src/state_change.rs index b8bd293de030..5dddb9b8665e 100644 --- a/crates/revm/src/state_change.rs +++ b/crates/revm/src/state_change.rs @@ -1,14 +1,7 @@ use crate::precompile::HashMap; -use alloy_eips::eip2935::{HISTORY_STORAGE_ADDRESS, HISTORY_STORAGE_CODE}; use reth_chainspec::{ChainSpec, EthereumHardforks}; use reth_consensus_common::calc; -use reth_execution_errors::{BlockExecutionError, BlockValidationError}; -use reth_primitives::{Address, Block, Withdrawal, Withdrawals, B256, U256}; -use reth_storage_errors::provider::ProviderError; -use revm::{ - primitives::{Account, AccountInfo, Bytecode, EvmStorageSlot, BLOCKHASH_SERVE_WINDOW}, - Database, DatabaseCommit, -}; +use reth_primitives::{Address, Block, Withdrawal, Withdrawals, U256}; /// Collect all balance changes at the end of the block. /// @@ -48,75 +41,6 @@ pub fn post_block_balance_increments( balance_increments } -/// Applies the pre-block state change outlined in [EIP-2935] to store historical blockhashes in a -/// system contract. -/// -/// If Prague is not activated, or the block is the genesis block, then this is a no-op, and no -/// state changes are made. -/// -/// If the provided block is after Prague has been activated, the parent hash will be inserted. -/// -/// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935 -#[inline] -pub fn apply_blockhashes_update> + DatabaseCommit>( - db: &mut DB, - chain_spec: &ChainSpec, - block_timestamp: u64, - block_number: u64, - parent_block_hash: B256, -) -> Result<(), BlockExecutionError> -where - DB::Error: core::fmt::Display, -{ - // If Prague is not activated or this is the genesis block, no hashes are added. - if !chain_spec.is_prague_active_at_timestamp(block_timestamp) || block_number == 0 { - return Ok(()) - } - assert!(block_number > 0); - - // Account is expected to exist either in genesis (for tests) or deployed on mainnet or - // testnets. - // If the account for any reason does not exist, we create it with the EIP-2935 bytecode and a - // nonce of 1, so it does not get deleted. - let mut account: Account = db - .basic(HISTORY_STORAGE_ADDRESS) - .map_err(|err| BlockValidationError::BlockHashAccountLoadingFailed(err.into()))? - .unwrap_or_else(|| AccountInfo { - nonce: 1, - code: Some(Bytecode::new_raw(HISTORY_STORAGE_CODE.clone())), - ..Default::default() - }) - .into(); - - // Insert the state change for the slot - let (slot, value) = eip2935_block_hash_slot(db, block_number - 1, parent_block_hash)?; - account.storage.insert(slot, value); - - // Mark the account as touched and commit the state change - account.mark_touch(); - db.commit(HashMap::from([(HISTORY_STORAGE_ADDRESS, account)])); - - Ok(()) -} - -/// Helper function to create a [`EvmStorageSlot`] for [EIP-2935] state transitions for a given -/// block number. -/// -/// This calculates the correct storage slot in the `BLOCKHASH` history storage address, fetches the -/// blockhash and creates a [`EvmStorageSlot`] with appropriate previous and new values. -fn eip2935_block_hash_slot>>( - db: &mut DB, - block_number: u64, - block_hash: B256, -) -> Result<(U256, EvmStorageSlot), BlockValidationError> { - let slot = U256::from(block_number % BLOCKHASH_SERVE_WINDOW as u64); - let current_hash = db - .storage(HISTORY_STORAGE_ADDRESS, slot) - .map_err(|err| BlockValidationError::BlockHashAccountLoadingFailed(err.into()))?; - - Ok((slot, EvmStorageSlot::new_changed(current_hash, block_hash.into()))) -} - /// Returns a map of addresses to their balance increments if the Shanghai hardfork is active at the /// given timestamp. /// diff --git a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs index a473267924a1..3fb0ecd1c6a4 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs @@ -5,7 +5,10 @@ use std::time::{Duration, Instant}; use futures::Future; use reth_chainspec::{ChainSpec, EthereumHardforks}; -use reth_evm::{system_calls::pre_block_beacon_root_contract_call, ConfigureEvm, ConfigureEvmEnv}; +use reth_evm::{ + system_calls::{pre_block_beacon_root_contract_call, pre_block_blockhashes_contract_call}, + ConfigureEvm, ConfigureEvmEnv, +}; use reth_execution_types::ExecutionOutcome; use reth_primitives::{ constants::{eip4844::MAX_DATA_GAS_PER_BLOCK, BEACON_NONCE, EMPTY_ROOT_HASH}, @@ -25,10 +28,7 @@ use reth_provider::{ use reth_revm::{ database::StateProviderDatabase, state_change::post_block_withdrawals_balance_increments, }; -use reth_rpc_eth_types::{ - pending_block::pre_block_blockhashes_update, EthApiError, PendingBlock, PendingBlockEnv, - PendingBlockEnvOrigin, -}; +use reth_rpc_eth_types::{EthApiError, PendingBlock, PendingBlockEnv, PendingBlockEnvOrigin}; use reth_transaction_pool::{BestTransactionsAttributes, TransactionPool}; use revm::{db::states::bundle_state::BundleRetention, DatabaseCommit, State}; use tokio::sync::Mutex; @@ -262,13 +262,17 @@ pub trait LoadPendingBlock: EthApiTypes { } else { None }; - pre_block_blockhashes_update( + pre_block_blockhashes_contract_call( &mut db, + self.evm_config(), chain_spec.as_ref(), + &cfg, &block_env, block_number, - parent_hash, - )?; + block_env.timestamp.to::(), + origin.header().hash(), + ) + .map_err(|err| EthApiError::Internal(err.into()))?; let mut receipts = Vec::new(); diff --git a/crates/rpc/rpc-eth-types/src/pending_block.rs b/crates/rpc/rpc-eth-types/src/pending_block.rs index db1dfab933c0..eaa6bb3d7ffc 100644 --- a/crates/rpc/rpc-eth-types/src/pending_block.rs +++ b/crates/rpc/rpc-eth-types/src/pending_block.rs @@ -2,19 +2,11 @@ //! //! Types used in block building. -use std::{fmt, time::Instant}; +use std::time::Instant; use derive_more::Constructor; -use reth_chainspec::ChainSpec; use reth_primitives::{BlockId, BlockNumberOrTag, SealedBlockWithSenders, SealedHeader, B256}; -use reth_revm::state_change::apply_blockhashes_update; -use reth_storage_api::errors::provider::ProviderError; -use revm_primitives::{ - db::{Database, DatabaseCommit}, - BlockEnv, CfgEnvWithHandlerCfg, -}; - -use super::{EthApiError, EthResult}; +use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg}; /// Configured [`BlockEnv`] and [`CfgEnvWithHandlerCfg`] for a pending block #[derive(Debug, Clone, Constructor)] @@ -27,32 +19,6 @@ pub struct PendingBlockEnv { pub origin: PendingBlockEnvOrigin, } -/// Apply the [EIP-2935](https://eips.ethereum.org/EIPS/eip-2935) pre block state transitions. -/// -/// This constructs a new [Evm](revm::Evm) with the given DB, and environment -/// [`CfgEnvWithHandlerCfg`] and [`BlockEnv`]. -/// -/// This uses [`apply_blockhashes_update`]. -pub fn pre_block_blockhashes_update + DatabaseCommit>( - db: &mut DB, - chain_spec: &ChainSpec, - initialized_block_env: &BlockEnv, - block_number: u64, - parent_block_hash: B256, -) -> EthResult<()> -where - DB::Error: fmt::Display, -{ - apply_blockhashes_update( - db, - chain_spec, - initialized_block_env.timestamp.to::(), - block_number, - parent_block_hash, - ) - .map_err(|err| EthApiError::Internal(err.into())) -} - /// The origin for a configured [`PendingBlockEnv`] #[derive(Clone, Debug)] pub enum PendingBlockEnvOrigin { diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index b259f1fd1fbb..938738eeb8b9 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -2,7 +2,10 @@ use alloy_rlp::{Decodable, Encodable}; use async_trait::async_trait; use jsonrpsee::core::RpcResult; use reth_chainspec::{ChainSpec, EthereumHardforks}; -use reth_evm::{system_calls::pre_block_beacon_root_contract_call, ConfigureEvmEnv}; +use reth_evm::{ + system_calls::{pre_block_beacon_root_contract_call, pre_block_blockhashes_contract_call}, + ConfigureEvmEnv, +}; use reth_primitives::{ Address, Block, BlockId, BlockNumberOrTag, Bytes, TransactionSignedEcRecovered, B256, U256, }; @@ -10,7 +13,7 @@ use reth_provider::{ BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, HeaderProvider, StateProofProvider, StateProviderFactory, TransactionVariant, }; -use reth_revm::{database::StateProviderDatabase, state_change::apply_blockhashes_update}; +use reth_revm::database::StateProviderDatabase; use reth_rpc_api::DebugApiServer; use reth_rpc_eth_api::{ helpers::{Call, EthApiSpec, EthTransactions, TraceExt}, @@ -595,9 +598,12 @@ where .map_err(|err| EthApiError::Internal(err.into()))?; // apply eip-2935 blockhashes update - apply_blockhashes_update( + pre_block_blockhashes_contract_call( &mut db, + &evm_config, &this.inner.provider.chain_spec(), + &cfg, + &block_env, block.timestamp, block.number, block.parent_hash, From 6bcb9f0f848473f0d1ea34976fec4af181f1d8c4 Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Mon, 26 Aug 2024 13:06:56 +0200 Subject: [PATCH 2/3] refactor: get block number and timestamp from blockenv --- crates/ethereum/payload/src/lib.rs | 9 --------- crates/evm/src/system_calls.rs | 14 ++++---------- crates/optimism/payload/src/builder.rs | 5 ----- .../rpc/rpc-eth-api/src/helpers/pending_block.rs | 4 ---- crates/rpc/rpc/src/debug.rs | 4 ---- 5 files changed, 4 insertions(+), 32 deletions(-) diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index ca1029f7d81b..02442d73067b 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -113,7 +113,6 @@ where .build(); let base_fee = initialized_block_env.basefee.to::(); - let block_number = initialized_block_env.number.to::(); let block_gas_limit = initialized_block_env.gas_limit.try_into().unwrap_or(chain_spec.max_gas_limit); @@ -124,8 +123,6 @@ where &chain_spec, &initialized_cfg, &initialized_block_env, - block_number, - attributes.timestamp, attributes.parent_beacon_block_root, ) .map_err(|err| { @@ -144,8 +141,6 @@ where &chain_spec, &initialized_cfg, &initialized_block_env, - block_number, - attributes.timestamp, parent_block.hash(), ) .map_err(|err| { @@ -307,8 +302,6 @@ where &chain_spec, &initialized_cfg, &initialized_block_env, - block_number, - attributes.timestamp, attributes.parent_beacon_block_root, ) .map_err(|err| { @@ -327,8 +320,6 @@ where &chain_spec, &initialized_cfg, &initialized_block_env, - block_number, - attributes.timestamp, parent_block.hash(), ) .map_err(|err| { diff --git a/crates/evm/src/system_calls.rs b/crates/evm/src/system_calls.rs index 5fdb65cc8eb2..530ed3cfafa1 100644 --- a/crates/evm/src/system_calls.rs +++ b/crates/evm/src/system_calls.rs @@ -31,15 +31,12 @@ use revm_primitives::{ /// /// This uses [`apply_blockhashes_contract_call`] to ultimately apply the blockhash contract state /// change. -#[allow(clippy::too_many_arguments)] pub fn pre_block_blockhashes_contract_call( db: &mut DB, evm_config: &EvmConfig, chain_spec: &ChainSpec, initialized_cfg: &CfgEnvWithHandlerCfg, initialized_block_env: &BlockEnv, - block_number: u64, - block_timestamp: u64, parent_block_hash: B256, ) -> Result<(), BlockExecutionError> where @@ -60,8 +57,8 @@ where apply_blockhashes_contract_call( evm_config, chain_spec, - block_timestamp, - block_number, + initialized_block_env.timestamp.to(), + initialized_block_env.number.to(), parent_block_hash, &mut evm_pre_block, ) @@ -135,15 +132,12 @@ where /// /// This uses [`apply_beacon_root_contract_call`] to ultimately apply the beacon root contract state /// change. -#[allow(clippy::too_many_arguments)] pub fn pre_block_beacon_root_contract_call( db: &mut DB, evm_config: &EvmConfig, chain_spec: &ChainSpec, initialized_cfg: &CfgEnvWithHandlerCfg, initialized_block_env: &BlockEnv, - block_number: u64, - block_timestamp: u64, parent_beacon_block_root: Option, ) -> Result<(), BlockExecutionError> where @@ -165,8 +159,8 @@ where apply_beacon_root_contract_call( evm_config, chain_spec, - block_timestamp, - block_number, + initialized_block_env.timestamp.to(), + initialized_block_env.number.to(), parent_beacon_block_root, &mut evm_pre_block, ) diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 7ae7d107baa8..d190a7e77855 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -113,7 +113,6 @@ where .build(); let base_fee = initialized_block_env.basefee.to::(); - let block_number = initialized_block_env.number.to::(); let block_gas_limit: u64 = initialized_block_env.gas_limit.try_into().unwrap_or(chain_spec.max_gas_limit); @@ -124,8 +123,6 @@ where &chain_spec, &initialized_cfg, &initialized_block_env, - block_number, - attributes.payload_attributes.timestamp, attributes.payload_attributes.parent_beacon_block_root, ) .map_err(|err| { @@ -289,8 +286,6 @@ where &chain_spec, &initialized_cfg, &initialized_block_env, - block_number, - attributes.payload_attributes.timestamp, attributes.payload_attributes.parent_beacon_block_root, ) .map_err(|err| { diff --git a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs index 3fb0ecd1c6a4..876b5b776317 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/pending_block.rs @@ -253,8 +253,6 @@ pub trait LoadPendingBlock: EthApiTypes { chain_spec.as_ref(), &cfg, &block_env, - block_number, - block_env.timestamp.to::(), origin.header().parent_beacon_block_root, ) .map_err(|err| EthApiError::Internal(err.into()))?; @@ -268,8 +266,6 @@ pub trait LoadPendingBlock: EthApiTypes { chain_spec.as_ref(), &cfg, &block_env, - block_number, - block_env.timestamp.to::(), origin.header().hash(), ) .map_err(|err| EthApiError::Internal(err.into()))?; diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 938738eeb8b9..8108a82c8b12 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -591,8 +591,6 @@ where &this.inner.provider.chain_spec(), &cfg, &block_env, - block.timestamp, - block.number, block.parent_beacon_block_root, ) .map_err(|err| EthApiError::Internal(err.into()))?; @@ -604,8 +602,6 @@ where &this.inner.provider.chain_spec(), &cfg, &block_env, - block.timestamp, - block.number, block.parent_hash, ) .map_err(|err| EthApiError::Internal(err.into()))?; From 1dafc0e3ce8bf40cc8b97c1b74439f93b850ce98 Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Mon, 26 Aug 2024 13:31:35 +0200 Subject: [PATCH 3/3] test: set eip2935 contract code for tests --- crates/ethereum/evm/src/execute.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 88b9f032cefa..8c15dee96006 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -466,7 +466,7 @@ where mod tests { use super::*; use alloy_eips::{ - eip2935::HISTORY_STORAGE_ADDRESS, + eip2935::{HISTORY_STORAGE_ADDRESS, HISTORY_STORAGE_CODE}, eip4788::{BEACON_ROOTS_ADDRESS, BEACON_ROOTS_CODE, SYSTEM_ADDRESS}, eip7002::{WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, WITHDRAWAL_REQUEST_PREDEPLOY_CODE}, }; @@ -867,11 +867,26 @@ mod tests { assert_eq!(parent_beacon_block_root_storage, U256::from(0x69)); } + /// Create a state provider with blockhashes and the EIP-2935 system contract. fn create_state_provider_with_block_hashes(latest_block: u64) -> StateProviderTest { let mut db = StateProviderTest::default(); for block_number in 0..=latest_block { db.insert_block_hash(block_number, keccak256(block_number.to_string())); } + + let blockhashes_contract_account = Account { + balance: U256::ZERO, + bytecode_hash: Some(keccak256(HISTORY_STORAGE_CODE.clone())), + nonce: 1, + }; + + db.insert_account( + HISTORY_STORAGE_ADDRESS, + blockhashes_contract_account, + Some(HISTORY_STORAGE_CODE.clone()), + HashMap::new(), + ); + db } @@ -917,9 +932,9 @@ mod tests { // ensure that the block hash was *not* written to storage, since this is before the fork // was activated // - // we load the account first, which should also not exist, because revm expects it to be + // we load the account first, because revm expects it to be // loaded - assert!(executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap().is_none()); + executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap(); assert!(executor .state_mut() .storage(HISTORY_STORAGE_ADDRESS, U256::ZERO) @@ -967,9 +982,9 @@ mod tests { // ensure that the block hash was *not* written to storage, since there are no blocks // preceding genesis // - // we load the account first, which should also not exist, because revm expects it to be + // we load the account first, because revm expects it to be // loaded - assert!(executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap().is_none()); + executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap(); assert!(executor .state_mut() .storage(HISTORY_STORAGE_ADDRESS, U256::ZERO) @@ -1139,7 +1154,10 @@ mod tests { ); // nothing should be written as the genesis has no ancestors - assert!(executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap().is_none()); + // + // we load the account first, because revm expects it to be + // loaded + executor.state_mut().basic(HISTORY_STORAGE_ADDRESS).unwrap(); assert!(executor .state_mut() .storage(HISTORY_STORAGE_ADDRESS, U256::ZERO)