From 6377aa9828ddd68a088a066702968114e3fe5183 Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Mon, 26 Aug 2024 12:27:45 +0200 Subject: [PATCH] EVM Node: Fix RLP encoding for transaction receipts In the kernel, the index of the transaction receipt is a `u32`, using the default RLP encoding for the primitive type (see `etherlink/kernel_evm/ethereum/src/transaction.rs`). let index: u32 = decode_field(&next(&mut it)?, "index")?; A peek at the [rlp] crate to see how the decoder is defined teaches us that `u32` are encoded as big-endian numbers (without the leading 0s). macro_rules! impl_encodable_for_u { ($name: ident) => { impl Encodable for $name { fn rlp_append(&self, s: &mut RlpStream) { let leading_empty_bytes = self.leading_zeros() as usize / 8; let buffer = self.to_be_bytes(); s.encoder().encode_value(&buffer[leading_empty_bytes..]); } } }; } On the node side, we can find the encoding of the transaction receipts in `etherlink/bin_node/lib_dev/encodings/transaction.ml`, and let index = decode_number_le index in And here it is. That is why the result for `eth_getTransactionReceipt` is inconsistent for blocks with more than 256 transactions. [rlp]: https://docs.rs/rlp/0.5.2/src/rlp/impls.rs.html#165 --- etherlink/CHANGES_NODE.md | 2 ++ etherlink/bin_node/lib_dev/encodings/transaction_receipt.ml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/etherlink/CHANGES_NODE.md b/etherlink/CHANGES_NODE.md index 944d27c9de43..6ce544bd2a44 100644 --- a/etherlink/CHANGES_NODE.md +++ b/etherlink/CHANGES_NODE.md @@ -76,6 +76,8 @@ - Improves the error message in case of unknown block in RPCs. (!14150) - Produces an empty block in case the produced one will trigger a kernel upgrade. (!14207) +- `eth_getTransactionReceipt` always returns the expected index for blocks with + more than 256 transactions. (!14645) ### Experimental diff --git a/etherlink/bin_node/lib_dev/encodings/transaction_receipt.ml b/etherlink/bin_node/lib_dev/encodings/transaction_receipt.ml index cea5ad5187ba..31e28192e3dd 100644 --- a/etherlink/bin_node/lib_dev/encodings/transaction_receipt.ml +++ b/etherlink/bin_node/lib_dev/encodings/transaction_receipt.ml @@ -46,7 +46,7 @@ let of_rlp_bytes block_hash bytes = Value status; ]) -> let hash = decode_hash hash in - let index = decode_number_le index in + let index = decode_number_be index in let block_number = decode_number_le block_number in let from = decode_address from in let to_ = if to_ = Bytes.empty then None else Some (decode_address to_) in -- GitLab