Skip to content

Conversation

@ilitteri
Copy link
Contributor

@ilitteri ilitteri commented Oct 23, 2025

Motivation

We want to persist batch prover inputs to avoid having to regenerate them in case of an unexpected shutdown. We also want to store the version of the binary that generated them to be able to prove yet-unproven batches from older ethrex versions.

Description

This PR:

  • Extends the L2 store functionality to support storing and retrieving batch prover inputs.
  • For the SQL store, a new table batch_prover_input is created with rows prover_input (actual rkyv-encoded ProverInputData), batch_number, and prover_version, being the tuple of the last two the primary key.
  • For the in-memory store, a new hash map batch_prover_input is created with key (batch_number, prover_version) and value witness (actual rkyv-encoded ProverInputData).
  • The committer now generates and stores the batch prover inputs in the L2 store.
  • The proof coordinator now retrieves the batch prover inputs from the L2 store.
  • ProverInputData is moved to the ethrex-l2-common crate, as it is now a common data structure between different crates.
  • The prover client now requests batch prover input data specifying both batch number and binary version.

Future work

With this new feature, an older prover should be able to retrieve data from an upgraded sequencer, as long as there are batches to be proven in that version. Currently it rejects any request from a different version.

@ilitteri ilitteri self-assigned this Oct 23, 2025
@github-actions github-actions bot added the L2 Rollup client label Oct 23, 2025
@github-actions
Copy link

github-actions bot commented Oct 23, 2025

Lines of code report

Total lines added: 251
Total lines removed: 111
Total lines changed: 362

Detailed view
+----------------------------------------------------+-------+------+
| File                                               | Lines | Diff |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/common/src/prover.rs              | 127   | +17  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/errors.rs               | 356   | +4   |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/l1_committer.rs         | 781   | +59  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/mod.rs                  | 222   | -2   |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/proof_coordinator.rs    | 482   | -109 |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/utils.rs                | 178   | +38  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/api.rs                | 120   | +11  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store.rs              | 311   | +19  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store_db/in_memory.rs | 327   | +39  |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/storage/src/store_db/sql.rs       | 853   | +64  |
+----------------------------------------------------+-------+------+

@ilitteri ilitteri changed the title feat(l2): generate batch witness at commit and store it in db feat(l2): generate batch prover input at commit and store it in db Oct 23, 2025
@ilitteri ilitteri marked this pull request as ready for review October 23, 2025 05:47
@ilitteri ilitteri requested a review from a team as a code owner October 23, 2025 05:47
Copilot AI review requested due to automatic review settings October 23, 2025 05:47
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 adds functionality to persist batch prover inputs to the L2 store, enabling recovery after unexpected shutdowns and supporting proofs for batches from older ethrex versions.

Key Changes:

  • Added database schema and storage layer methods to store/retrieve batch prover inputs keyed by batch number and prover version
  • Moved ProverInputData to ethrex-l2-common crate for cross-crate usage
  • Modified the committer to generate and persist batch prover inputs during commit operations
  • Updated the proof coordinator to retrieve prover inputs from storage instead of regenerating them

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/l2/storage/src/store_db/sql.rs Adds SQL table schema and implementation for storing/retrieving batch prover inputs
crates/l2/storage/src/store_db/in_memory.rs Adds in-memory storage implementation for batch prover inputs
crates/l2/storage/src/store.rs Adds public API methods for storing/retrieving batch prover inputs
crates/l2/storage/src/api.rs Defines trait methods for batch prover input operations
crates/l2/storage/Cargo.toml Adds rkyv dependency for serialization
crates/l2/sequencer/utils.rs Adds utility function to fetch blocks for a given batch
crates/l2/sequencer/proof_coordinator.rs Removes prover input generation logic and retrieves inputs from storage instead
crates/l2/sequencer/mod.rs Removes unused dependencies from ProofCoordinator::spawn
crates/l2/sequencer/l1_committer.rs Adds batch prover input generation and storage during commit operations
crates/l2/sequencer/errors.rs Adds new error variants for missing prover inputs and witness generation failures
crates/l2/prover/src/prover.rs Updates batch request to include binary version
crates/l2/l2.rs Adds constants module
crates/l2/constants.rs Defines binary version constant from package version
crates/l2/common/src/prover.rs Moves ProverInputData definition here and adds rkyv serialization support
crates/l2/common/Cargo.toml Adds rkyv and serde_with dependencies

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

prover_input: ProverInputData,
) -> Result<(), RollupStoreError> {
let witness_bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&prover_input)
.map_err(|e| RollupStoreError::Custom(format!("Failed to serialize witness: {}", e)))?
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message says 'witness' but should say 'prover input' to match the actual data being serialized (ProverInputData).

Copilot uses AI. Check for mistakes.
@ilitteri ilitteri added this pull request to the merge queue Oct 23, 2025
Merged via the queue into main with commit 417aafc Oct 23, 2025
41 checks passed
@ilitteri ilitteri deleted the store_batch_witness_in_db branch October 23, 2025 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L2 Rollup client

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants