RLPWriter

Git Source

Author: RLPWriter is a library for encoding Solidity types to RLP bytes. Adapted from Bakaoh's RLPEncode library (https://github.com/bakaoh/solidity-rlp-encode) with minor modifications to improve legibility.

Notes:

  • https://github.com/bakaoh/solidity-rlp-encode

  • https://raw.githubusercontent.com/Maia-DAO/solidity-rlp-encoder/main/rlp/RLPWriter.sol

Functions

writeBytes

RLP encodes a byte string.

function writeBytes(bytes memory _in) internal pure returns (bytes memory);

Parameters

NameTypeDescription
_inbytesThe byte string to encode.

Returns

NameTypeDescription
<none>bytesThe RLP encoded string in bytes.

writeList

RLP encodes a list of RLP encoded byte byte strings.

function writeList(bytes memory _in) internal pure returns (bytes memory);

Parameters

NameTypeDescription
_inbytesThe RLP encoded byte strings.

Returns

NameTypeDescription
<none>bytesThe RLP encoded list of items in bytes.

writeList

RLP encodes a list of RLP encoded byte byte strings.

function writeList(bytes[] memory _in) internal pure returns (bytes memory);

Parameters

NameTypeDescription
_inbytes[]The list of RLP encoded byte strings.

Returns

NameTypeDescription
<none>bytesThe RLP encoded list of items in bytes.

writeString

RLP encodes a string.

function writeString(string memory _in) internal pure returns (bytes memory);

Parameters

NameTypeDescription
_instringThe string to encode.

Returns

NameTypeDescription
<none>bytesThe RLP encoded string in bytes.

writeAddress

RLP encodes an address.

function writeAddress(address _in) internal pure returns (bytes memory);

Parameters

NameTypeDescription
_inaddressThe address to encode.

Returns

NameTypeDescription
<none>bytesThe RLP encoded address in bytes.

writeUint

RLP encodes a uint.

function writeUint(uint256 _in) internal pure returns (bytes memory);

Parameters

NameTypeDescription
_inuint256The uint256 to encode.

Returns

NameTypeDescription
<none>bytesThe RLP encoded uint256 in bytes.

writeBool

RLP encodes a bool.

function writeBool(bool _in) internal pure returns (bytes memory);

Parameters

NameTypeDescription
_inboolThe bool to encode.

Returns

NameTypeDescription
<none>bytesThe RLP encoded bool in bytes.

_writeLength

Encode the first byte and then the len in binary form if length is more than 55.

function _writeLength(uint256 _len, uint256 _offset) private pure returns (bytes memory);

Parameters

NameTypeDescription
_lenuint256The length of the string or the payload.
_offsetuint256128 if item is string, 192 if item is list.

Returns

NameTypeDescription
<none>bytesRLP encoded bytes.

_toBinary

Encode integer in big endian binary form with no leading zeroes.

function _toBinary(uint256 _x) private pure returns (bytes memory);

Parameters

NameTypeDescription
_xuint256The integer to encode.

Returns

NameTypeDescription
<none>bytesRLP encoded bytes.

_memcpy

Copies a piece of memory to another location.

Note: https://github.com/Arachnid/solidity-stringutils

function _memcpy(uint256 _dest, uint256 _src, uint256 _len) private pure;

Parameters

NameTypeDescription
_destuint256Destination location.
_srcuint256Source location.
_lenuint256Length of memory to copy.

_flatten

Flattens a list of byte strings into one byte string.

Note: https://github.com/sammayo/solidity-rlp-encoder

function _flatten(bytes[] memory _list) private pure returns (bytes memory);

Parameters

NameTypeDescription
_listbytes[]List of byte strings to flatten.

Returns

NameTypeDescription
<none>bytesThe flattened byte string.