Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute receipts root #106

Closed
Tracked by #68
MegaRedHand opened this issue Jul 1, 2024 · 0 comments · Fixed by #111
Closed
Tracked by #68

Compute receipts root #106

MegaRedHand opened this issue Jul 1, 2024 · 0 comments · Fixed by #111
Assignees

Comments

@MegaRedHand
Copy link
Collaborator

MegaRedHand commented Jul 1, 2024

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).

@MegaRedHand MegaRedHand moved this to Todo in ethrex_l1 Jul 1, 2024
@ricomateo ricomateo self-assigned this Jul 2, 2024
@ricomateo ricomateo moved this from Todo to In Progress in ethrex_l1 Jul 2, 2024
@ricomateo ricomateo moved this from In Progress to In Review in ethrex_l1 Jul 2, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l1 Jul 3, 2024
mpaulucci pushed a commit to mpaulucci/lambda_ethereum_rust that referenced this issue Oct 16, 2024
Closes lambdaclass#106

---------

Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants