Skip to content

Commit 75a0dea

Browse files
ethan-cryptoilluzenn13
authored
chore: support the new wormhole aggregation pipeline (#71)
* *adds support for the new wormhole aggregation pipeline *update and clean up deps * *quinn-proto 0.11.13 -> 0.11.14 * *invoke zk-circuit library builder and add skip prover option. * update deps, don't copy bins to chain * update known values * build circuits on cargo build * make it compile with updated metadata * support new storage proof structure * redirect git * added wormhole fuzz command * fuzz the secret too * update zk deps * clippy * update dilithium pair usage * deps updated * fix tests and git deps * fix cargo audit * new poseidon api * update hashing of leaf accounts * git deps * fix git deps * expose wormhole functions * fix ci - clippy * it compiles again * fmt * fix performance issue --------- Co-authored-by: illuzen <illuzen@users.noreply.github.com> Co-authored-by: Nikolaus Heger <nheger@gmail.com>
1 parent 93b6b2c commit 75a0dea

22 files changed

Lines changed: 1685 additions & 660 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/target
22
.idea
33
*.hex
4-
/generated-bins/prover.bin
4+
5+
# Circuit binaries are generated at build time by build.rs
6+
/generated-bins/

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,30 @@ subxt-metadata = "0.44"
7676

7777
# ZK proof generation (aligned with chain)
7878
anyhow = "1.0"
79+
7980
qp-wormhole-circuit = { version = "1.3.0", default-features = false, features = ["std"] }
8081
qp-wormhole-prover = { version = "1.3.0", default-features = false, features = ["std"] }
8182
qp-wormhole-verifier = { version = "1.3.0", default-features = false, features = ["std"] }
8283
qp-wormhole-aggregator = { version = "1.3.0", default-features = false, features = ["rayon", "std"] }
8384
qp-wormhole-inputs = { version = "1.3.0", default-features = false, features = ["std"] }
8485
qp-zk-circuits-common = { version = "1.3.0", default-features = false, features = ["std"] }
8586
qp-plonky2 = { version = "1.1.6", default-features = false, features = ["rand", "std"] }
87+
qp-wormhole-circuit-builder = { version = "1.3.0" }
88+
89+
90+
[build-dependencies]
91+
qp-wormhole-circuit-builder = { version = "1.3.0" }
8692

8793
[dev-dependencies]
8894
tempfile = "3.8.1"
8995
serial_test = "3.1"
90-
qp-wormhole-circuit-builder = { version = "1.2.1" }
96+
qp-poseidon-core = "1.4.0"
97+
98+
# Optimize build scripts and their dependencies in dev mode.
99+
# This is critical for circuit generation which is CPU-intensive.
100+
# Without this, circuit generation takes ~10 minutes instead of ~30 seconds.
101+
[profile.dev.build-override]
102+
opt-level = 3
103+
104+
[profile.release.build-override]
105+
opt-level = 3

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ quantus wormhole aggregate \
180180
```
181181

182182
- `--proofs`: One or more hex-encoded proof files. The number must not exceed `num_leaf_proofs` from the circuit config.
183-
- Before aggregation, the CLI verifies binary hashes from `generated-bins/config.json` to detect stale circuit binaries.
184183
- Displays timing for dummy proof generation and aggregation separately.
185184

186185
#### `quantus wormhole verify-aggregated`
@@ -250,23 +249,31 @@ Build ZK circuit binaries from the `qp-zk-circuits` repository, then copy them t
250249

251250
```bash
252251
quantus developer build-circuits \
253-
--branching-factor 2 \
254-
--depth 1 \
255-
--circuits-path ../qp-zk-circuits \
252+
--num-leaf-proofs 2 \
253+
--num-layer0-proofs 2 \
256254
--chain-path ../chain
257255
```
258256

259-
- `--branching-factor`: Number of proofs aggregated at each tree level.
260-
- `--depth`: Depth of the aggregation tree. Total leaf proofs = `branching_factor ^ depth`.
261-
- `--circuits-path`: Path to the `qp-zk-circuits` repo (default: `../qp-zk-circuits`).
257+
Add `--skip-prover` when you only need verifier artifacts:
258+
259+
```bash
260+
quantus developer build-circuits \
261+
--num-leaf-proofs 2 \
262+
--num-layer0-proofs 2 \
263+
--chain-path ../chain \
264+
--skip-prover
265+
```
266+
267+
- `--num-leaf-proofs`: Number of leaf proofs per layer-0 aggregation.
268+
- `--num-layer0-proofs`: Number of inner proofs per layer-1 aggregation.
262269
- `--chain-path`: Path to the chain repo (default: `../chain`).
263270
- `--skip-chain`: Skip copying binaries to the chain directory.
271+
- `--skip-prover`: Skip generating prover binaries.
264272

265-
**What it does (4 steps):**
266-
1. Builds the `qp-wormhole-circuit-builder` binary.
267-
2. Runs the circuit builder to generate binary files in `generated-bins/` (includes `prover.bin`, `verifier.bin`, `common.bin`, `aggregated_verifier.bin`, `aggregated_common.bin`, `config.json` with SHA256 hashes).
268-
3. Copies binaries to the CLI's `generated-bins/` directory and touches the aggregator source to force recompilation.
269-
4. Copies chain-relevant binaries (`aggregated_common.bin`, `aggregated_verifier.bin`, `config.json`) to `chain/pallets/wormhole/` and touches the pallet source.
273+
**What it does (3 steps):**
274+
1. Clears stale artifacts from the CLI's `generated-bins/` directory.
275+
2. Calls the `qp-wormhole-circuit-builder` library directly to regenerate binary files in `generated-bins/` (`verifier.bin`, `common.bin`, `aggregated_verifier.bin`, `aggregated_common.bin`, `config.json`, plus prover binaries unless `--skip-prover` is set).
276+
3. Copies chain-relevant binaries (`aggregated_common.bin`, `aggregated_verifier.bin`, `config.json`) to `chain/pallets/wormhole/` and touches the pallet source.
270277

271278
After running, rebuild the chain (`cargo build --release` in the chain directory) so `include_bytes!()` picks up the new binaries.
272279

build.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//! Build script for quantus-cli.
2+
//!
3+
//! Generates circuit binaries (prover, verifier, aggregator) at build time.
4+
//! This ensures the binaries are always consistent with the circuit crate version
5+
//! and eliminates the need to manually run `quantus developer build-circuits`.
6+
7+
use std::{env, path::Path, time::Instant};
8+
9+
fn main() {
10+
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
11+
let output_dir = Path::new(&manifest_dir).join("generated-bins");
12+
13+
let num_leaf_proofs: usize = env::var("QP_NUM_LEAF_PROOFS")
14+
.unwrap_or_else(|_| "16".to_string())
15+
.parse()
16+
.expect("QP_NUM_LEAF_PROOFS must be a valid usize");
17+
18+
// Rerun if the circuit builder crate changes
19+
println!("cargo:rerun-if-changed=build.rs");
20+
21+
println!(
22+
"cargo:warning=[quantus-cli] Generating ZK circuit binaries (num_leaf_proofs={})...",
23+
num_leaf_proofs
24+
);
25+
26+
let start = Instant::now();
27+
28+
// Create the output directory if it doesn't exist
29+
std::fs::create_dir_all(&output_dir).expect("Failed to create generated-bins directory");
30+
31+
// Generate all circuit binaries (leaf + aggregated, WITH prover)
32+
qp_wormhole_circuit_builder::generate_all_circuit_binaries(
33+
&output_dir,
34+
true, // include_prover = true (CLI needs prover for proof generation)
35+
num_leaf_proofs,
36+
None, // num_layer0_proofs - no layer-1 aggregation
37+
)
38+
.expect("Failed to generate circuit binaries");
39+
40+
let elapsed = start.elapsed();
41+
println!(
42+
"cargo:warning=[quantus-cli] ZK circuit binaries generated in {:.2}s",
43+
elapsed.as_secs_f64()
44+
);
45+
}
-1.32 KB
Binary file not shown.
-552 Bytes
Binary file not shown.

generated-bins/common.bin

-1.03 KB
Binary file not shown.

generated-bins/config.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

generated-bins/dummy_proof.bin

-147 KB
Binary file not shown.

0 commit comments

Comments
 (0)