Skip to content

Commit

Permalink
fix: unconstrained account absence (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI authored Sep 11, 2024
1 parent cb3f341 commit 4d57234
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/storage/witness-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ impl DatabaseRef for WitnessDb {
type Error = ProviderError;

fn basic_ref(&self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
Ok(self.accounts.get(&address).cloned())
// Even absent accounts are loaded as `None`, so if an entry is missing from `HashMap` we
// need to panic. Otherwise it would be interpreted by `revm` as an uninitialized account.
Ok(Some(self.accounts.get(&address).cloned().unwrap()))
}

fn code_by_hash_ref(&self, _code_hash: B256) -> Result<Bytecode, Self::Error> {
unimplemented!()
}

fn storage_ref(&self, address: Address, index: U256) -> Result<U256, Self::Error> {
// Absence of storage trie or slot must be treated as an error here. Otherwise it's possible
// to trick `revm` into believing a slot is `0` when it's not.
Ok(*self.storage.get(&address).unwrap().get(&index).unwrap())
}

Expand Down

0 comments on commit 4d57234

Please sign in to comment.