Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rlp.ParseTree() #82

Closed
wants to merge 2 commits into from
Closed

feat: rlp.ParseTree() #82

wants to merge 2 commits into from

Conversation

ARR4N
Copy link
Collaborator

@ARR4N ARR4N commented Dec 6, 2024

Why this should be merged

The types.Header fields of both coreth and subnet-evm have been modified such that their RLP encodings (i.e. block hashes) aren't compatible with vanilla geth nor each other. Supporting both coreth and subnet-evm (let alone backwards compatibility) via "passive" modification of RLP (i.e. by modifying fields) is proving to be extremely difficult, if not impossible. This PR is the first step towards an active, and therefore controlled, approach.

How this works

The (R)ecursive element of RLP allows it to be readily parsed into a tree, which is introduced as the rlp.ParseTree([]byte) ItemNode function. The only node types are the so-called "items" of byte arrays (also called "strings"), positive integers, and lists of other items. The parser is implemented in rlp/tree.libevm.go, which should be reviewed first.

The intent is that libevm-style extra payloads will have RLP hooks that manipulate trees after encoding (to add their own items and remove unused ones) and before decoding (to invert the encoding changes). A follow-up PR will add re-encoding of trees.

How this was tested

Tree parsing is run against all existing RLP-encoding tests merely to ensure no errors. A more comprehensive set of fuzz tests builds trees and concrete values n parallel, ensuring that the former is recoverable via rlp.ParseTree(rlp.EncodeToBytes([concrete values])). I originally tried to build trees directly from the upstream test inputs but there were so many edge cases that the test logic was no longer reliable.

A fuzzed types.Header is also parsed, resulting in an RLP "list". As this is the first step in sensitive changes to header encoding, a change-detector test is introduced to lock in backwards compatibility even though no changes are made yet.

@ARR4N ARR4N marked this pull request as ready for review December 6, 2024 16:48
@ARR4N ARR4N requested review from a team, darioush, ceyonur and michaelkaplan13 and removed request for a team December 6, 2024 16:48
@ARR4N
Copy link
Collaborator Author

ARR4N commented Dec 12, 2024

Closing as superseded by #89.

@ARR4N ARR4N closed this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant