Skip to content

Commit

Permalink
fix: ignore failures in load_access_list
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing committed Oct 16, 2024
1 parent f7f0745 commit 4562c39
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 8 deletions.
21 changes: 21 additions & 0 deletions crates/interpreter/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ pub trait Host {
/// Returns a mutable reference to the environment.
fn env_mut(&mut self) -> &mut Env;

#[cfg(feature = "scroll")]
/// Check an address is in the access list.
fn is_address_in_access_list(&self, address: Address) -> bool {
self.env()
.tx
.access_list
.iter()
.any(|item| item.address == address)
}

#[cfg(feature = "scroll")]
/// Check a storage key is in the access list.
fn is_storage_key_in_access_list(&self, address: Address, index: U256) -> bool {
self.env()
.tx
.access_list
.iter()
.filter(|item| item.address == address)
.any(|item| item.storage_keys.contains(&B256::from(index)))
}

/// Load an account code.
fn load_account_delegated(&mut self, address: Address) -> Option<AccountLoad>;

Expand Down
19 changes: 18 additions & 1 deletion crates/interpreter/src/instructions/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,15 @@ pub fn call<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &
return;
};

let Some(account_load) = host.load_account_delegated(to) else {
#[allow(unused_mut)]
let Some(mut account_load) = host.load_account_delegated(to) else {
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};
#[cfg(feature = "scroll")]
if account_load.is_cold && host.is_address_in_access_list(interpreter.contract.target_address) {
account_load.is_cold = false;
}
let Some(mut gas_limit) =
calc_call_gas::<SPEC>(interpreter, account_load, has_transfer, local_gas_limit)
else {
Expand Down Expand Up @@ -464,6 +469,10 @@ pub fn call_code<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, ho
};
// set is_empty to false as we are not creating this account.
load.is_empty = false;
#[cfg(feature = "scroll")]
if load.is_cold && host.is_address_in_access_list(interpreter.contract.target_address) {
load.is_cold = false;
}
let Some(mut gas_limit) =
calc_call_gas::<SPEC>(interpreter, load, !value.is_zero(), local_gas_limit)
else {
Expand Down Expand Up @@ -512,6 +521,10 @@ pub fn delegate_call<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter
};
// set is_empty to false as we are not creating this account.
load.is_empty = false;
#[cfg(feature = "scroll")]
if load.is_cold && host.is_address_in_access_list(interpreter.contract.target_address) {
load.is_cold = false;
}
let Some(gas_limit) = calc_call_gas::<SPEC>(interpreter, load, false, local_gas_limit) else {
return;
};
Expand Down Expand Up @@ -553,6 +566,10 @@ pub fn static_call<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
};
// set is_empty to false as we are not creating this account.
load.is_empty = false;
#[cfg(feature = "scroll")]
if load.is_cold && host.is_address_in_access_list(interpreter.contract.target_address) {
load.is_cold = false;
}
let Some(gas_limit) = calc_call_gas::<SPEC>(interpreter, load, false, local_gas_limit) else {
return;
};
Expand Down
43 changes: 38 additions & 5 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ use std::vec::Vec;

pub fn balance<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
pop_address!(interpreter, address);
let Some(balance) = host.balance(address) else {
#[allow(unused_mut)]
let Some(mut balance) = host.balance(address) else {
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};
#[cfg(feature = "scroll")]
if balance.is_cold && host.is_address_in_access_list(interpreter.contract.target_address) {
balance.is_cold = false;
}
gas!(
interpreter,
if SPEC::enabled(BERLIN) {
Expand Down Expand Up @@ -62,10 +67,14 @@ pub fn extcodesize<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
#[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 {
let Some((code_size, mut 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) {
is_cold = false;
}
gas!(interpreter, warm_cold_cost(is_cold));

push!(interpreter, U256::from(code_size));
Expand All @@ -75,10 +84,15 @@ 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) = host.code_hash(address) else {
#[allow(unused_mut)]
let Some(mut code_hash) = host.code_hash(address) else {
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};
#[cfg(feature = "scroll")]
if code_hash.is_cold && host.is_address_in_access_list(interpreter.contract.target_address) {
code_hash.is_cold = false;
}
let (code_hash, load) = code_hash.into_components();
if SPEC::enabled(BERLIN) {
gas!(interpreter, warm_cold_cost_with_delegation(load))
Expand All @@ -94,10 +108,15 @@ pub fn extcodecopy<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter,
pop_address!(interpreter, address);
pop!(interpreter, memory_offset, code_offset, len_u256);

let Some(code) = host.code(address) else {
#[allow(unused_mut)]
let Some(mut 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) {
code.is_cold = false;
}

let len = as_usize_or_fail!(interpreter, len_u256);
let (code, load) = code.into_components();
Expand Down Expand Up @@ -164,10 +183,17 @@ pub fn blockhash<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, ho

pub fn sload<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
pop_top!(interpreter, index);
let Some(value) = host.sload(interpreter.contract.target_address, *index) else {
#[allow(unused_mut)]
let Some(mut value) = host.sload(interpreter.contract.target_address, *index) else {
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};
#[cfg(feature = "scroll")]
if value.is_cold
&& host.is_storage_key_in_access_list(interpreter.contract.target_address, *index)
{
value.is_cold = false;
}
gas!(interpreter, gas::sload_cost(SPEC::SPEC_ID, value.is_cold));
*index = value.data;
}
Expand All @@ -180,6 +206,13 @@ pub fn sstore<H: Host + ?Sized, SPEC: Spec>(interpreter: &mut Interpreter, host:
interpreter.instruction_result = InstructionResult::FatalExternalError;
return;
};
#[cfg(feature = "scroll")]
if state_load.is_cold
&& host.is_storage_key_in_access_list(interpreter.contract.target_address, index)
{
interpreter.instruction_result = InstructionResult::NotActivated;
return;
}
gas_or_fail!(interpreter, {
let remaining_gas = interpreter.gas.remaining();
gas::sstore_cost(
Expand Down
11 changes: 9 additions & 2 deletions crates/revm/src/context/inner_evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,18 @@ impl<DB: Database> InnerEvmContext<DB> {
storage_keys,
} in self.env.tx.access_list.iter()
{
self.journaled_state.initial_account_load(
let result = self.journaled_state.initial_account_load(
*address,
storage_keys.iter().map(|i| U256::from_be_bytes(i.0)),
&mut self.db,
)?;
);
cfg_if::cfg_if! {
if #[cfg(feature = "scroll")] {
result.ok();
} else {
result?;
}
}
}
Ok(())
}
Expand Down

0 comments on commit 4562c39

Please sign in to comment.