fix(witness): allow no storage multiproof (#10656)

This commit is contained in:
Roman Krasiuk
2024-09-02 07:04:25 -07:00
committed by GitHub
parent d5906f3f89
commit d5c6f1a54c
2 changed files with 6 additions and 11 deletions

View File

@ -125,9 +125,6 @@ pub enum TrieWitnessError {
Proof(StateProofError), Proof(StateProofError),
/// RLP decoding error. /// RLP decoding error.
Rlp(alloy_rlp::Error), Rlp(alloy_rlp::Error),
/// Missing storage multiproof.
#[display("missing storage multiproof for {_0}")]
MissingStorageMultiProof(B256),
/// Missing account. /// Missing account.
#[display("missing account {_0}")] #[display("missing account {_0}")]
MissingAccount(B256), MissingAccount(B256),

View File

@ -74,7 +74,7 @@ where
}), }),
), ),
); );
let account_multiproof = let mut account_multiproof =
Proof::new(self.trie_cursor_factory.clone(), self.hashed_cursor_factory.clone()) Proof::new(self.trie_cursor_factory.clone(), self.hashed_cursor_factory.clone())
.with_prefix_sets_mut(self.prefix_sets.clone()) .with_prefix_sets_mut(self.prefix_sets.clone())
.with_targets(proof_targets.clone()) .with_targets(proof_targets.clone())
@ -85,11 +85,8 @@ where
let mut account_rlp = Vec::with_capacity(128); let mut account_rlp = Vec::with_capacity(128);
let mut account_trie_nodes = BTreeMap::default(); let mut account_trie_nodes = BTreeMap::default();
for (hashed_address, hashed_slots) in proof_targets { for (hashed_address, hashed_slots) in proof_targets {
let key = Nibbles::unpack(hashed_address); let storage_multiproof =
let storage_multiproof = account_multiproof account_multiproof.storages.remove(&hashed_address).unwrap_or_default();
.storages
.get(&hashed_address)
.ok_or(TrieWitnessError::MissingStorageMultiProof(hashed_address))?;
// Gather and record account trie nodes. // Gather and record account trie nodes.
let account = state let account = state
@ -104,6 +101,7 @@ where
} else { } else {
None None
}; };
let key = Nibbles::unpack(hashed_address);
let proof = account_multiproof.account_subtree.iter().filter(|e| key.starts_with(e.0)); let proof = account_multiproof.account_subtree.iter().filter(|e| key.starts_with(e.0));
account_trie_nodes.extend(self.target_nodes(key.clone(), value, proof)?); account_trie_nodes.extend(self.target_nodes(key.clone(), value, proof)?);
@ -124,7 +122,7 @@ where
)?); )?);
} }
let root = Self::next_root_from_proofs(storage_trie_nodes, |key: Nibbles| { let storage_root = Self::next_root_from_proofs(storage_trie_nodes, |key: Nibbles| {
// Right pad the target with 0s. // Right pad the target with 0s.
let mut padded_key = key.pack(); let mut padded_key = key.pack();
padded_key.resize(32, 0); padded_key.resize(32, 0);
@ -142,7 +140,7 @@ where
self.witness.insert(keccak256(node.as_ref()), node.clone()); // record in witness self.witness.insert(keccak256(node.as_ref()), node.clone()); // record in witness
Ok(node) Ok(node)
})?; })?;
debug_assert_eq!(storage_multiproof.root, root); debug_assert_eq!(storage_multiproof.root, storage_root);
} }
Self::next_root_from_proofs(account_trie_nodes, |key: Nibbles| { Self::next_root_from_proofs(account_trie_nodes, |key: Nibbles| {