Skip to content

Commit

Permalink
feat(trie): HashedPostState::account_proof
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk committed Jul 4, 2024
1 parent 1fcd819 commit 5403347
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/trie/trie/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
hashed_cursor::HashedPostStateCursorFactory,
prefix_set::{PrefixSetMut, TriePrefixSetsMut},
proof::Proof,
updates::TrieUpdates,
Nibbles, StateRoot,
};
Expand All @@ -13,6 +14,7 @@ use reth_db_api::{
};
use reth_execution_errors::StateRootError;
use reth_primitives::{keccak256, Account, Address, BlockNumber, B256, U256};
use reth_trie_common::AccountProof;
use revm::db::BundleAccount;
use std::{
collections::{hash_map, HashMap, HashSet},
Expand Down Expand Up @@ -252,6 +254,21 @@ impl HashedPostState {
.with_prefix_sets(prefix_sets)
.root_with_updates()
}

/// Generates the state proof for target account and slots on top of this [`HashedPostState`].
pub fn account_proof<TX: DbTx>(
&self,
tx: &TX,
address: Address,
slots: &[B256],
) -> Result<AccountProof, StateRootError> {
let sorted = self.clone().into_sorted();
let prefix_sets = self.construct_prefix_sets();
Proof::from_tx(tx)
.with_hashed_cursor_factory(HashedPostStateCursorFactory::new(tx, &sorted))
.with_prefix_sets_mut(prefix_sets)
.account_proof(address, slots)
}
}

/// Representation of in-memory hashed storage.
Expand Down

0 comments on commit 5403347

Please sign in to comment.