2

I am trying to understand why RLP was chosen and developed as an in-house protocol.I stumbled up this link which provides some insights:

https://github.com/ethereum/wiki/wiki/Design-Rationale

Trying to understand the paragraph below, a detailed explanation is greatly appreciated.

"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."

2

It says that RLP is

  • simple
  • unambiguous

It's simpler than other algorithms because it doesn't define any data types other than bytes and arrays.

It's unambiguous because the same input data is always serialized to the same sequence of bytes.

In many languages key/value maps don't have explicit ordering. This means 2 entries:

key1: value1
key2: value2

might be serialized as:

{
  "key1": "value1",
  "key2": "value2"
}

in one implementation, and

{
  "key2": "value2",
  "key1": "value1"
}

in another implementation. The same input data can output different serializations. This is unacceptable in Ethereum.

On the other hand, when using RLP, the map needs to be converted to arrays first (this conversion is out of scope for RLP), and then passed to RLP for serialization. In our example, the input structure for RLP will be:

[["key1", "value1"],["key2","value2"]]

where strings in quotes should first be converted into bytes (also out of scope for RLP).

Basically, RLP tries to avoid ambiguity by limiting the supported datatypes.

| improve this answer | |
  • Thank you for the detailed answer from what I am getting is 1)RLP is simple 2)Only understands bytes and arrays. Relating to mapping Key->Value pairs, the order has to be in chronological order and in order to maintain that Keys [ ["key1", "val1"], ["key2", "val2"] ] are serialized as in the exact order as they have been sent as a input. This I assume is to maintain the ordering. – drao Mar 10 '18 at 20:11
  • That's correct. – medvedev1088 Mar 10 '18 at 20:16

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.