From 659448241bd015153d9b851058ab75743bca0ee4 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 5 Dec 2024 12:44:48 +0100 Subject: [PATCH] chore: reuse alloy proof fns (#13091) --- crates/primitives/src/proofs.rs | 36 +++++++++------------------------ 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/crates/primitives/src/proofs.rs b/crates/primitives/src/proofs.rs index 81c26d7180..2a1d5b6982 100644 --- a/crates/primitives/src/proofs.rs +++ b/crates/primitives/src/proofs.rs @@ -1,26 +1,22 @@ //! Helper function for calculating Merkle proofs and hashes. use crate::{Receipt, ReceiptWithBloom, ReceiptWithBloomRef}; -use alloc::{borrow::Borrow, vec::Vec}; -use alloy_consensus::{Header, EMPTY_OMMER_ROOT_HASH}; -use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawal}; -use alloy_primitives::{keccak256, B256}; -use alloy_trie::root::{ordered_trie_root, ordered_trie_root_with_encoder}; +use alloy_primitives::B256; +use alloy_trie::root::ordered_trie_root_with_encoder; /// Calculate a transaction root. /// /// `(rlp(index), encoded(tx))` pairs. -pub fn calculate_transaction_root(transactions: &[T]) -> B256 -where - T: Encodable2718, -{ - ordered_trie_root_with_encoder(transactions, |tx, buf| tx.borrow().encode_2718(buf)) -} +#[doc(inline)] +pub use alloy_consensus::proofs::calculate_transaction_root; /// Calculates the root hash of the withdrawals. -pub fn calculate_withdrawals_root(withdrawals: &[Withdrawal]) -> B256 { - ordered_trie_root(withdrawals) -} +#[doc(inline)] +pub use alloy_consensus::proofs::calculate_withdrawals_root; + +/// Calculates the root hash for ommer/uncle headers. +#[doc(inline)] +pub use alloy_consensus::proofs::calculate_ommers_root; /// Calculates the receipt root for a header. pub fn calculate_receipt_root(receipts: &[ReceiptWithBloom]) -> B256 { @@ -41,18 +37,6 @@ pub fn calculate_receipt_root_no_memo(receipts: &[&Receipt]) -> B256 { }) } -/// Calculates the root hash for ommer/uncle headers. -pub fn calculate_ommers_root(ommers: &[Header]) -> B256 { - // Check if `ommers` list is empty - if ommers.is_empty() { - return EMPTY_OMMER_ROOT_HASH - } - // RLP Encode - let mut ommers_rlp = Vec::new(); - alloy_rlp::encode_list(ommers, &mut ommers_rlp); - keccak256(ommers_rlp) -} - #[cfg(test)] mod tests { use super::*;