Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Receipt roots
Browse files Browse the repository at this point in the history
receipts
  • Loading branch information
clabby committed Oct 17, 2023
1 parent d4b0fcf commit 562c2e3
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions crates/primitives/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use crate::{
b256, keccak256,
trie::{HashBuilder, Nibbles},
Address, GenesisAccount, Header, Log, ReceiptWithBloom, ReceiptWithBloomRef, TransactionSigned,
Withdrawal, B256,
Address, GenesisAccount, Header, Log, Receipt, ReceiptWithBloom, ReceiptWithBloomRef,
TransactionSigned, Withdrawal, B256,
};
use alloy_rlp::Encodable;
use bytes::{BufMut, BytesMut};
Expand Down Expand Up @@ -102,10 +102,28 @@ pub fn calculate_receipt_root(receipts: &[ReceiptWithBloom]) -> B256 {
/// Calculates the receipt root for a header for the reference type of [ReceiptWithBloom].
///
/// NOTE: Prefer [calculate_receipt_root] if you have log blooms memoized.
pub fn calculate_receipt_root_ref<T>(receipts: &[&T]) -> B256
where
for<'a> ReceiptWithBloomRef<'a>: From<&'a T>,
{
pub fn calculate_receipt_root_ref(receipts: &[&Receipt]) -> B256 {
#[cfg(feature = "optimism")]
{
let receipts = receipts
.iter()
.map(|r| {
let mut r = (*r).clone();
r.deposit_nonce = None;
r
})
.collect::<Vec<_>>();

// There is a minor bug in op-geth and op-erigon where in the Regolith hardfork,
// the receipt root calculation does not include the deposit nonce in the receipt
// encoding. This will be fixd in the next hardfork, however for now, we must strip
// the deposit nonce from the receipts before calculating the receipt root.
ordered_trie_root_with_encoder(&receipts, |r, buf| {
ReceiptWithBloomRef::from(r).encode_inner(buf, false)
})
}

#[cfg(not(feature = "optimism"))]
ordered_trie_root_with_encoder(receipts, |r, buf| {
ReceiptWithBloomRef::from(r).encode_inner(buf, false)
})
Expand Down

0 comments on commit 562c2e3

Please sign in to comment.