Skip to content

feat(cheats): add RLP related cheats #11144

@0xClandestine

Description

@0xClandestine

Component

Forge

Describe the feature you would like

It would be useful imo to add RLP encoding/decoding related cheats, mirroring the functionality already available in cast via cast to-rlp and cast from-rlp. This would allow contracts to easily manage RLP data in tests without relying on external libraries or tooling.

/// @dev RLP encodes a list of `data` into an rlp payload.
function toRlp(bytes[] calldata data) public pure returns (bytes memory);
/// @dev RLP decodes an `rlp` payload into a list of `data`.
function fromRlp(bytes calldata rlp) public pure returns (bytes[] memory data);

Rather than bytes[] calldata data it may be cleaner to simply take in bytes calldata abiEncoded so usage becomes:

bytes memory rlpPayload = vm.toRlp(abi.encode(item0, item1, item2...));
(bytes item0, uint256 item1, address item2, ...) = abi.decode(vm.fromRlp(rlpPayload), (bytes, uint256, address);

Worth noting the abi.encode pattern might be annoying if you don't want to parse all elements.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions