Skip to content

Conversation

@fakedev9999
Copy link
Member

Summary

Adds witness caching to skip the 2-hour witness generation bottleneck in multi.rs and cost_estimator scripts. Cache files are saved to data/{chain_id}/witness-cache/{start_block}-{end_block}.bin using rkyv serialization.

Changes

  • New witness_cache module with save/load/exists functions supporting conditional EigenDA compilation
  • Three cache flags: --cache (recommended), --use-cache (load only), --save-cache (force regenerate)
  • Integration in multi.rs and cost_estimator with per-range caching
  • Comprehensive documentation on cache usage, location, and DA compatibility
  • Cache files are NOT compatible across DA types (Ethereum/Celestia vs EigenDA)

Testing

Run multi or cost_estimator with --cache flag to test caching behavior. Verify cache files are created at expected location.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 14, 2026

Metric Value
Batch Start 13,311,208
Batch End 13,311,213
Witness Generation (seconds) 0
Execution Duration (seconds) 15
Total Instruction Count 307,362,825
Oracle Verify Cycles 26,575,095
Derivation Cycles 219,040,686
Block Execution Cycles 7,097,038
Blob Verification Cycles 23,426,232
Total SP1 Gas 497,528,064
Number of Blocks 5
Number of Transactions 5
Ethereum Gas Used 242,290
Cycles per Block 61,472,565
Cycles per Transaction 61,472,565
Transactions per Block 1
Gas Used per Block 48,458
Gas Used per Transaction 48,458
BN Pair Cycles 0
BN Add Cycles 0
BN Mul Cycles 0
KZG Eval Cycles 0
EC Recover Cycles 0
P256 Verify Cycles 0

Add witness caching to reduce 2-hour bottleneck in multi.rs and cost_estimator scripts.
Cache WitnessData (not SP1Stdin) to disk with keys (chain_id, start_block, end_block).

New features:
- Witness cache module with save/load functions using rkyv serialization
- cfg_if conditional compilation for EigenDA support
- Three cache flags: --cache (default), --use-cache (load only), --save-cache (force regenerate)
- Multi-script integration with cache status messages
- Cost estimator parallel cache loads per batch range
- Comprehensive documentation on cache usage and management

Cache location: data/{chain_id}/witness-cache/{start_block}-{end_block}.bin
DA compatibility: Ethereum/Celestia compatible, EigenDA separate cache

Files changed:
- utils/host/src/witness_cache.rs (NEW)
- utils/host/src/lib.rs, Cargo.toml
- scripts/utils/src/lib.rs
- scripts/prove/bin/multi.rs
- scripts/utils/bin/cost_estimator.rs
- book/advanced/cost-estimation-tools.md (renamed from cost-estimator.md)
- book/SUMMARY.md
@fakedev9999 fakedev9999 force-pushed the fakedev9999/cache-proving-input branch from 7d51eaa to b2a2f7a Compare January 14, 2026 06:15
@fakedev9999 fakedev9999 changed the title Add witness caching for faster multi and cost_estimator runs feat(scripts): add witness caching for multi and cost_estimator Jan 14, 2026
- Add SP1Stdin cache functions using bincode (DA-agnostic)
- cost_estimator.rs now caches SP1Stdin instead of WitnessData
- Remove WitnessDataType type constraint that caused CI failures
- Fix race condition in multi.rs by using match pattern with graceful fallback

SP1Stdin is the same type regardless of which DA witness generator
produced it, so it works with generic host types. This fixes the CI
type mismatch error when running with --features celestia/eigenda.
Switch both multi.rs and cost_estimator.rs to use SP1Stdin caching
instead of WitnessData caching. This fixes CI failures when running
with different DA feature flags (celestia, eigenda).

SP1Stdin is DA-agnostic - it's the same type regardless of which
witness generator produced it. This means cache files now work across
all DA types (Ethereum, Celestia, EigenDA).

Changes:
- Update multi.rs to cache SP1Stdin using bincode
- Simplify witness_cache.rs to only contain SP1Stdin functions
- Remove eigenda feature flag from utils/host (no longer needed)
- Update documentation to reflect SP1Stdin caching
- Use tracing macros instead of println/eprintln in multi.rs
- Fix DA compatibility docs: clarify that cache files are compatible
  between Ethereum ↔ Celestia, but NOT with EigenDA
- Simplify cache flags: remove --use-cache and --save-cache,
  keep only --cache for simpler UX
Copy link
Collaborator

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

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

@fakedev9999 fakedev9999 merged commit 7bfa643 into main Jan 30, 2026
28 checks passed
@fakedev9999 fakedev9999 deleted the fakedev9999/cache-proving-input branch January 30, 2026 11:59
@github-actions
Copy link
Contributor

The backport to v3.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-v3.x v3.x
# Navigate to the new working tree
cd .worktrees/backport-v3.x
# Create a new branch
git switch --create backport-776-to-v3.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 7bfa64372cea807e7547e8afc8a9778be40c079e
# Push it to GitHub
git push --set-upstream origin backport-776-to-v3.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-v3.x

Then, create a pull request where the base branch is v3.x and the compare/head branch is backport-776-to-v3.x.

fakedev9999 added a commit that referenced this pull request Jan 30, 2026
* feat(witness-cache): add caching for witness generation

Add witness caching to reduce 2-hour bottleneck in multi.rs and cost_estimator scripts.
Cache WitnessData (not SP1Stdin) to disk with keys (chain_id, start_block, end_block).

New features:
- Witness cache module with save/load functions using rkyv serialization
- cfg_if conditional compilation for EigenDA support
- Three cache flags: --cache (default), --use-cache (load only), --save-cache (force regenerate)
- Multi-script integration with cache status messages
- Cost estimator parallel cache loads per batch range
- Comprehensive documentation on cache usage and management

Cache location: data/{chain_id}/witness-cache/{start_block}-{end_block}.bin
DA compatibility: Ethereum/Celestia compatible, EigenDA separate cache

Files changed:
- utils/host/src/witness_cache.rs (NEW)
- utils/host/src/lib.rs, Cargo.toml
- scripts/utils/src/lib.rs
- scripts/prove/bin/multi.rs
- scripts/utils/bin/cost_estimator.rs
- book/advanced/cost-estimation-tools.md (renamed from cost-estimator.md)
- book/SUMMARY.md

* fix(witness-cache): use SP1Stdin caching for cost_estimator to fix CI

- Add SP1Stdin cache functions using bincode (DA-agnostic)
- cost_estimator.rs now caches SP1Stdin instead of WitnessData
- Remove WitnessDataType type constraint that caused CI failures
- Fix race condition in multi.rs by using match pattern with graceful fallback

SP1Stdin is the same type regardless of which DA witness generator
produced it, so it works with generic host types. This fixes the CI
type mismatch error when running with --features celestia/eigenda.

* refactor(witness-cache): unify on SP1Stdin caching for DA-agnosticism

Switch both multi.rs and cost_estimator.rs to use SP1Stdin caching
instead of WitnessData caching. This fixes CI failures when running
with different DA feature flags (celestia, eigenda).

SP1Stdin is DA-agnostic - it's the same type regardless of which
witness generator produced it. This means cache files now work across
all DA types (Ethereum, Celestia, EigenDA).

Changes:
- Update multi.rs to cache SP1Stdin using bincode
- Simplify witness_cache.rs to only contain SP1Stdin functions
- Remove eigenda feature flag from utils/host (no longer needed)
- Update documentation to reflect SP1Stdin caching

* refactor(witness-cache): address PR review comments

- Use tracing macros instead of println/eprintln in multi.rs
- Fix DA compatibility docs: clarify that cache files are compatible
  between Ethereum ↔ Celestia, but NOT with EigenDA
- Simplify cache flags: remove --use-cache and --save-cache,
  keep only --cache for simpler UX

(cherry picked from commit 7bfa643)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants