Skip to content

Commit aaeaaf7

Browse files
authored
mpcs e2e batch in one proof (#894)
Build on top of #901. ### Design rationale zkvm + mpcs api: use `batch_commit/batch_opening` to commit/open **ALL** opcode together. In more detail, we commit `fixed_commit` and `witin_commit` separately with just one opening. basefold: batch opcodes with rmm with different "height", in other words, different "num_vars". For basefold to batch opcodes with different variables, for sumcheck part we apply suffix alignment techniques based on #870. For FRI part, we also apply suffix alignment techniques. So the smaller codeword will "involved" into the folding process when current length match. During implementation, there is key principle in mind: verifier only rely on one untrusted information "num_instances" from prover, and other information should derived from verifier key. ### Working items - [x] mpcs batch api + batch basefold prover - [x] batch basefold verifier ### Fibonacci Benchmark Results | Size | Branch | Proof Size | E2E Latency Change | Prover Speed (kHz) | |----------|----------------------|------------|--------------------|---------------------| | 2²⁰ | Master | 14.68 MB | - | 363 | | 2²⁰ | Batched + conjecture | 1.16 MB | -14.195% | 422 | | 2²⁰ | Batched | 2.02 MB | -11.599% | 411 | | 2²¹ | Master | 15.53 MB | - | 411 | | 2²¹ | Batched + conjecture | 1.24 MB | -11.178% | 451 | | 2²¹ | Batched | 2.16 MB | -6.4525% | 428 | | 2²² | Master | 16.42 MB | - | 406 | | 2²² | Batched + conjecture | 1.31 MB | -11.178% | 433 | | 2²² | Batched | 2.31 MB | -13.691% | 448 |
1 parent b49e3a8 commit aaeaaf7

33 files changed

+2145
-1151
lines changed

Cargo.lock

Lines changed: 32 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ p3-challenger = { git = "https://github.com/scroll-tech/plonky3", rev = "20c3cb9
4545
p3-commit = { git = "https://github.com/scroll-tech/plonky3", rev = "20c3cb9" }
4646
p3-dft = { git = "https://github.com/scroll-tech/plonky3", rev = "20c3cb9" }
4747
p3-field = { git = "https://github.com/scroll-tech/plonky3", rev = "20c3cb9" }
48+
p3-fri = { git = "https://github.com/scroll-tech/plonky3", rev = "20c3cb9" }
4849
p3-goldilocks = { git = "https://github.com/scroll-tech/plonky3", rev = "20c3cb9" }
4950
p3-matrix = { git = "https://github.com/scroll-tech/plonky3", rev = "20c3cb9" }
5051
p3-maybe-rayon = { git = "https://github.com/scroll-tech/plonky3", rev = "20c3cb9" }

ceno_zkvm/benches/riscv_add.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::time::Duration;
1+
use std::{collections::BTreeMap, time::Duration};
22

33
use ceno_zkvm::{
44
self,
@@ -73,14 +73,16 @@ fn bench_add(c: &mut Criterion) {
7373
for _ in 0..iters {
7474
// generate mock witness
7575
let num_instances = 1 << instance_num_vars;
76-
let rmm =
77-
RowMajorMatrix::rand(&mut OsRng, num_instances, num_witin as usize);
76+
let rmms = BTreeMap::from([(
77+
0,
78+
RowMajorMatrix::rand(&mut OsRng, num_instances, num_witin as usize),
79+
)]);
7880

7981
let instant = std::time::Instant::now();
8082
let num_instances = 1 << instance_num_vars;
8183
let mut transcript = BasicTranscript::new(b"riscv");
8284
let commit =
83-
Pcs::batch_commit_and_write(&prover.pk.pp, rmm, &mut transcript)
85+
Pcs::batch_commit_and_write(&prover.pk.pp, rmms, &mut transcript)
8486
.unwrap();
8587
let polys = Pcs::get_arc_mle_witness_from_commitment(&commit);
8688
let challenges = [
@@ -91,10 +93,8 @@ fn bench_add(c: &mut Criterion) {
9193
let _ = prover
9294
.create_opcode_proof(
9395
"ADD",
94-
&prover.pk.pp,
9596
circuit_pk,
9697
polys,
97-
commit,
9898
&[],
9999
num_instances,
100100
&mut transcript,

ceno_zkvm/src/circuit_builder.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use serde::de::DeserializeOwned;
33
use std::{collections::HashMap, iter::once, marker::PhantomData};
44

55
use ff_ext::ExtensionField;
6-
use mpcs::PolynomialCommitmentScheme;
76

87
use crate::{
98
ROMType,
@@ -13,7 +12,6 @@ use crate::{
1312
structs::{ProgramParams, ProvingKey, RAMType, VerifyingKey, WitnessId},
1413
};
1514
use p3::field::PrimeCharacteristicRing;
16-
use witness::RowMajorMatrix;
1715

1816
/// namespace used for annotation, preserve meta info during circuit construction
1917
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
@@ -178,24 +176,9 @@ impl<E: ExtensionField> ConstraintSystem<E> {
178176
}
179177
}
180178

181-
pub fn key_gen<PCS: PolynomialCommitmentScheme<E>>(
182-
self,
183-
pp: &PCS::ProverParam,
184-
fixed_traces: Option<RowMajorMatrix<E::BaseField>>,
185-
) -> ProvingKey<E, PCS> {
186-
// transpose from row-major to column-major
187-
let fixed_traces_polys = fixed_traces.as_ref().map(|rmm| rmm.to_mles());
188-
189-
let fixed_commit_wd = fixed_traces.map(|traces| PCS::batch_commit(pp, traces).unwrap());
190-
let fixed_commit = fixed_commit_wd.as_ref().map(PCS::get_pure_commitment);
191-
179+
pub fn key_gen(self) -> ProvingKey<E> {
192180
ProvingKey {
193-
fixed_traces: fixed_traces_polys,
194-
fixed_commit_wd,
195-
vk: VerifyingKey {
196-
cs: self,
197-
fixed_commit,
198-
},
181+
vk: VerifyingKey { cs: self },
199182
}
200183
}
201184

ceno_zkvm/src/e2e.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,11 @@ pub fn verify(
675675
// print verification statistics like proof size and hash count
676676
let stat_recorder = StatisticRecorder::default();
677677
let transcript = BasicTranscriptWithStat::new(&stat_recorder, b"riscv");
678-
verifier.verify_proof_halt(zkvm_proof.clone(), transcript, zkvm_proof.has_halt())?;
678+
verifier.verify_proof_halt(
679+
zkvm_proof.clone(),
680+
transcript,
681+
zkvm_proof.has_halt(&verifier.vk),
682+
)?;
679683
info!("e2e proof stat: {}", zkvm_proof);
680684
info!(
681685
"hashes count = {}",

ceno_zkvm/src/instructions/riscv/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ fn test_multiple_opcode() {
2323
|cs| SubInstruction::construct_circuit(&mut CircuitBuilder::<E>::new(cs)),
2424
);
2525
let param = Pcs::setup(1 << 10).unwrap();
26-
let (pp, _) = Pcs::trim(param, 1 << 10).unwrap();
27-
cs.key_gen::<Pcs>(&pp, None);
26+
let (_, _) = Pcs::trim(param, 1 << 10).unwrap();
27+
cs.key_gen();
2828
}

ceno_zkvm/src/keygen.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::BTreeMap;
2+
13
use crate::{
24
error::ZKVMError,
35
structs::{ZKVMConstraintSystem, ZKVMFixedTraces, ZKVMProvingKey},
@@ -12,24 +14,27 @@ impl<E: ExtensionField> ZKVMConstraintSystem<E> {
1214
vp: PCS::VerifierParam,
1315
mut vm_fixed_traces: ZKVMFixedTraces<E>,
1416
) -> Result<ZKVMProvingKey<E, PCS>, ZKVMError> {
15-
let mut vm_pk = ZKVMProvingKey::new(pp, vp);
17+
let mut vm_pk = ZKVMProvingKey::new(pp.clone(), vp);
18+
let mut fixed_traces = BTreeMap::new();
1619

17-
for (c_name, cs) in self.circuit_css {
20+
for (circuit_index, (c_name, cs)) in self.circuit_css.into_iter().enumerate() {
1821
// fixed_traces is optional
1922
// verifier will check it existent if cs.num_fixed > 0
20-
let fixed_traces = if cs.num_fixed > 0 {
21-
vm_fixed_traces
23+
if cs.num_fixed > 0 {
24+
let fixed_trace_rmm = vm_fixed_traces
2225
.circuit_fixed_traces
2326
.remove(&c_name)
24-
.ok_or(ZKVMError::FixedTraceNotFound(c_name.clone()))?
25-
} else {
26-
None
27+
.flatten()
28+
.ok_or(ZKVMError::FixedTraceNotFound(c_name.clone()))?;
29+
fixed_traces.insert(circuit_index, fixed_trace_rmm);
2730
};
2831

29-
let circuit_pk = cs.key_gen(&vm_pk.pp, fixed_traces);
32+
let circuit_pk = cs.key_gen();
3033
assert!(vm_pk.circuit_pks.insert(c_name, circuit_pk).is_none());
3134
}
3235

36+
vm_pk.commit_fixed(fixed_traces)?;
37+
3338
vm_pk.initial_global_state_expr = self.initial_global_state_expr;
3439
vm_pk.finalize_global_state_expr = self.finalize_global_state_expr;
3540

0 commit comments

Comments
 (0)