tempo icon indicating copy to clipboard operation
tempo copied to clipboard

perf(sub-block): avoid double encoding during signature hashing

Open 0x00101010 opened this issue 1 month ago • 1 comments

Avoid double encoding during signature hashing

0x00101010 avatar Dec 13 '25 01:12 0x00101010

@0x00101010 is attempting to deploy a commit to the Tempo Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Dec 13 '25 01:12 vercel[bot]

ah good catch, proper fix here would be to define fn length as self.rlp_header().length_with_payload()

Thought about this, personally prefer current solution:

  1. other parts of the codebase uses the same / similar pattern as current PR
  2. comparing vec reallocation vs pre-computation even using the self.rlp_header().length_with_payload() function, still think vec reallocation will be faster? length_with_payload will go through all txs and calculate length one by one, which is slower than a few pure memcpy?
  3. simpler to read

0x00101010 avatar Dec 15 '25 23:12 0x00101010

we should definitely override length fn

self.encode will still compute the length for the header so I guess we could just do something like

let header = self.rlp_header();
let mut buf = Vec::with_capacity(header.length_with_payload() + 1);
buf.put_u8(SUBBLOCK_SIGNATURE_HASH_MAGIC_BYTE);
header.encode(&mut buf);
self.rlp_encode_fields(&mut buf);

klkvr avatar Dec 15 '25 23:12 klkvr

we should definitely override length fn

self.encode will still compute the length for the header so I guess we could just do something like

let header = self.rlp_header();
let mut buf = Vec::with_capacity(header.length_with_payload() + 1);
buf.put_u8(SUBBLOCK_SIGNATURE_HASH_MAGIC_BYTE);
header.encode(&mut buf);
self.rlp_encode_fields(&mut buf);

The only difference between above and the proposed solution is the vec reallocation, which I think is totally negligible. However, with proposed solution we gain better readability and easier future maintainence (directly use the defined self.encode function)

let mut buf = vec![SUBBLOCK_SIGNATURE_HASH_MAGIC_BYTE];
self.encode(&mut buf);

let me know if you agree.

P.S.

Added length() override function for SubBlock.

0x00101010 avatar Dec 16 '25 00:12 0x00101010