Skip to content

Commit

Permalink
remove mpcs commit/opening
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Nov 13, 2024
1 parent 9571c2b commit 4ef4ab1
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 78 deletions.
2 changes: 1 addition & 1 deletion ceno_zkvm/examples/riscv_opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn main() {
println!(
"riscv_opcodes::create_proof, instance_num_vars = {}, time = {}",
instance_num_vars,
timer.elapsed().as_secs()
timer.elapsed()
);

let transcript = Transcript::new(b"riscv");
Expand Down
12 changes: 6 additions & 6 deletions ceno_zkvm/src/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod mock_prover;
mod tests;

#[derive(Clone)]
pub struct ZKVMOpcodeProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> {
pub struct ZKVMOpcodeProof<E: ExtensionField> {
// TODO support >1 opcodes
pub num_instances: usize,

Expand All @@ -39,8 +39,8 @@ pub struct ZKVMOpcodeProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>
pub w_records_in_evals: Vec<E>,
pub lk_records_in_evals: Vec<E>,

pub wits_commit: PCS::Commitment,
pub wits_opening_proof: PCS::Proof,
// pub wits_commit: PCS::Commitment,
// pub wits_opening_proof: PCS::Proof,
pub wits_in_evals: Vec<E>,
}

Expand All @@ -62,9 +62,9 @@ pub struct ZKVMTableProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>>

pub fixed_in_evals: Vec<E>,
pub fixed_opening_proof: Option<PCS::Proof>,
pub wits_commit: PCS::Commitment,
// pub wits_commit: PCS::Commitment,
pub wits_in_evals: Vec<E>,
pub wits_opening_proof: PCS::Proof,
// pub wits_opening_proof: PCS::Proof,
}

/// each field will be interpret to (constant) polynomial
Expand Down Expand Up @@ -122,7 +122,7 @@ pub struct ZKVMProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> {
pub raw_pi: Vec<Vec<E::BaseField>>,
// the evaluation of raw_pi.
pub pi_evals: Vec<E>,
opcode_proofs: BTreeMap<String, (usize, ZKVMOpcodeProof<E, PCS>)>,
opcode_proofs: BTreeMap<String, (usize, ZKVMOpcodeProof<E>)>,
table_proofs: BTreeMap<String, (usize, ZKVMTableProof<E, PCS>)>,
}

Expand Down
74 changes: 38 additions & 36 deletions ceno_zkvm/src/scheme/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use ff::Field;
use itertools::{Itertools, izip};
use mpcs::PolynomialCommitmentScheme;
use mpcs::{CommitmentWithData, PolynomialCommitmentScheme};
use multilinear_extensions::{
mle::{IntoMLE, MultilinearExtension},
util::ceil_log2,
Expand Down Expand Up @@ -99,8 +99,9 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
let witness = witness.into_mles();
commitments.insert(
circuit_name.clone(),
PCS::batch_commit_and_write(&self.pk.pp, &witness, &mut transcript)
.map_err(ZKVMError::PCSError)?,
CommitmentWithData::<E, PCS>::default(),
// PCS::batch_commit_and_write(&self.pk.pp, &witness, &mut transcript)
// .map_err(ZKVMError::PCSError)?,
);
witness
}
Expand Down Expand Up @@ -214,7 +215,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
num_instances: usize,
transcript: &mut Transcript<E>,
challenges: &[E; 2],
) -> Result<ZKVMOpcodeProof<E, PCS>, ZKVMError> {
) -> Result<ZKVMOpcodeProof<E>, ZKVMError> {
let cs = circuit_pk.get_cs();
let next_pow2_instances = next_pow2_instance_padding(num_instances);
let log2_num_instances = ceil_log2(next_pow2_instances);
Expand Down Expand Up @@ -604,22 +605,23 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
witnesses.len(),
input_open_point
);
let wits_opening_proof = PCS::simple_batch_open(
pp,
&witnesses,
&wits_commit,
&input_open_point,
wits_in_evals.as_slice(),
transcript,
)
.map_err(ZKVMError::PCSError)?;
// let wits_opening_proof = PCS::simple_batch_open(
// pp,
// &witnesses,
// &wits_commit,
// &input_open_point,
// wits_in_evals.as_slice(),
// transcript,
// )
// .map_err(ZKVMError::PCSError)?;

tracing::info!(
"[opcode {}] build opening proof took {:?}",
name,
opening_dur.elapsed(),
);
exit_span!(pcs_open_span);
let wits_commit = PCS::get_pure_commitment(&wits_commit);
// let wits_commit = PCS::get_pure_commitment(&wits_commit);

Ok(ZKVMOpcodeProof {
num_instances,
Expand All @@ -634,8 +636,8 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
r_records_in_evals,
w_records_in_evals,
lk_records_in_evals,
wits_commit,
wits_opening_proof,
// wits_commit,
// wits_opening_proof,
wits_in_evals,
})
}
Expand Down Expand Up @@ -1069,27 +1071,27 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
fixed_commit,
);
let span = entered_span!("pcs_witin_opening");
let wits_opening_proof = PCS::simple_batch_open(
pp,
&witnesses,
&wits_commit,
&input_open_point,
wits_in_evals.as_slice(),
transcript,
)
.map_err(ZKVMError::PCSError)?;
// let wits_opening_proof = PCS::simple_batch_open(
// pp,
// &witnesses,
// &wits_commit,
// &input_open_point,
// wits_in_evals.as_slice(),
// transcript,
// )
// .map_err(ZKVMError::PCSError)?;
exit_span!(pcs_opening);
let pcs_witin_commitment = entered_span!("pcs_witin_commitment");
let wits_commit = PCS::get_pure_commitment(&wits_commit);
// let wits_commit = PCS::get_pure_commitment(&wits_commit);
exit_span!(pcs_witin_commitment);
tracing::debug!(
"[table {}] build opening proof for {} polys at {:?}: values = {:?}, commit = {:?}",
name,
witnesses.len(),
input_open_point,
wits_in_evals,
wits_commit,
);
// tracing::debug!(
// "[table {}] build opening proof for {} polys at {:?}: values = {:?}, commit = {:?}",
// name,
// witnesses.len(),
// input_open_point,
// wits_in_evals,
// wits_commit,
// );

Ok((
ZKVMTableProof {
Expand All @@ -1104,8 +1106,8 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
fixed_opening_proof,
rw_hints_num_vars,
wits_in_evals,
wits_commit,
wits_opening_proof,
// wits_commit,
// wits_opening_proof,
},
pi_in_evals,
))
Expand Down
70 changes: 35 additions & 35 deletions ceno_zkvm/src/scheme/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMVerifier<E, PCS>
}
}

for (_, (_, proof)) in vm_proof.opcode_proofs.iter() {
PCS::write_commitment(&proof.wits_commit, &mut transcript)
.map_err(ZKVMError::PCSError)?;
}
for (_, (_, proof)) in vm_proof.table_proofs.iter() {
PCS::write_commitment(&proof.wits_commit, &mut transcript)
.map_err(ZKVMError::PCSError)?;
}
// for (_, (_, proof)) in vm_proof.opcode_proofs.iter() {
// PCS::write_commitment(&proof.wits_commit, &mut transcript)
// .map_err(ZKVMError::PCSError)?;
// }
// for (_, (_, proof)) in vm_proof.table_proofs.iter() {
// PCS::write_commitment(&proof.wits_commit, &mut transcript)
// .map_err(ZKVMError::PCSError)?;
// }

// alpha, beta
let challenges = [
Expand Down Expand Up @@ -233,7 +233,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMVerifier<E, PCS>
name: &str,
vp: &PCS::VerifierParam,
circuit_vk: &VerifyingKey<E, PCS>,
proof: &ZKVMOpcodeProof<E, PCS>,
proof: &ZKVMOpcodeProof<E>,
pi: &[E],
transcript: &mut Transcript<E>,
num_product_fanin: usize,
Expand Down Expand Up @@ -463,15 +463,15 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMVerifier<E, PCS>
proof.wits_in_evals.len(),
input_opening_point
);
PCS::simple_batch_verify(
vp,
&proof.wits_commit,
&input_opening_point,
&proof.wits_in_evals,
&proof.wits_opening_proof,
transcript,
)
.map_err(ZKVMError::PCSError)?;
// PCS::simple_batch_verify(
// vp,
// &proof.wits_commit,
// &input_opening_point,
// &proof.wits_in_evals,
// &proof.wits_opening_proof,
// transcript,
// )
// .map_err(ZKVMError::PCSError)?;

Ok(input_opening_point)
}
Expand Down Expand Up @@ -761,23 +761,23 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMVerifier<E, PCS>
circuit_vk.fixed_commit,
);

PCS::simple_batch_verify(
vp,
&proof.wits_commit,
&input_opening_point,
&proof.wits_in_evals,
&proof.wits_opening_proof,
transcript,
)
.map_err(ZKVMError::PCSError)?;
tracing::debug!(
"[table {}] verified opening proof for {} polys at {:?}: values = {:?}, commit = {:?}",
name,
proof.wits_in_evals.len(),
input_opening_point,
proof.wits_in_evals,
proof.wits_commit
);
// PCS::simple_batch_verify(
// vp,
// &proof.wits_commit,
// &input_opening_point,
// &proof.wits_in_evals,
// &proof.wits_opening_proof,
// transcript,
// )
// .map_err(ZKVMError::PCSError)?;
// tracing::debug!(
// "[table {}] verified opening proof for {} polys at {:?}: values = {:?}, commit = {:?}",
// name,
// proof.wits_in_evals.len(),
// input_opening_point,
// proof.wits_in_evals,
// proof.wits_commit
// );

Ok(input_opening_point)
}
Expand Down
24 changes: 24 additions & 0 deletions mpcs/src/util/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[macro_export]
macro_rules! entered_span {
($first:expr, $($fields:tt)*) => {
$crate::tracing_span!($first, $($fields)*).entered()
};
($first:expr $(,)*) => {
$crate::tracing_span!($first).entered()
};
}
#[macro_export]
macro_rules! tracing_span {
($first:expr, $($fields:tt)*) => {
tracing::span!(tracing::Level::INFO, $first, $($fields)*)
};
($first:expr $(,)*) => {
tracing::span!(tracing::Level::INFO, $first)
};
}
#[macro_export]
macro_rules! exit_span {
($first:expr $(,)*) => {
$first.exit();
};
}

0 comments on commit 4ef4ab1

Please sign in to comment.