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?


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 '17 at 17:45
  • I've added encoding example to my response ;) – debris Apr 2 '17 at 16:43

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.