Skip to content
Merged
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
13 changes: 6 additions & 7 deletions src/db/fork_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use std::{

/// Maps storage slots to their values.
/// Also contains a flag to indicate if the account is self destructed.
/// If the account is self destructed, it won't read from the inner database.
/// Dont read from inner db is used to indicate that the account is not self destructed.
#[derive(Debug, Clone, Default)]
pub struct ForkStorageMap {
pub map: HashMap<U256, U256>,
self_destructed: bool,
pub dont_read_from_inner_db: bool,
}

/// Contains mutations on top of an existing database.
Expand Down Expand Up @@ -62,7 +62,7 @@ impl<ExtDb: DatabaseRef> DatabaseRef for ForkDb<ExtDb> {
match self.storage.get(&address) {
Some(s) => {
// If the account is self destructed, do not read from inner db.
if s.self_destructed {
if s.dont_read_from_inner_db {
return Ok(*s.map.get(&slot).unwrap_or(&U256::ZERO));
}

Expand Down Expand Up @@ -97,9 +97,8 @@ impl<ExtDb> DatabaseCommit for ForkDb<ExtDb> {

let fork_storage_map = self.storage.entry(address).or_default();

// Mark the account as self destructed.
// This will prevent reading from the inner database.
fork_storage_map.self_destructed = true;
// Mark the account to not read from the inner database if it is self destructed.
fork_storage_map.dont_read_from_inner_db = true;
fork_storage_map.map.clear();

continue;
Expand Down Expand Up @@ -129,7 +128,7 @@ impl<ExtDb> DatabaseCommit for ForkDb<ExtDb> {
.into_iter()
.map(|(k, v)| (k, v.present_value()))
.collect(),
self_destructed: false,
dont_read_from_inner_db: false,
},
);
}
Expand Down
12 changes: 12 additions & 0 deletions src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@ where
state.insert(ASSERTION_CONTRACT, account);
state.insert(CALLER, caller_account);
multi_fork_db.commit(state);
multi_fork_db
.active_db
.storage
.entry(ASSERTION_CONTRACT)
.or_default()
.dont_read_from_inner_db = true;
multi_fork_db
.active_db
.storage
.entry(CALLER)
.or_default()
.dont_read_from_inner_db = true;
Comment thread
makemake-kbo marked this conversation as resolved.

trace!(
target: "assertion-executor::assertion",
Expand Down
5 changes: 5 additions & 0 deletions src/inspectors/phevm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ fn insert_precompile_account<T>(db: &mut MultiForkDb<T>) {
..Default::default()
},
);
db.active_db
.storage
.entry(PRECOMPILE_ADDRESS)
.or_default()
.dont_read_from_inner_db = true;
}

#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions src/inspectors/precompiles/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ pub fn load_external_slot(
};
let address: Address = call.target;

// Load the account before reading the storage.
// This prevents a bug with revm's State<Db> where it panics if reading the storage before
// loading the account.
let _ = context.db.active_db.basic_ref(address);

let slot = call.slot;

let slot_value = match context.db.active_db.storage_ref(address, slot.into()) {
Expand Down