Skip to content

Commit bf8494e

Browse files
lispcVelaciela
andauthored
chore: openvm v2 (#252)
* chore(openvm): v1.6.0 * clean axiom * fixed * update exe commit * fmt * fix some sec issues * update exe commit * exe comm * openvm v2.1 * fix sol * fix sol * fix perf * update * chore: upgrade openvm to 2d21d630 - cargo update -p openvm - rebuild guest assets (chunk/batch/bundle commitments + verifier) - test-single-chunk and test-e2e-bundle pass * chore: upgrade openvm to 64bfcb2a and simplify execute_guest - cargo update -p openvm (now at 64bfcb2a; stark-backend at 27bb74b9) - adapt to renamed SystemConfig::segmentation_limits - simplify execute_guest using Sdk::compile_metered_cost / execute_compiled_metered_cost and Sdk::execute, now safe because upstream fixed inventory lifetime in compiled instances - cargo check passes * chore: upgrade OpenVM to develop-v2.0.0-rc.3 - Update Cargo.toml/Cargo.lock to OpenVM develop-v2.0.0-rc.3. - Adapt deferral API: MultiDeferralCircuitProver, DeferralAggProver, SupportedDeferral::VerifyStark, and Sdk builder hooks. - Fix verify_stark expected public-values format in crates/types/circuit/src/lib.rs (low u8 limbs, not u32 le bytes). - Fix deferral circuit memory layout to use parent VM config. - Regenerate all guest assets (chunk/batch/bundle app.vmexe) and EVM verifier. - Update AGENTS.md and migration docs for rc.3 build/test commands. Tested: - GPU=1 make test-e2e-batch - GPU=1 make test-e2e-bundle - GPU=1 make test-multi-chunk - CUDA_VISIBLE_DEVICES=2 GPU=1 make test-single-chunk * fix: address review findings for OpenVM rc.3 upgrade - Fix root_verifier_vk release artifact to use bundle SDK's agg_vk instead of the generic AGG_STARK_PROVING_KEY. - Add explicit doc comment explaining STARK vs EVM commitment checks. - Replace host-side verify_proof panic with unimplemented! + comment. - Validate all child proof baselines match in compute_deferral_data. - Replace magic 21 with MAX_APP_LOG_STACKED_HEIGHT in build-guest. - Add bounds check for deferral address space indexing. - Use u64::MAX sentinel for metered-execution fallback cycle count. - Fix stale doc comment link for gen_proof_snark. - Correct migration doc API/TOML descriptions and build commands. - Fix README branch reference and AGENTS.md leaf_fri_params note. All integration tests re-passed after regenerating assets. * style: cargo fmt * ci: align lint/clippy and release workflows with rust-toolchain nightly-2025-11-20 * fix: clippy warnings for rc.3 toolchain * fix: clippy unnecessary unwrap in build-guest * chore: bump openvm to v2.0.0 and regenerate guest assets via docker * style: cargo fmt * fix: remove useless conversion for clippy --------- Co-authored-by: Velaciela <git.rover@outlook.com>
1 parent 5de3d67 commit bf8494e

60 files changed

Lines changed: 4955 additions & 3519 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@ docs
1616
*.yml
1717

1818
*.sh
19-
2019
*.log
2120
*.md
2221

2322
openvm-clippy
2423

2524
target
25+
26+
# Large sub-project build artifacts that are not needed inside the guest builder
27+
sp1/target
28+
zisk/target
29+
zisk/releases
30+
31+
# Performance data files
32+
perf
33+
34+
# Git metadata
35+
.git

.github/workflows/build-guest-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Install Rust nightly toolchain
2525
uses: actions-rs/toolchain@v1
2626
with:
27-
toolchain: nightly-2025-08-18
27+
toolchain: nightly-2025-11-20
2828
target: x86_64-unknown-linux-gnu
2929
components: rust-src
3030
override: true

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040

4141
- uses: dtolnay/rust-toolchain@56f84321dbccf38fb67ce29ab63e4754056677e0
4242
with:
43-
toolchain: nightly-2025-08-18
43+
toolchain: nightly-2025-11-20
4444
components: rustfmt
4545

4646
- name: Cargo fmt
@@ -66,8 +66,8 @@ jobs:
6666

6767
- uses: dtolnay/rust-toolchain@56f84321dbccf38fb67ce29ab63e4754056677e0
6868
with:
69-
toolchain: nightly-2025-08-18
70-
components: clippy
69+
toolchain: nightly-2025-11-20
70+
components: clippy, rust-src
7171

7272
- name: Clippy
7373
run: make clippy

.github/workflows/profile-guest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Setup rust
3131
uses: dtolnay/rust-toolchain@56f84321dbccf38fb67ce29ab63e4754056677e0
3232
with:
33-
toolchain: nightly-2025-08-18
33+
toolchain: nightly-2025-11-20
3434

3535
- name: Guest profiling to capture total_cycles
3636
id: guest-profiling

AGENTS.md

Lines changed: 93 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,50 @@ Critical context for AI agents working on this repo. Read this before making cha
1313

1414
## OpenVM Version Sensitivity
1515

16-
This project uses **OpenVM** as its ZKVM. Guest executables (`.vmexe`) and host code **must be built from the exact same OpenVM version**. Even a minor version bump can change:
16+
This project uses **OpenVM v2.0.0** as its ZKVM. Guest executables (`.vmexe`) and host code **must be built from the exact same OpenVM version**. Even a minor version bump can change:
1717

1818
- The guest/host data layout (hint streams, public inputs)
19-
- The `root_verifier.asm` format
20-
- The Halo2 SRS degree requirement (e.g. `k=23``k=24`)
19+
- The Halo2 SRS degree requirement
2120
- The EVM verifier contract ABI
22-
- Field algebra APIs (`from_canonical_u32``from_int`)
23-
- ECC constructor signatures (some became `unsafe`)
21+
- Field algebra APIs
22+
- ECC constructor signatures
23+
24+
### How to update OpenVM dependencies correctly
25+
26+
OpenVM is declared as a **git dependency** (`tag = "v2.0.0"`) in `Cargo.toml`, and the exact commit is also pinned in `Cargo.lock`. The `openvm-org/openvm.git` and `openvm-org/stark-backend.git` entries MUST stay on matching tags — `openvm`'s own `Cargo.toml` pins a specific `stark-backend` tag, and a mismatch produces duplicate-registry / type-mismatch errors. Because the tag is immutable, the declared ref and the locked commit should always agree. The real hazard is a bare `cargo update`: it will **not** change the OpenVM tag, but it will bump unrelated crates.io packages (e.g. `alloy`, `revm`) which often break compatibility with the `scroll-tech/reth` and `sbv` forks.
27+
28+
**Do NOT run a global `cargo update` unless you are prepared to upgrade the entire `alloy`/`revm`/`reth`/`sbv` dependency chain together.**
29+
30+
To move to a newer OpenVM tag, retarget every `openvm-org/openvm.git` and `openvm-org/stark-backend.git` entry in `Cargo.toml` to the new tag, then refresh only those git sources — `cargo metadata` is enough — rather than a global `cargo update`. Verify with `git diff Cargo.lock` that no other package's version/source changed. Then rebuild guests and run tests as described below.
2431

2532
### After ANY OpenVM version upgrade, you MUST:
2633

2734
1. **Update the hardcoded version string** in `crates/build-guest/src/verifier.rs`:
2835
```rust
29-
let openvm_version = "v1.6"; // MUST match Cargo.toml git rev
36+
let solidity_sdk_tag = "v2.0"; // MUST match openvm-solidity-sdk tag
37+
let verifier_path = "v2.0-deferral"; // bundle/deferral verifier
3038
```
3139

3240
2. **Force-rebuild ALL guest assets** (auto mode skips existing files):
3341
```bash
34-
cargo run --release -p scroll-zkvm-build-guest -- --mode force
42+
# Local build
43+
OPENVM_RUST_TOOLCHAIN=nightly-2025-11-20 cargo run --release -p scroll-zkvm-build-guest -- --mode force
44+
45+
# Docker build (matches CI)
46+
OPENVM_RUST_TOOLCHAIN=nightly-2025-11-20 make build-guest
3547
```
36-
This regenerates: `app.elf`, `app.vmexe`, `root_verifier.asm`, commitment `.rs` files, and `openVmVk.json`.
48+
This regenerates: `app.elf`, `app.vmexe`, commitment `.rs` files, `openVmVk.json`,
49+
and the EVM verifier (`verifier.sol` + `verifier.bin`).
50+
51+
> The default `RECOMPUTE_MODE=auto` tries to download the Solidity verifier from
52+
> `openvm-solidity-sdk` and compiles it locally with `solc` to produce `verifier.bin`.
53+
> If the download fails, it falls back to the full local OpenVM verifier generation.
54+
> `RECOMPUTE_MODE=yes` skips the download and always generates the verifier locally;
55+
> `RECOMPUTE_MODE=no` forces download-only and fails if no pre-built verifier is available.
56+
57+
> Building `batch` or `bundle` requires the SDK of the previous circuit
58+
> (`batch` needs `chunk`, `bundle` needs `batch`). Always build in a single
59+
> `force` run so dependencies are generated in the correct order.
3760
3861
3. **Verify commitments were updated** — check that `*_exe_commit.rs` and `*_vm_commit.rs` files changed, and that `openVmVk.json` timestamps are fresh.
3962

@@ -44,8 +67,7 @@ This project uses **OpenVM** as its ZKVM. Guest executables (`.vmexe`) and host
4467
These are cached proving keys. They are **not** automatically invalidated on version bumps.
4568

4669
5. **Check SRS params** in `~/.openvm/params/`:
47-
- OpenVM v1.5.0+ requires `kzg_bn254_24.srs` (2 GB)
48-
- Earlier versions used `kzg_bn254_23.srs` (1 GB)
70+
- OpenVM v2.0.0 requires `kzg_bn254_24.srs` (2 GB)
4971
- If the file is empty/corrupted, replace it (check for `.1` or `.part` suffixes from interrupted downloads)
5072

5173
6. **Clear test output cache** before re-running integration tests:
@@ -60,42 +82,96 @@ This project uses **OpenVM** as its ZKVM. Guest executables (`.vmexe`) and host
6082
```
6183
assertion left == right failed (left: 21, right: 1)
6284
```
63-
**Cause**: Stale guest assets (`app.vmexe` or `root_verifier.asm`) from a previous OpenVM version.
85+
**Cause**: Stale guest assets (`app.vmexe`) from a previous OpenVM version.
6486
**Fix**: Follow all 6 steps above.
6587

6688
### `UnexpectedEof` in `CacheHalo2ParamsReader::read_params`
6789
```
6890
UnexpectedEof: failed to fill whole buffer
6991
```
70-
**Cause**: `~/.openvm/params/kzg_bn254_24.srs` is missing, empty, or truncated.
92+
**Cause**: `~/.openvm/params/kzg_bn254_24.srs` is missing, empty, or truncated.
7193
**Fix**: Ensure a valid 2 GB SRS file exists at that exact path.
7294

95+
### `ProofVerificationFailed()` (Solidity error `0xd611c318`)
96+
**Cause**: The EVM verifier was generated with a different circuit config than the proof.
97+
This happens when:
98+
- The verifier was built with `RECOMPUTE_MODE=no` but the downloaded verifier is missing, stale, or has empty bytecode
99+
- The verifier was built **without** the deferral prover, but the proof uses deferral (batch/bundle)
100+
- The verifier's `AggregationTreeConfig` does not match the prover's (`num_children_internal/leaf`)
101+
102+
**Fix**: Regenerate with:
103+
```bash
104+
OPENVM_RUST_TOOLCHAIN=nightly-2025-11-20 cargo run --release -p scroll-zkvm-build-guest -- --mode force
105+
```
106+
(The default `auto` mode will fall back to local generation if the download fails; use `RECOMPUTE_MODE=yes` to force local generation immediately.)
107+
108+
### `cargo update` breaks compilation with alloy/revm type mismatches
109+
**Symptoms**: Errors like `missing verify_and_compute_signer_unchecked in implementation` (alloy) or `mismatched types` between `revm_primitives::hardfork::SpecId` and `SpecId` (revm).
110+
**Cause**: A global `cargo update` bumps `alloy` to 1.8.x and `revm` to 30.2.0, but the `scroll-tech/reth` and `sbv` forks were built against older versions. The `[patch.crates-io]` table pins `revm` to `scroll-v91` (30.1.1), which no longer satisfies the newer `alloy-evm` requirements, leading to duplicate registry versions of `revm-handler` / `revm-primitives` in the dependency graph.
111+
**Fix**: Restore the original `Cargo.lock` (`git checkout HEAD -- Cargo.lock`) and update only what you actually need (e.g. `cargo metadata` scoped to the OpenVM git sources).
112+
73113
### Docker build fails with stale CID
74114
The `build-guest.sh` script may fail if a stale `build-guest.cid` file exists. Use local build (`cargo run -p scroll-zkvm-build-guest`) as fallback.
75115

76116
## Build & Test Commands
77117

78118
```bash
79-
# Force rebuild all guest assets (required after OpenVM upgrade)
80-
cargo run --release -p scroll-zkvm-build-guest -- --mode force
119+
# Force rebuild all guest assets (required after OpenVM upgrade).
120+
# Default RECOMPUTE_MODE=auto falls back to local generation if the download fails.
121+
# Use RECOMPUTE_MODE=yes to skip the download and force local generation.
122+
OPENVM_RUST_TOOLCHAIN=nightly-2025-11-20 cargo run --release -p scroll-zkvm-build-guest -- --mode force
81123

82124
# Run end-to-end tests (ALWAYS use make, never raw cargo test)
83125
GPU=1 make test-e2e-bundle
84126
GPU=1 make test-e2e-batch
85-
GPU=1 make test-e2e-chunk
127+
GPU=1 make test-single-chunk
128+
GPU=1 make test-multi-chunk
86129
```
87130

88131
**⚠️ CRITICAL: Always use `make` for integration tests.**
89132
The Makefile sets `RUST_MIN_STACK=16777216` (16 MB) and `CARGO_CONFIG_FLAG`. Running `cargo test` directly skips both, which causes:
90133
- Stack overflow during prover initialization (default Rust stack is only ~2 MB)
91134
- Missing CUDA features if `GPU=1` is set but `--features scroll-zkvm-integration/cuda` is not passed
92135

136+
**⚠️ CRITICAL: Use `--release` for any test that exercises halo2 verifier generation.**
137+
The `test_verifier` test in `scroll-zkvm-build-guest` builds the full bundle SDK and runs
138+
`generate_halo2_verifier_solidity()`. In debug mode this is orders of magnitude slower and
139+
can waste hours of CPU time. Always run it as:
140+
```bash
141+
cargo test --release -p scroll-zkvm-build-guest test_verifier
142+
```
143+
144+
## Deferral Model (OpenVM v2+)
145+
146+
OpenVM v2 replaces the traditional root-verifier recursion with a **deferred compute model**:
147+
148+
- **Chunk** (leaf circuit, 42 AIRs): no deferral
149+
- **Batch** (aggregation, 44 AIRs): defers child STARK verification to the root
150+
- **Bundle** (aggregation, 44 AIRs): defers child STARK verification to the root
151+
152+
The extra 2 AIRs in batch/bundle come from the deferral extension.
153+
154+
### Deferral circuit must use the parent VM's memory layout
155+
156+
The `MultiDeferralCircuitProver` (verify-stark deferral circuit) is constructed from the **child's aggregation VK**, but its `memory_dimensions` and `num_user_pvs` must come from the **parent's VM config** (the batch or bundle circuit that calls `verify_stark`). Using the child's config causes the deferral circuit to write public values to the wrong location in the parent VM, leading to `Proof verification failed for commit ...` inside the batch/bundle guest.
157+
158+
### Key configuration that must match between prover and verifier
159+
160+
| Parameter | Prover (`crates/prover/src/prover/mod.rs`) | Verifier (`crates/build-guest/src/main.rs`) |
161+
|-----------|---------------------------------------------|---------------------------------------------|
162+
| `AggregationTreeConfig` | `num_children_internal: 3, num_children_leaf: 4` | Same |
163+
| `MultiDeferralCircuitProver` | Built from child SDK in `enable_deferral()` | Built from batch SDK in `generate_evm_verifier()` |
164+
| `agg_params` | `leaf_params + internal_params` (100-bit security) | Same |
165+
166+
If any of these mismatch, the EVM verifier will reject proofs with `ProofVerificationFailed()`.
167+
93168
## Important File Paths
94169

95170
| File / Dir | Purpose |
96171
|------------|---------|
97172
| `releases/dev/{chunk,batch,bundle}/app.vmexe` | Guest executables |
98173
| `releases/dev/verifier/openVmVk.json` | Program commitments loaded by integration tests |
174+
| `releases/dev/verifier/verifier.bin` | EVM verifier bytecode |
99175
| `crates/circuits/*-circuit/openvm.toml` | Guest VM configs (FRI params, PoW bits) |
100176
| `crates/circuits/*-circuit/commitments.rs` | Hardcoded commitment arrays |
101177
| `~/.openvm/params/kzg_bn254_24.srs` | Halo2 KZG SRS (2 GB) |
@@ -105,5 +181,5 @@ The Makefile sets `RUST_MIN_STACK=16777216` (16 MB) and `CARGO_CONFIG_FLAG`. Run
105181
## Guest Config Notes
106182

107183
- `chunk-circuit`: requires `system.config.continuation_enabled = true`
108-
- `batch-circuit` / `bundle-circuit`: include `leaf_fri_params` with `num_queries = 193`, `commit_proof_of_work_bits = 20`
109-
- FRI params format changed in OpenVM 1.6.0: `proof_of_work_bits` `commit_proof_of_work_bits` + `query_proof_of_work_bits`
184+
- `batch-circuit` / `bundle-circuit`: aggregation FRI params are supplied in code via `AggregationConfig { params: default_agg_params() }`; the checked-in `openvm.toml` files do not contain `leaf_fri_params`
185+
- FRI params format in OpenVM v2: `commit_proof_of_work_bits` + `query_proof_of_work_bits`

0 commit comments

Comments
 (0)