Skip to content

Commit

Permalink
adapt parallel continuation-batcher
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Mar 18, 2024
1 parent 77f033a commit 5cda906
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 168 deletions.
59 changes: 45 additions & 14 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ resolver = "2"
[workspace.dependencies]
anyhow = { version = "1.0.68", features = ["backtrace"] }
cfg-if = "1.0.0"
halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", branch = "para-synthesize", features = ["unsafe"] }
halo2_proofs = { git = "https://github.com/DelphinusLab/halo2-gpu-specific.git", branch = "zhangjunyu/para-synthesize", default-features = true }
halo2aggregator-s = { git = "https://github.com/DelphinusLab/halo2aggregator-s.git", features = ["unsafe"] }
halo2_proofs = { git = "https://github.com/DelphinusLab/halo2-gpu-specific.git", default-features = true }
parity-wasm = { version = "0.42.0", features = ["sign_ext"] }
wasmi = { path = "third-party/wasmi" }
circuits-batcher = { git = "https://github.com/DelphinusLab/continuation-batcher.git", branch = "para-synthesize" }
zkwasm-host-circuits = { git = "https://github.com/DelphinusLab/zkWasm-host-circuits.git", branch="para-synthesize" }
circuits-batcher = { git = "https://github.com/DelphinusLab/continuation-batcher.git" }
zkwasm-host-circuits = { git = "https://github.com/DelphinusLab/zkWasm-host-circuits.git" }

[profile.dev]
opt-level = 3
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ circuits-batcher.workspace = true

[features]
default = []
perf = ["circuits-batcher/perf"]
cuda = ["delphinus-zkwasm/cuda"]
uniform-circuit = ["delphinus-zkwasm/uniform-circuit"]

58 changes: 31 additions & 27 deletions crates/cli/src/exec.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use anyhow::Result;
use circuits_batcher::proof::CircuitInfo;
use circuits_batcher::args::HashType::Poseidon;
use circuits_batcher::proof::ParamsCache;
use circuits_batcher::proof::ProofInfo;
use circuits_batcher::proof::ProofLoadInfo;
use circuits_batcher::proof::ProofPieceInfo;
use circuits_batcher::proof::ProvingKeyCache;
use delphinus_zkwasm::circuits::ZkWasmCircuit;
use delphinus_zkwasm::loader::ZkWasmLoader;
use delphinus_zkwasm::runtime::host::HostEnvBuilder;
use halo2_proofs::pairing::bn256::Bn256;
use halo2_proofs::pairing::bn256::Fr;
use halo2_proofs::plonk::verify_proof_with_shplonk;
use halo2_proofs::plonk::SingleVerifier;
use halo2_proofs::poly::commitment::ParamsVerifier;
use halo2aggregator_s::circuits::utils::load_or_build_unsafe_params;
use halo2aggregator_s::circuits::utils::TranscriptHash;
use halo2aggregator_s::native_verifier;
use halo2aggregator_s::transcript::poseidon::PoseidonRead;
use log::info;
use std::io::Write;
use std::path::PathBuf;
Expand Down Expand Up @@ -156,25 +156,27 @@ pub fn exec_create_proof<Builder: HostEnvBuilder>(
info!("Mock test passed");
}

let circuit: CircuitInfo<Bn256, ZkWasmCircuit<Fr>> = CircuitInfo::new(
circuit,
prefix.to_string(),
vec![instances],
zkwasm_k as usize,
circuits_batcher::args::HashType::Poseidon,
);
let prover: ProofPieceInfo = ProofPieceInfo::new(prefix.to_string(), 0, instances.len() as u32);

// save the proof load info for the zkwasm circuit
circuit.proofloadinfo.save(output_dir);
let mut param_cache = ParamsCache::<Bn256>::new(5);
let mut pkey_cache = ProvingKeyCache::<Bn256>::new(5);

// Cli saves zkwasm.0.instance.data as the
// first instance file for .loadinfo
// Thus we provide arg index = 0 to generate a
// proof with the first instance file
let mut param_cache = ParamsCache::new(5);
let mut pkey_cache = ProvingKeyCache::new(5);
let mut proof_load_info = ProofLoadInfo::new(prefix, zkwasm_k as usize, Poseidon);

circuit.exec_create_proof(output_dir, param_dir, &mut pkey_cache, 0, &mut param_cache);
prover.exec_create_proof(
&circuit,
&vec![instances],
output_dir.as_path(),
param_dir.as_path(),
format!("K{}.params", zkwasm_k),
zkwasm_k as usize,
&mut pkey_cache,
&mut param_cache,
circuits_batcher::args::HashType::Poseidon,
);
//prover.mock_proof(k as u32);
proof_load_info.append_single_proof(prover);
proof_load_info.save(output_dir);

info!("Proof has been created.");

Expand Down Expand Up @@ -206,14 +208,16 @@ pub fn exec_verify_proof(
}

let params_verifier: ParamsVerifier<Bn256> = params.verifier(public_inputs_size).unwrap();
for (_, proof) in proofs.iter().enumerate() {
native_verifier::verify_single_proof::<Bn256>(
for (_, proof) in proofs.into_iter().enumerate() {
let strategy = SingleVerifier::new(&params_verifier);
verify_proof_with_shplonk::<Bn256, _, _, _>(
&params_verifier,
&proof.vkey,
&proof.instances,
proof.transcripts.clone(),
TranscriptHash::Poseidon,
);
strategy,
&[&proof.instances.iter().map(|x| &x[..]).collect::<Vec<_>>()[..]],
&mut PoseidonRead::init(&proof.transcripts[..]),
)
.unwrap();
}
info!("Verifing proof passed");

Expand Down
2 changes: 1 addition & 1 deletion crates/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ delphinus-zkwasm = { path = "../zkwasm" }

ff = "0.12"
sha2 = "0.10.6"
poseidon = { git = "https://github.com/DelphinusLab/poseidon", branch="para-synthesize" }
poseidon = { git = "https://github.com/DelphinusLab/poseidon" }

anyhow.workspace = true
halo2aggregator-s.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/zkwasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
ff = "0.12"
sha2 = "0.10.6"
poseidon = { git = "https://github.com/DelphinusLab/poseidon", branch="para-synthesize" }
poseidon = { git = "https://github.com/DelphinusLab/poseidon" }
rayon = "1.5"

anyhow.workspace = true
Expand Down
Loading

0 comments on commit 5cda906

Please sign in to comment.