Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
.idea
*.hex
/generated-bins/prover.bin
/generated-bins/*prover.bin
32 changes: 12 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ subxt-metadata = "0.44"

# ZK proof generation (aligned with chain)
anyhow = "1.0"
qp-wormhole-circuit = { version = "1.0.7", default-features = false, features = ["std"] }
qp-wormhole-prover = { version = "1.0.7", default-features = false, features = ["std"] }
qp-wormhole-verifier = { version = "1.0.7", default-features = false, features = ["std"] }
qp-wormhole-aggregator = { version = "1.0.7", default-features = false, features = ["rayon", "std"] }
qp-wormhole-inputs = { version = "1.0.7", default-features = false, features = ["std"] }
qp-zk-circuits-common = { version = "1.0.7", default-features = false, features = ["std"] }
qp-wormhole-circuit = { git = "https://github.com/Quantus-Network/qp-zk-circuits", branch = "refactor/sep-prover-and-circuit-build", package = "qp-wormhole-circuit", default-features = false, features = ["std"] }
qp-wormhole-prover = { git = "https://github.com/Quantus-Network/qp-zk-circuits", branch = "refactor/sep-prover-and-circuit-build", package = "qp-wormhole-prover", default-features = false, features = ["std"] }
qp-wormhole-verifier = { git = "https://github.com/Quantus-Network/qp-zk-circuits", branch = "refactor/sep-prover-and-circuit-build", package = "qp-wormhole-verifier", default-features = false, features = ["std"] }
qp-wormhole-aggregator = { git = "https://github.com/Quantus-Network/qp-zk-circuits", package = "qp-wormhole-aggregator", branch = "refactor/sep-prover-and-circuit-build", default-features = false, features = ["rayon", "std"] }
# qp-wormhole-aggregator = { path = "../zk-circuits/wormhole/aggregator", package = "qp-wormhole-aggregator", default-features = false, features = ["rayon", "std"] }
qp-wormhole-inputs = { git = "https://github.com/Quantus-Network/qp-zk-circuits", branch = "refactor/sep-prover-and-circuit-build", package = "qp-wormhole-inputs", default-features = false, features = ["std"] }
qp-zk-circuits-common = { git = "https://github.com/Quantus-Network/qp-zk-circuits", branch = "refactor/sep-prover-and-circuit-build", package = "qp-zk-circuits-common", default-features = false, features = ["std"] }
qp-plonky2 = { version = "1.1.3", default-features = false, features = ["rand", "std"] }

[dev-dependencies]
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,15 @@ Build ZK circuit binaries from the `qp-zk-circuits` repository, then copy them t

```bash
quantus developer build-circuits \
--branching-factor 2 \
--num-leaf-proofs 2 \
--num-layer0-proofs 2 \
--depth 1 \
--circuits-path ../qp-zk-circuits \
--chain-path ../chain
```

- `--branching-factor`: Number of proofs aggregated at each tree level.
- `--depth`: Depth of the aggregation tree. Total leaf proofs = `branching_factor ^ depth`.
- `--num-leaf-proofs`: Number of leaf proofs per layer-0 aggregation.
- `--num-layer0-proofs`: Number of inner proofs per layer-1 aggregation.
- `--circuits-path`: Path to the `qp-zk-circuits` repo (default: `../qp-zk-circuits`).
- `--chain-path`: Path to the chain repo (default: `../chain`).
- `--skip-chain`: Skip copying binaries to the chain directory.
Expand Down
Binary file modified generated-bins/aggregated_common.bin
Binary file not shown.
Binary file modified generated-bins/aggregated_verifier.bin
Binary file not shown.
10 changes: 6 additions & 4 deletions generated-bins/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"num_leaf_proofs": 16,
"num_leaf_proofs": 8,
"num_layer0_proofs": null,
"hashes": {
"common": "672689a87e8ed780337c0752ebc7fd1db6a63611fbd59b4ad0cbe4a4d97edcf2",
"verifier": "bb017485b12fb9c6d0b5c3db8b68f417bd3f75b2d5f3a2ea5fe12b6244233372",
"prover": "78c114c7290b04bac00551a590fd652f98194653b10ac4e11b0c0ddd5c7c0976",
"aggregated_common": "af4461081f6fb527d2b9ffb74479a133ed8b92cdd3554b46adc481a0dfc38b5d",
"aggregated_verifier": "90350437c8e0e2144ca849623ea0b58edd2decd7bdf6b728b32e1aa9d8f1e337",
"dummy_proof": "8c46fd19c4c3581016ba4adcf4f0735bd04bf09f8e94e9b0f092ea522c9d3ba9"
"aggregated_common": "20a2dc0e48a9d7a69c9bffca5e9ee917769abdbd1f512dcb5ba303af4f69ed91",
"aggregated_verifier": "22913f5a8da5bfe1d3153e8fb4ca3c9bce02ad1afc7a07d229c48b40f67f5b8b",
"aggregated_prover": "168212332937960d0a8319f1944ecd5357476a2f0b7017c2dedb6ae461717d6b",
"dummy_proof": "6828bea2ccd42eac05f9e785f3834a1cc218553a68b090718d84c2d9dd381e8d"
}
}
Binary file modified generated-bins/dummy_proof.bin
Binary file not shown.
72 changes: 53 additions & 19 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,14 @@ pub enum DeveloperCommands {
#[arg(long, default_value = "../chain")]
chain_path: String,

/// Number of leaf proofs aggregated into a single proof
/// Number of leaf proofs aggregated into a single layer-0 proof
#[arg(long)]
num_leaf_proofs: usize,

/// Number of inner layer-0 proofs aggregated into a single layer-1 proof
#[arg(long)]
num_layer0_proofs: Option<usize>,

/// Skip copying to chain directory
#[arg(long)]
skip_chain: bool,
Expand Down Expand Up @@ -569,8 +573,17 @@ pub async fn handle_developer_command(command: DeveloperCommands) -> crate::erro
circuits_path,
chain_path,
num_leaf_proofs,
num_layer0_proofs,
skip_chain,
} => build_wormhole_circuits(&circuits_path, &chain_path, num_leaf_proofs, skip_chain).await,
} =>
build_wormhole_circuits(
&circuits_path,
&chain_path,
num_leaf_proofs,
num_layer0_proofs,
skip_chain,
)
.await,
}
}

Expand All @@ -579,11 +592,16 @@ async fn build_wormhole_circuits(
circuits_path: &str,
chain_path: &str,
num_leaf_proofs: usize,
num_layer0_proofs: Option<usize>,
skip_chain: bool,
) -> crate::error::Result<()> {
use std::{path::Path, process::Command};

log_print!("Building ZK circuit binaries (num_leaf_proofs={})", num_leaf_proofs);
log_print!(
"Building ZK circuit binaries (num_leaf_proofs={}, num_layer0_proofs={})",
num_leaf_proofs,
num_layer0_proofs.unwrap_or(0)
);
log_print!("");

let circuits_dir = Path::new(circuits_path);
Expand Down Expand Up @@ -619,13 +637,16 @@ async fn build_wormhole_circuits(
// Step 2: Run the circuit builder to generate binaries
log_print!("Step 2/4: Generating circuit binaries (this may take a while)...");
let builder_path = circuits_dir.join("target/release/qp-wormhole-circuit-builder");
let run_output = Command::new(&builder_path)
.args(["--num-leaf-proofs", &num_leaf_proofs.to_string()])
.current_dir(circuits_dir)
.output()
.map_err(|e| {
crate::error::QuantusError::Generic(format!("Failed to run circuit builder: {}", e))
})?;
let mut cmd = Command::new(&builder_path);
cmd.arg("--num-leaf-proofs").arg(num_leaf_proofs.to_string());

if let Some(num_layer0) = num_layer0_proofs {
cmd.arg("--num-layer0-proofs").arg(num_layer0.to_string());
}

let run_output = cmd.current_dir(circuits_dir).output().map_err(|e| {
crate::error::QuantusError::Generic(format!("Failed to run circuit builder: {}", e))
})?;

if !run_output.status.success() {
let stderr = String::from_utf8_lossy(&run_output.stderr);
Expand All @@ -641,17 +662,30 @@ async fn build_wormhole_circuits(
let source_bins = circuits_dir.join("generated-bins");
let cli_bins = Path::new("generated-bins");

let cli_bin_files = [
"common.bin",
"verifier.bin",
"prover.bin",
"dummy_proof.bin",
"aggregated_common.bin",
"aggregated_verifier.bin",
"config.json",
let possible_cli_bin_files = [
"common.bin", // leaf circuit
"verifier.bin", // leaf circuit
"prover.bin", // leaf circuit
"dummy_proof.bin", // leaf dummy proof
"aggregated_common.bin", // layer-0 aggregated circuit
"aggregated_verifier.bin", // layer-0 aggregated circuit
"aggregated_prover.bin", // layer-0 aggregated circuit
"config.json", // config file with metadata about the circuit bin data
// Layer-0 binaries are always generated, but layer-1 binaries are only generated if
// num_layer0_proofs is set
"layer1_common.bin", // layer-1 aggregated circuit
"layer1_verifier.bin", // layer-1 aggregated circuit
"layer1_prover.bin", // layer-1 aggregated circuit
];

for file in &cli_bin_files {
let cli_bin_files = if num_layer0_proofs.is_some() {
&possible_cli_bin_files
} else {
// If num_layer0_proofs is not set, we only generate layer-0 binaries.
&possible_cli_bin_files[0..8]
};

for file in cli_bin_files {
let src = source_bins.join(file);
let dst = cli_bins.join(file);
std::fs::copy(&src, &dst).map_err(|e| {
Expand Down
Loading
Loading