Skip to content

Commit

Permalink
fix(witness): collect witness using sparse trie
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk committed Dec 3, 2024
1 parent 9d5e159 commit 0e93c96
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 229 deletions.
11 changes: 4 additions & 7 deletions crates/evm/execution-errors/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,20 @@ pub enum SparseTrieError {
}

/// Trie witness errors.
#[derive(Error, PartialEq, Eq, Clone, Debug)]
#[derive(Error, Debug)]
pub enum TrieWitnessError {
/// Error gather proofs.
#[error(transparent)]
Proof(#[from] StateProofError),
/// RLP decoding error.
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
/// Sparse state trie error.
#[error(transparent)]
Sparse(#[from] SparseStateTrieError),
/// Missing account.
#[error("missing account {_0}")]
MissingAccount(B256),
/// Missing target node.
#[error("target node missing from proof {_0:?}")]
MissingTargetNode(Nibbles),
/// Unexpected empty root.
#[error("unexpected empty root: {_0:?}")]
UnexpectedEmptyRoot(Nibbles),
}

impl From<TrieWitnessError> for ProviderError {
Expand Down
2 changes: 1 addition & 1 deletion crates/trie/sparse/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ pub struct SparseStateTrie<F: BlindedProviderFactory = DefaultBlindedProviderFac
impl Default for SparseStateTrie {
fn default() -> Self {
Self {
provider_factory: Default::default(),
state: Default::default(),
storages: Default::default(),
revealed: Default::default(),
provider_factory: Default::default(),
retain_updates: false,
account_rlp_buf: Vec::with_capacity(TRIE_ACCOUNT_RLP_MAX_SIZE),
}
Expand Down
34 changes: 34 additions & 0 deletions crates/trie/trie/src/proof/blinded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ pub struct ProofBlindedProviderFactory<T, H> {
prefix_sets: Arc<TriePrefixSetsMut>,
}

impl<T, H> ProofBlindedProviderFactory<T, H> {
/// Create new proof-based blinded provider factory.
pub fn new(
trie_cursor_factory: T,
hashed_cursor_factory: H,
prefix_sets: Arc<TriePrefixSetsMut>,
) -> Self {
Self { trie_cursor_factory, hashed_cursor_factory, prefix_sets }
}
}

impl<T, H> BlindedProviderFactory for ProofBlindedProviderFactory<T, H>
where
T: TrieCursorFactory + Clone,
Expand Down Expand Up @@ -57,6 +68,17 @@ pub struct ProofBlindedAccountProvider<T, H> {
prefix_sets: Arc<TriePrefixSetsMut>,
}

impl<T, H> ProofBlindedAccountProvider<T, H> {
/// Create new proof-based blinded account node provider.
pub fn new(
trie_cursor_factory: T,
hashed_cursor_factory: H,
prefix_sets: Arc<TriePrefixSetsMut>,
) -> Self {
Self { trie_cursor_factory, hashed_cursor_factory, prefix_sets }
}
}

impl<T, H> BlindedProvider for ProofBlindedAccountProvider<T, H>
where
T: TrieCursorFactory + Clone,
Expand Down Expand Up @@ -89,6 +111,18 @@ pub struct ProofBlindedStorageProvider<T, H> {
account: B256,
}

impl<T, H> ProofBlindedStorageProvider<T, H> {
/// Create new proof-based blinded storage node provider.
pub fn new(
trie_cursor_factory: T,
hashed_cursor_factory: H,
prefix_sets: Arc<TriePrefixSetsMut>,
account: B256,
) -> Self {
Self { trie_cursor_factory, hashed_cursor_factory, prefix_sets, account }
}
}

impl<T, H> BlindedProvider for ProofBlindedStorageProvider<T, H>
where
T: TrieCursorFactory + Clone,
Expand Down
Loading

0 comments on commit 0e93c96

Please sign in to comment.