Skip to content

Compute receipts root #106

@MegaRedHand

Description

@MegaRedHand

We need to compute the Merkle Patricia Tree's root for the receipts generated after executing all the transactions in a given block body. For an example, see the computation for the transactions root:

pub fn compute_transactions_root(&self) -> H256 {
let transactions_iter: Vec<_> = self
.transactions
.iter()
.enumerate()
.map(|(i, tx)| {
// TODO: check if tree is RLP encoding the value
// Key: RLP(tx_index)
let mut k = Vec::new();
i.encode(&mut k);
// Value: tx_type || RLP(tx) if tx_type != 0
// RLP(tx) else
let mut v = Vec::new();
match tx {
// Legacy transactions don't have a prefix
Transaction::LegacyTransaction(_) => {}
_ => v.push(tx.tx_type()),
}
tx.encode(&mut v);
(k, v)
})
.collect();
let root = PatriciaMerkleTree::<_, _, Keccak256>::compute_hash_from_sorted_iter(
&transactions_iter,
);
H256(root.into())
}
}

You can check how values are encoded in Ethereum's yellow paper. Similar to transactions, the key should be computed as KECCAK256(RLP(receipts_index)) and the value as tx_type (if tx_type != 0) || RLP(receipt).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions