From 5403347a10f13cfc1eeac9896e77d852c5df03b4 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Thu, 4 Jul 2024 22:40:37 +0200 Subject: [PATCH] feat(trie): `HashedPostState::account_proof` --- crates/trie/trie/src/state.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/trie/trie/src/state.rs b/crates/trie/trie/src/state.rs index f92b1dd08241..c6c93c0b3620 100644 --- a/crates/trie/trie/src/state.rs +++ b/crates/trie/trie/src/state.rs @@ -1,6 +1,7 @@ use crate::{ hashed_cursor::HashedPostStateCursorFactory, prefix_set::{PrefixSetMut, TriePrefixSetsMut}, + proof::Proof, updates::TrieUpdates, Nibbles, StateRoot, }; @@ -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}, @@ -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( + &self, + tx: &TX, + address: Address, + slots: &[B256], + ) -> Result { + 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.