Suppose I'm building a transaction such as:

const raw = [
    new Buffer("0001", "hex"),
    new Buffer("23000000000", "hex"),
    new Buffer("21000", "hex"),
    new Buffer("0x00000000000000000000"),
    new Buffer("0xde0b6b3a7640000"),
    new Buffer("0x1234abcd")
const encoded = RLP.encode(raw);

Can I freely add/remove leading zeroes of those buffers without affecting the meaning of the message?

1 Answer 1


You can't. RLP can't have leading zeros. It is designed to encode values in a shortest way, so redundant leading zeros make RLP not canonical.

What's more, transaction's RLP starts with payload containing size of transaction. By prepending anything there, you simply alter/overwrite the payload and make transaction undecodable


Encoding example:

257 is encoded as 0x810101 which is

0x80 plus the length of the string followed by the string

docs: https://github.com/ethereum/wiki/wiki/RLP

  • OK - but is that on the byte level, right? You can still have leading zeroes within a byte, i.e., 257 is still 00000001 00000001, rather than 10000001, corect?
    – MaiaVictor
    Apr 1, 2017 at 17:45
  • I've added encoding example to my response ;)
    – debris
    Apr 2, 2017 at 16:43
  • Note: With nonce 0x80 is not appended until nonce ≥0x80 itself. So nonce of 0x0 is 80, nonce of 0x1 is 01, nonce of 0x7f is just 7f whereas nonce 0x8f is 808f May 15, 2020 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.