Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/storage/provider/src/providers/state/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'b, TX: DbTx> StateRootProvider for LatestStateProviderRef<'b, TX> {

impl<'b, TX: DbTx> StateProofProvider for LatestStateProviderRef<'b, TX> {
fn proof(&self, address: Address, slots: &[B256]) -> ProviderResult<AccountProof> {
Ok(Proof::new(self.tx)
Ok(Proof::from_tx(self.tx)
.account_proof(address, slots)
.map_err(Into::<reth_db::DatabaseError>::into)?)
}
Expand Down
31 changes: 23 additions & 8 deletions crates/trie/trie/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@ pub struct Proof<'a, TX, H> {
hashed_cursor_factory: H,
}

impl<'a, TX, H> Proof<'a, TX, H> {
/// Creates a new proof generator.
pub const fn new(tx: &'a TX, hashed_cursor_factory: H) -> Self {
Self { tx, hashed_cursor_factory }
}

/// Set the hashed cursor factory.
pub fn with_hashed_cursor_factory<HF>(self, hashed_cursor_factory: HF) -> Proof<'a, TX, HF> {
Proof { tx: self.tx, hashed_cursor_factory }
}
}

impl<'a, TX> Proof<'a, TX, &'a TX> {
/// Create a new [Proof] instance.
pub const fn new(tx: &'a TX) -> Self {
Self { tx, hashed_cursor_factory: tx }
/// Create a new [Proof] instance from database transaction.
pub const fn from_tx(tx: &'a TX) -> Self {
Self::new(tx, tx)
}
}

Expand Down Expand Up @@ -282,7 +294,8 @@ mod tests {
let provider = factory.provider().unwrap();
for (target, expected_proof) in data {
let target = Address::from_str(target).unwrap();
let account_proof = Proof::new(provider.tx_ref()).account_proof(target, &[]).unwrap();
let account_proof =
Proof::from_tx(provider.tx_ref()).account_proof(target, &[]).unwrap();
similar_asserts::assert_eq!(
account_proof.proof,
expected_proof,
Expand All @@ -302,7 +315,8 @@ mod tests {
let slots = Vec::from([B256::with_last_byte(1), B256::with_last_byte(3)]);

let provider = factory.provider().unwrap();
let account_proof = Proof::new(provider.tx_ref()).account_proof(target, &slots).unwrap();
let account_proof =
Proof::from_tx(provider.tx_ref()).account_proof(target, &slots).unwrap();
assert_eq!(account_proof.storage_root, EMPTY_ROOT_HASH, "expected empty storage root");

assert_eq!(slots.len(), account_proof.storage_proofs.len());
Expand Down Expand Up @@ -334,7 +348,7 @@ mod tests {
]);

let provider = factory.provider().unwrap();
let account_proof = Proof::new(provider.tx_ref()).account_proof(target, &[]).unwrap();
let account_proof = Proof::from_tx(provider.tx_ref()).account_proof(target, &[]).unwrap();
similar_asserts::assert_eq!(account_proof.proof, expected_account_proof);
assert_eq!(account_proof.verify(root), Ok(()));
}
Expand All @@ -357,7 +371,7 @@ mod tests {
]);

let provider = factory.provider().unwrap();
let account_proof = Proof::new(provider.tx_ref()).account_proof(target, &[]).unwrap();
let account_proof = Proof::from_tx(provider.tx_ref()).account_proof(target, &[]).unwrap();
similar_asserts::assert_eq!(account_proof.proof, expected_account_proof);
assert_eq!(account_proof.verify(root), Ok(()));
}
Expand Down Expand Up @@ -443,7 +457,8 @@ mod tests {
};

let provider = factory.provider().unwrap();
let account_proof = Proof::new(provider.tx_ref()).account_proof(target, &slots).unwrap();
let account_proof =
Proof::from_tx(provider.tx_ref()).account_proof(target, &slots).unwrap();
similar_asserts::assert_eq!(account_proof, expected);
assert_eq!(account_proof.verify(root), Ok(()));
}
Expand Down