Skip to content

Conversation

@xqft
Copy link
Contributor

@xqft xqft commented Nov 6, 2025

Motivation

Directly deserializing the Node struct 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:

  1. Now we need to encode the nodes to hash them
  2. Now deserialization is a lot more expensive because rkyv calls a memcpy for unsized types (like vectors of structs, in this case Vec<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

  • implements the rkyv traits for Node and other relevant types
  • changes the execution witness to contain a list of Node instead of encoded nodes.
  • misc. needed refactors to adapt the new execution witness

Flamegraphs

before:
image
after:
image

Copilot AI review requested due to automatic review settings November 11, 2025 14:14
Copilot finished reviewing on behalf of xqft November 11, 2025 14:16
Copy link
Contributor

Copilot AI left a 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, and Nibbles
  • Replaced RLP-encoded node storage with direct Node serialization in ExecutionWitness and GuestProgramState
  • 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.

@github-actions
Copy link

Benchmark for 6a58c9a

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 30.2±1.42ms 30.6±1.35ms +1.32%
Trie/cita-trie insert 1k 2.9±0.07ms 2.9±0.03ms 0.00%
Trie/ethrex-trie insert 10k 26.3±0.98ms 26.7±1.04ms +1.52%
Trie/ethrex-trie insert 1k 2.2±0.04ms 2.2±0.07ms 0.00%

@github-actions github-actions bot added the L2 Rollup client label Nov 11, 2025
@github-actions
Copy link

Benchmark for dd8fe10

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 29.3±2.01ms 28.0±0.94ms -4.44%
Trie/cita-trie insert 1k 2.9±0.02ms 2.9±0.14ms 0.00%
Trie/ethrex-trie insert 10k 27.3±1.07ms 24.9±0.83ms -8.79%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.01ms 0.00%

@github-actions
Copy link

Benchmark for bbb11fb

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 28.1±0.38ms 27.9±0.29ms -0.71%
Trie/cita-trie insert 1k 2.9±0.01ms 2.9±0.02ms 0.00%
Trie/ethrex-trie insert 10k 24.7±0.32ms 25.5±0.77ms +3.24%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.08ms 0.00%

@github-actions
Copy link

Benchmark for 13e1514

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 27.6±0.97ms 28.6±1.17ms +3.62%
Trie/cita-trie insert 1k 2.9±0.02ms 2.9±0.14ms 0.00%
Trie/ethrex-trie insert 10k 24.6±0.75ms 26.8±0.95ms +8.94%
Trie/ethrex-trie insert 1k 2.2±0.12ms 2.2±0.02ms 0.00%

@github-actions
Copy link

Benchmark for e550313

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 27.7±0.20ms 27.9±0.21ms +0.72%
Trie/cita-trie insert 1k 2.9±0.02ms 2.9±0.13ms 0.00%
Trie/ethrex-trie insert 10k 23.9±0.27ms 24.0±0.69ms +0.42%
Trie/ethrex-trie insert 1k 2.2±0.06ms 2.1±0.02ms -4.55%

@github-actions
Copy link

Benchmark for 8f498ad

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 27.9±0.35ms 27.6±0.30ms -1.08%
Trie/cita-trie insert 1k 2.9±0.01ms 2.9±0.09ms 0.00%
Trie/ethrex-trie insert 10k 24.7±0.60ms 25.3±0.34ms +2.43%
Trie/ethrex-trie insert 1k 2.2±0.03ms 2.2±0.01ms 0.00%

@github-actions
Copy link

Benchmark for 8bc6100

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 28.4±0.81ms 28.3±0.96ms -0.35%
Trie/cita-trie insert 1k 2.9±0.03ms 2.9±0.10ms 0.00%
Trie/ethrex-trie insert 10k 24.2±0.55ms 24.5±1.14ms +1.24%
Trie/ethrex-trie insert 1k 2.2±0.06ms 2.1±0.05ms -4.55%

@github-actions
Copy link

Benchmark for 9c97c2c

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 28.8±1.37ms 32.5±1.86ms +12.85%
Trie/cita-trie insert 1k 2.9±0.01ms 2.9±0.16ms 0.00%
Trie/ethrex-trie insert 10k 25.1±1.29ms 26.6±1.10ms +5.98%
Trie/ethrex-trie insert 1k 2.2±0.03ms 2.2±0.02ms 0.00%

@github-actions
Copy link

Benchmark for 34853c1

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 28.1±0.88ms 28.1±0.54ms 0.00%
Trie/cita-trie insert 1k 2.9±0.01ms 2.9±0.11ms 0.00%
Trie/ethrex-trie insert 10k 24.4±0.58ms 24.1±0.50ms -1.23%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.05ms 0.00%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L2 Rollup client

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants