Skip to content

Commit

Permalink
feat: EXTCODEHASH load bytecode and check if it is EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgonzalezra committed Jun 8, 2024
1 parent 561fbdb commit 047f54a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
Host, InstructionResult, SStoreResult,
};
use core::cmp::min;
use revm_primitives::EOF_BYTECODE_HASH;
use std::vec::Vec;

pub fn balance<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
Expand Down Expand Up @@ -61,7 +62,7 @@ pub fn extcodesize<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
pub fn extcodehash<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
check!(interpreter, CONSTANTINOPLE);
pop_address!(interpreter, address);
let Some((code_hash, is_cold)) = host.code_hash(address) else {
let Some((mut code_hash, is_cold)) = host.code_hash(address) else {
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};
Expand All @@ -72,6 +73,12 @@ pub fn extcodehash<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
} else {
gas!(interpreter, 400);
}
if let Some((bytecode, _)) = host.code(address) {
// TODO: Once issue https://github.com/bluealloy/revm/issues/1464 is resolved, update this logic to use the new method for detecting if the bytecode is EOF.
if bytecode.bytes().starts_with(&[0xEF, 0x00]) {
code_hash = B256::from_slice(&EOF_BYTECODE_HASH);
}
}
push_b256!(interpreter, code_hash);
}

Expand Down
5 changes: 5 additions & 0 deletions crates/primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ pub const BLOB_GASPRICE_UPDATE_FRACTION: u64 = 3338477;

/// First version of the blob.
pub const VERSIONED_HASH_VERSION_KZG: u8 = 0x01;

pub const EOF_BYTECODE_HASH: &[u8] = &[
0x9d, 0xbf, 0x36, 0x48, 0xdb, 0x82, 0x10, 0x55, 0x2e, 0x9c, 0x4f, 0x75, 0xc6, 0xa1, 0xc3, 0x05,
0x7c, 0x0c, 0xa4, 0x32, 0x04, 0x3b, 0xd6, 0x48, 0xbe, 0x15, 0xfe, 0x7b, 0xe0, 0x56, 0x46, 0xf5,
];

0 comments on commit 047f54a

Please sign in to comment.