Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: EXTCODEHASH load bytecode and check if it is EOF #1501

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 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,13 @@ pub fn extcodehash<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
} else {
gas!(interpreter, 400);
}
if let Some((bytecode, _)) = host.code(address) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to go where Host is implemented here:

fn code_hash(&mut self, address: Address) -> Option<(B256, bool)> {

host.code_hash needs to return whatever is needed for instruction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, let me do it 💪

// 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
6 changes: 6 additions & 0 deletions crates/primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ 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] = &[
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,
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use &hex!("..") here, it is more readable

Loading