From f07c0ef1c27d7a7a6b160849f4f2c88dcd843cfe Mon Sep 17 00:00:00 2001 From: rakita Date: Thu, 16 May 2024 16:47:41 +0300 Subject: [PATCH] Revert "feat: implement EIP-2935 (#1354)" (#1424) * Revert "feat: implement EIP-2935 (#1354)" This reverts commit 3e089f35ed2a98278ddbae8f5dd816ccc373fa31. * dont revert some commend changes * Revert "fix(eip2935): Preload blockchash storage address (#1395)" This reverts commit aeefcda7fa124a8695228e5b8ab4118083f80a03. --- crates/interpreter/src/instructions/host.rs | 38 +++++-------------- crates/interpreter/src/opcode.rs | 2 +- crates/primitives/src/constants.rs | 31 +++------------ .../revm/src/handler/mainnet/pre_execution.rs | 14 +------ 4 files changed, 19 insertions(+), 66 deletions(-) diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index eea5dc20a5..bad571de35 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -5,7 +5,7 @@ use crate::{ Host, InstructionResult, SStoreResult, }; use core::cmp::min; -use revm_primitives::{BLOCKHASH_SERVE_WINDOW, BLOCKHASH_STORAGE_ADDRESS, BLOCK_HASH_HISTORY}; +use revm_primitives::BLOCK_HASH_HISTORY; use std::vec::Vec; pub fn balance(interpreter: &mut Interpreter, host: &mut H) { @@ -103,40 +103,22 @@ pub fn extcodecopy(interpreter: &mut Interpreter, .set_data(memory_offset, code_offset, len, &code.original_bytes()); } -pub fn blockhash(interpreter: &mut Interpreter, host: &mut H) { +pub fn blockhash(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BLOCKHASH); pop_top!(interpreter, number); - let block_number = host.env().block.number; - - match block_number.checked_sub(*number) { + if let Some(diff) = host.env().block.number.checked_sub(*number) { + let diff = as_usize_saturated!(diff); // blockhash should push zero if number is same as current block number. - Some(diff) if !diff.is_zero() => { - let diff = as_usize_saturated!(diff); - - if SPEC::enabled(PRAGUE) && diff <= BLOCKHASH_SERVE_WINDOW { - let index = number.wrapping_rem(U256::from(BLOCKHASH_SERVE_WINDOW)); - let Some((value, _)) = host.sload(BLOCKHASH_STORAGE_ADDRESS, index) else { - interpreter.instruction_result = InstructionResult::FatalExternalError; - return; - }; - *number = value; - return; - } else if diff <= BLOCK_HASH_HISTORY { - let Some(hash) = host.block_hash(*number) else { - interpreter.instruction_result = InstructionResult::FatalExternalError; - return; - }; - *number = U256::from_be_bytes(hash.0); + if diff <= BLOCK_HASH_HISTORY && diff != 0 { + let Some(hash) = host.block_hash(*number) else { + interpreter.instruction_result = InstructionResult::FatalExternalError; return; - } - } - _ => { - // If blockhash is requested for the current block, the hash should be 0, so we fall - // through. + }; + *number = U256::from_be_bytes(hash.0); + return; } } - *number = U256::ZERO; } diff --git a/crates/interpreter/src/opcode.rs b/crates/interpreter/src/opcode.rs index b5b6ffd17c..672d1ecd92 100644 --- a/crates/interpreter/src/opcode.rs +++ b/crates/interpreter/src/opcode.rs @@ -604,7 +604,7 @@ opcodes! { 0x3D => RETURNDATASIZE => system::returndatasize:: => stack_io(0, 1); 0x3E => RETURNDATACOPY => system::returndatacopy:: => stack_io(3, 0); 0x3F => EXTCODEHASH => host::extcodehash:: => stack_io(1, 1), not_eof; - 0x40 => BLOCKHASH => host::blockhash:: => stack_io(1, 1); + 0x40 => BLOCKHASH => host::blockhash => stack_io(1, 1); 0x41 => COINBASE => host_env::coinbase => stack_io(0, 1); 0x42 => TIMESTAMP => host_env::timestamp => stack_io(0, 1); 0x43 => NUMBER => host_env::block_number => stack_io(0, 1); diff --git a/crates/primitives/src/constants.rs b/crates/primitives/src/constants.rs index c8223300bf..1ad219dca9 100644 --- a/crates/primitives/src/constants.rs +++ b/crates/primitives/src/constants.rs @@ -1,41 +1,22 @@ -use alloy_primitives::{address, Address}; +use crate::Address; /// EIP-170: Contract code size limit -/// -/// By default the limit is `0x6000` (~25kb) +/// By default limit is 0x6000 (~25kb) pub const MAX_CODE_SIZE: usize = 0x6000; -/// Number of block hashes that EVM can access in the past (pre-Prague). +/// Number of block hashes that EVM can access in the past pub const BLOCK_HASH_HISTORY: usize = 256; -/// EIP-2935: Serve historical block hashes from state -/// -/// Number of block hashes the EVM can access in the past (Prague). -/// -/// # Note -/// -/// This is named `HISTORY_SERVE_WINDOW` in the EIP. -pub const BLOCKHASH_SERVE_WINDOW: usize = 8192; - -/// EIP-2935: Serve historical block hashes from state -/// -/// The address where historical blockhashes are available. -/// -/// # Note -/// -/// This is named `HISTORY_STORAGE_ADDRESS` in the EIP. -pub const BLOCKHASH_STORAGE_ADDRESS: Address = address!("25a219378dad9b3503c8268c9ca836a52427a4fb"); - /// EIP-3860: Limit and meter initcode /// -/// Limit of maximum initcode size is `2 * MAX_CODE_SIZE`. +/// Limit of maximum initcode size is 2 * MAX_CODE_SIZE pub const MAX_INITCODE_SIZE: usize = 2 * MAX_CODE_SIZE; -/// The address of precompile 3, which is handled specially in a few places. +/// Precompile 3 is special in few places pub const PRECOMPILE3: Address = Address::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3]); -// === EIP-4844 constants === +// --- EIP-4844 constants --- /// Gas consumption of a single data blob (== blob byte size). pub const GAS_PER_BLOB: u64 = 1 << 17; diff --git a/crates/revm/src/handler/mainnet/pre_execution.rs b/crates/revm/src/handler/mainnet/pre_execution.rs index c0f4fe7bde..64b41e7045 100644 --- a/crates/revm/src/handler/mainnet/pre_execution.rs +++ b/crates/revm/src/handler/mainnet/pre_execution.rs @@ -7,8 +7,8 @@ use crate::{ primitives::{ db::Database, Account, EVMError, Env, Spec, - SpecId::{CANCUN, PRAGUE, SHANGHAI}, - TransactTo, BLOCKHASH_STORAGE_ADDRESS, U256, + SpecId::{CANCUN, SHANGHAI}, + TransactTo, U256, }, Context, ContextPrecompiles, }; @@ -39,16 +39,6 @@ pub fn load_accounts( )?; } - // Load blockhash storage address - // EIP-2935: Serve historical block hashes from state - if SPEC::enabled(PRAGUE) { - context.evm.inner.journaled_state.initial_account_load( - BLOCKHASH_STORAGE_ADDRESS, - &[], - &mut context.evm.inner.db, - )?; - } - context.evm.load_access_list()?; Ok(()) }