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 all commits
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
6 changes: 5 additions & 1 deletion crates/primitives/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::{address, Address};
use alloy_primitives::{address, hex, Address};

/// EIP-170: Contract code size limit
///
Expand Down Expand Up @@ -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");
17 changes: 14 additions & 3 deletions crates/revm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -154,10 +156,19 @@ impl<EXT, DB: Database> Host for Context<EXT, DB> {
}

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() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rakita What do you think about doing this instead of checking the first byte?

Copy link
Member

Choose a reason for hiding this comment

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

This is fine, as only EOF 0xEFXX is 0xEF00

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the clarification

return Some((B256::from_slice(EOF_BYTECODE_HASH), is_cold));
}
}

code_hash
}

fn sload(&mut self, address: Address, index: U256) -> Option<(U256, bool)> {
Expand Down
Loading