Debugging RLP on the Web

Geunwoo Kim
CodeChain
Published in
3 min readJun 24, 2019

RLP(Recursive Length Prefix) is the way of encoding arbitrarily nested arrays of binary data. It was first proposed for serializing Ethereum’s objects, such as transactions and smart contracts. Data for RLP encoding is defined as two forms: string and array. An item of an array is recursively defined as two forms again, which is why its name includes “Recursive”. Also, RLP attaches a prefix that specifies the length in front of encoded data except single byte encoded data. This is the reason why it is called “Length Prefix”. Loosely inspired by this, CodeChain is using the same scheme for serializing objects that are held by a node before storing them into the disk or sending them to peers.

In the middle of developing CodeChain, we encountered a number of instances to dig into an RLP encoded data and add or remove an item from it. From this article, I am going to tell you about a useful tool you can use when you face such situations.

The rlp-debugger is an RLP debugging web page powered by CodeChain team. Anyone can use and access it even now. The rlp-debugger basically provides the functionality to encode and decode data and also has an integrated user-interface to add, remove and edit an item in the data.

  1. Decoding

When you first open the rlp-debugger, you can see such textbox where you can put your rlp encoded data as a hex string form. If your data is valid, the ‘Decode’ button will be activated.

If your data is not a valid form of rlp encoded data, the button will be deactivated while printing “RLP decode error”.

2. Encoding

For example, when you decode “c512c2345678”, you can see the structure of the decoded data. Furthermore, if you click the + button next to the item, you can add a new item for the very next index. If you click the — button, you can remove the corresponding item. In cases where the item is an array, if you click the + button just under the array(e.g [+] List(2)) a new item will be added in front of the array. The ‘List’ button is used to change a single item to an array.

It is also possible to edit the items in various forms.

Before using the rlp-debugger, it is worth noting that if your modifications on the decoded data is invalid, you cannot encode it properly. For example, if you type 0x3f4ttt on the item textbox, encoding is not possible. In addition to that, if you want to encode ‘null’, then just empty the textbox.

We briefly look around what the rlp-debugger is and how to use it. This is where the rlp-debugger is now running:

https://codechain-io.github.io/rlp-debugger/

If you find some bugs, please report them as an issue on this repository.

--

--