-
Notifications
You must be signed in to change notification settings - Fork 118
chore(l2): implement rkyv traits for Node, serialize them directly into the prover guest program instead of its RLP encoding
#5224
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the execution witness mechanism to serialize trie Node structures directly using rkyv instead of their RLP-encoded representations. The key changes include implementing rkyv serialization traits for all trie node types, replacing the nodes_hashed field with embedded state_trie and storage_trie_roots, and updating the witness generation and consumption logic throughout the codebase.
Key Changes
- Implemented rkyv serialization traits for
Node,NodeRef,NodeHash,BranchNode,ExtensionNode,LeafNode, andNibbles - Replaced RLP-encoded node storage with direct
Nodeserialization inExecutionWitnessandGuestProgramState - Refactored execution witness generation to build embedded trie structures and removed the need for trie rebuilding logic
Reviewed Changes
Copilot reviewed 18 out of 21 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/vm/witness_db.rs | Improved error messages to include actual error details instead of generic messages |
| crates/networking/rpc/debug/execution_witness.rs | Changed From to TryFrom for witness conversion and added trie embedding logic |
| crates/l2/networking/rpc/l2/execution_witness.rs | Updated to use TryFrom with proper error handling |
| crates/common/types/block_execution_witness.rs | Replaced nodes_hashed with state_trie and storage_trie_roots, removed trie rebuild logic |
| crates/l2/prover/src/guest_program/src/execution.rs | Updated to use embedded state trie directly |
| crates/common/trie/*.rs | Added rkyv trait implementations and utility methods for embedded tries |
| crates/blockchain/blockchain.rs | Updated witness generation to create embedded trie structures |
| Cargo.lock files | Added rkyv dependency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Benchmark for 6a58c9aClick to view benchmark
|
Benchmark for dd8fe10Click to view benchmark
|
Benchmark for bbb11fbClick to view benchmark
|
Benchmark for 13e1514Click to view benchmark
|
Benchmark for e550313Click to view benchmark
|
Benchmark for 8f498adClick to view benchmark
|
Benchmark for 8bc6100Click to view benchmark
|
Benchmark for 9c97c2cClick to view benchmark
|
Benchmark for 34853c1Click to view benchmark
|
Motivation
Directly deserializing the
Nodestruct in the prover's guest program allows skipping RLP decoding and resolving the subtries (this is, converting the list of nodes into the tree structure). Though this comes at a cost:memcpyfor unsized types (like vectors of structs, in this caseVec<Node>).Even considering these, the net change is negative: 697k cycles -> 533k cycles, 24% reduction.
This PR also removes the double hashing of nodes (previously we were hashing once at the start and then hashing again to populate the hash cache of each node)
Description
rkyvtraits forNodeand other relevant typesNodeinstead of encoded nodes.Flamegraphs
before:


after: