diff --git a/crates/primitives/src/constants.rs b/crates/primitives/src/constants.rs index c8223300bf..a53c87b220 100644 --- a/crates/primitives/src/constants.rs +++ b/crates/primitives/src/constants.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{address, Address}; +use alloy_primitives::{address, hex, Address}; /// EIP-170: Contract code size limit /// @@ -60,3 +60,7 @@ pub const BLOB_GASPRICE_UPDATE_FRACTION: u64 = 3338477; /// First version of the blob. pub const VERSIONED_HASH_VERSION_KZG: u8 = 0x01; + +/// Precomputed hash for EOF bytecode used with the EXTCODEHASH opcode for EOF contracts. +pub const EOF_BYTECODE_HASH: &[u8] = + &hex!("9dbf3648db8210552e9c4f75c6a1c3057c0ca432043bd648be15fe7be05646f5"); diff --git a/crates/revm/src/context.rs b/crates/revm/src/context.rs index 40107651cb..733107c23f 100644 --- a/crates/revm/src/context.rs +++ b/crates/revm/src/context.rs @@ -13,7 +13,9 @@ use revm_interpreter::as_usize_saturated; use crate::{ db::{Database, EmptyDB}, interpreter::{Host, LoadAccountResult, SStoreResult, SelfDestructResult}, - primitives::{Address, Bytecode, Env, HandlerCfg, Log, B256, BLOCK_HASH_HISTORY, U256}, + primitives::{ + Address, Bytecode, Env, HandlerCfg, Log, B256, BLOCK_HASH_HISTORY, EOF_BYTECODE_HASH, U256, + }, }; use std::boxed::Box; @@ -154,10 +156,19 @@ impl Host for Context { } fn code_hash(&mut self, address: Address) -> Option<(B256, bool)> { - self.evm + let code_hash = self + .evm .code_hash(address) .map_err(|e| self.evm.error = Err(e)) - .ok() + .ok(); + + if let Some((bytecode, is_cold)) = self.code(address) { + if bytecode.is_eof() { + return Some((B256::from_slice(EOF_BYTECODE_HASH), is_cold)); + } + } + + code_hash } fn sload(&mut self, address: Address, index: U256) -> Option<(U256, bool)> {