Skip to content

Commit

Permalink
grasp
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy committed Nov 14, 2024
1 parent 4a395a5 commit dce3341
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions crates/executor/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ impl ClientExecutor {
{
// Initialize the witnessed database with verified storage proofs.
let witness_db = input.witness_db()?;
let db = WrapDatabaseRef(witness_db);

// Execute the block.
let spec = V::spec();
Expand All @@ -114,7 +113,7 @@ impl ClientExecutor {
})?;
let executor_difficulty = input.current_block.header.difficulty;
let executor_output =
profile!("execute", { V::execute(&executor_block_input, executor_difficulty, db) })?;
profile!("execute", { V::execute(&executor_block_input, executor_difficulty, witness_db) })?;

// Validate the block post execution.
profile!("validate block post-execution", {
Expand Down
12 changes: 6 additions & 6 deletions crates/storage/witness-db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use reth_primitives::{
revm_primitives::{db::DatabaseRef, AccountInfo, Bytecode},
revm_primitives::{db::Database, AccountInfo, Bytecode},
B256,
};
use reth_storage_errors::provider::ProviderError;
Expand All @@ -17,26 +17,26 @@ pub struct WitnessDb {
pub block_hashes: HashMap<u64, B256>,
}

impl DatabaseRef for WitnessDb {
impl Database for WitnessDb {
type Error = ProviderError;

fn basic_ref(&self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
fn basic(&mut self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
// 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> {
fn code_by_hash(&mut self, _code_hash: B256) -> Result<Bytecode, Self::Error> {
unimplemented!()
}

fn storage_ref(&self, address: Address, index: U256) -> Result<U256, Self::Error> {
fn storage(&mut 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())
}

fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
Ok(*self.block_hashes.get(&number).unwrap())
}
}

0 comments on commit dce3341

Please sign in to comment.