2

What are the differences between SCALE and RLP serialization beyond little-endian vs big-endian encoding? If both are length-encoded, what might make one better than the other?

1 Answer 1

3

I am not an expert of RLP, but it does not seem these two things are that comparable.

From RLP docs:

The purpose of RLP is to encode arbitrarily nested arrays of binary data, and RLP is the primary encoding method used to serialize objects in Ethereum's execution layer. The only purpose of RLP is to encode structure; encoding specific data types (e.g. strings, floats) is left up to higher-order protocols; but positive RLP integers must be represented in big-endian binary form with no leading zeroes (thus making the integer value zero equivalent to the empty byte array).

SCALE clearly has a wider scope than RLP, where the SCALE specification is designed to encode any data type.

Furthermore, it is not trivial to just breeze over the fact that SCALE is little-endian, since Wasm is little-endian making SCALE near zero overhead, and we know that Substrate and Polkadot are based entirely around Wasm.

Beyond that, you have the usual reasons why SCALE was chosen:

  • Simple to define.
  • Not Rust-specific (but happens to work great in Rust).
    • Easy to derive codec logic: #[derive(Encode, Decode)]
    • Viable and useful for APIs like: MaxEncodedLen and TypeInfo
    • It does not use Rust std, and thus can compile to Wasm no_std.
  • Consensus critical / bijective; one value will always encode to one blob and that blob will only decode to that value.
  • Supports a copy-free decode for basic types on LE architectures.
  • It is about as thin and lightweight as can be.
1
  • Thanks for the great answer @Shawn!
    – Drew Stone
    Commented Sep 3, 2022 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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