Skip to content

Commit

Permalink
feat: remove code_size access in Host trait
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 committed Jan 11, 2025
1 parent 5cdeaba commit 73610d7
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 35 deletions.
4 changes: 0 additions & 4 deletions crates/interpreter/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ pub trait Host {
/// Get code hash of `address` and if the account is cold.
fn code_hash(&mut self, address: Address) -> Option<StateLoad<B256>>;

#[cfg(feature = "scroll")]
/// Get code size of `address` and if the account is cold.
fn code_size(&mut self, address: Address) -> Option<(usize, bool)>;

/// Get storage value of `address` at `index` and if the account is cold.
fn sload(&mut self, address: Address, index: U256) -> Option<StateLoad<U256>>;

Expand Down
6 changes: 0 additions & 6 deletions crates/interpreter/src/host/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ impl Host for DummyHost {
Some(Default::default())
}

#[inline]
#[cfg(feature = "scroll")]
fn code_size(&mut self, _address: Address) -> Option<(usize, bool)> {
Some((0, false))
}

#[inline]
fn code_hash(&mut self, _address: Address) -> Option<StateLoad<B256>> {
Some(StateLoad::new(KECCAK_EMPTY, false))
Expand Down
21 changes: 4 additions & 17 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ pub fn selfbalance<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
push!(interpreter, balance.data);
}

#[cfg(not(feature = "scroll"))]
pub fn extcodesize<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
pop_address!(interpreter, address);
let Some(code) = host.code(address) else {
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};
#[cfg(feature = "scroll")]
if code.is_cold && host.is_address_in_access_list(interpreter.contract.target_address) {
panic!("access list account should be either loaded or never accessed");
}
if SPEC::enabled(BERLIN) {
gas!(interpreter, warm_cold_cost(code.is_cold));
} else if SPEC::enabled(TANGERINE) {
Expand All @@ -62,22 +65,6 @@ pub fn extcodesize<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
push!(interpreter, U256::from(code.len()));
}

#[cfg(feature = "scroll")]
pub fn extcodesize<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
pop_address!(interpreter, address);
let Some((code_size, is_cold)) = host.code_size(address) else {
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};
#[cfg(feature = "scroll")]
if is_cold && host.is_address_in_access_list(interpreter.contract.target_address) {
panic!("access list account should be either loaded or never accessed");
}
gas!(interpreter, warm_cold_cost(is_cold));

push!(interpreter, U256::from(code_size));
}

/// EIP-1052: EXTCODEHASH opcode
pub fn extcodehash<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
check!(interpreter, CONSTANTINOPLE);
Expand Down
8 changes: 0 additions & 8 deletions crates/revm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,6 @@ impl<EXT, DB: Database> Host for Context<EXT, DB> {
.ok()
}

#[cfg(feature = "scroll")]
fn code_size(&mut self, address: Address) -> Option<(usize, bool)> {
self.evm
.code_size(address)
.map_err(|e| self.evm.error = Err(e))
.ok()
}

fn code_hash(&mut self, address: Address) -> Option<StateLoad<B256>> {
self.evm
.code_hash(address)
Expand Down

0 comments on commit 73610d7

Please sign in to comment.