9

Is this an ad-hoc decision? Why RLP? Is it specifically suited to something?

11

RLP was chosen because of (1) simplicity of implementation, and (2) guaranteed absolute byte-perfect consistency.

Source is Ethereum Wiki:

RLP is intended to be a highly minimalistic serialization format; its sole purpose is to store nested arrays of bytes. Unlike protobuf, BSON and other existing solutions, RLP does not attempt to define any specific data types such as booleans, floats, doubles or even integers; instead, it simply exists to store structure, in the form of nested arrays, and leaves it up to the protocol to determine the meaning of the arrays. Key/value maps are also not explicitly supported; the semi-official suggestion for supporting key/value maps is to represent such maps as [[k1, v1], [k2, v2], ...] where k1, k2... are sorted using the standard ordering for strings.

The alternative to RLP would have been using an existing algorithm such as protobuf or BSON; however, we prefer RLP because of (1) simplicity of implementation, and (2) guaranteed absolute byte-perfect consistency. Key/value maps in many languages don't have an explicit ordering, and floating point formats have many special cases, potentially leading to the same data leading to different encodings and thus different hashes. By developing a protocol in-house we can be assured that it is designed with these goals in mind (this is a general principle that applies also to other parts of the code, eg. the VM). Note that bencode, used by BitTorrent, may have provided a passable alternative for RLP, although its use of decimal encoding for lengths makes it slightly suboptimal compared to the binary RLP.

  • Thanks all, I was unaware of the design rationale document. – Sentinel Jun 29 '17 at 20:29
  • 3
    By the way. I often see the phrase "RLP was chosen" but I don't see anything to suggest that RLP existed outside of Ethereum. Am I correct in saying that RLP was designed for Ethereum, and is specific to Ethereum? The Yellow paper specification does in fact recognize positive integers as part of the RLP spec, so it is not data type agnostic, and has special requirements for their encoding. – Sentinel Nov 13 '17 at 15:50

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.