[go: up one dir, main page]

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.

Manually testing the MR

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, CHANGES.rst at the root of the repository for everything else).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR

Merge request reports

Loading