Home

RLP

RLP, or Recursive Length Prefix encoding, is a simple serialisation method used to encode arbitrarily nested arrays of binary data. It is designed for compact representation and efficient decoding, and it is a core encoding scheme in Ethereum for encoding various protocol data structures such as transactions, blocks, receipts, and state data. RLP is characterized by its use of prefixes to indicate the length of encoded items, enabling straightforward parsing and streaming.

The encoding rules distinguish between strings (raw byte sequences) and lists (arrays of encoded items). For

Examples help illustrate: encoding the string "cat" (three bytes) yields 0x83 63 61 74; encoding the list

a
string,
several
cases
apply:
the
empty
string
is
encoded
as
a
single
byte
0x80;
a
single
byte
with
value
in
the
range
0x00
to
0x7f
is
encoded
as
that
byte
itself
(no
prefix);
a
string
with
length
L
between
1
and
55
is
prefixed
with
0x80
+
L
followed
by
the
data;
a
string
longer
than
55
bytes
is
prefixed
with
0xb7
+
the
length
of
the
length,
followed
by
the
length
in
big-endian
form
and
then
the
data.
Lists
are
encoded
similarly
but
with
different
prefix
ranges:
a
list
with
total
payload
length
up
to
55
bytes
uses
0xc0
+
length
as
the
prefix,
followed
by
the
concatenation
of
the
encoded
items;
longer
lists
use
0xf7
+
length
of
the
length,
followed
by
the
length
and
the
payload.
The
empty
list
is
encoded
as
0xc0.
["cat",
"dog"]
yields
0xc8
0x83
63
61
74
0x83
64
6f
67.
RLP
is
not
a
cryptographic
primitive;
it
is
an
encoding
scheme
used
to
enable
compact,
unambiguous
data
transmission
and
storage
within
Ethereum.