diff --git a/ceno_zkvm/src/scheme/prover.rs b/ceno_zkvm/src/scheme/prover.rs index b0ff7b656..2c8cae8bc 100644 --- a/ceno_zkvm/src/scheme/prover.rs +++ b/ceno_zkvm/src/scheme/prover.rs @@ -216,7 +216,7 @@ impl> ZKVMProver { pp: &PCS::ProverParam, circuit_pk: &ProvingKey, witnesses: Vec>, - wits_commit: PCS::CommitmentWithData, + wits_commit: PCS::CommitmentWithWitness, pi: &[ArcMultilinearExtension<'_, E>], num_instances: usize, transcript: &mut impl Transcript, @@ -661,7 +661,7 @@ impl> ZKVMProver { pp: &PCS::ProverParam, circuit_pk: &ProvingKey, witnesses: Vec>, - wits_commit: PCS::CommitmentWithData, + wits_commit: PCS::CommitmentWithWitness, pi: &[ArcMultilinearExtension<'_, E>], transcript: &mut impl Transcript, challenges: &[E; 2], diff --git a/ceno_zkvm/src/structs.rs b/ceno_zkvm/src/structs.rs index af41851f9..b006b10e1 100644 --- a/ceno_zkvm/src/structs.rs +++ b/ceno_zkvm/src/structs.rs @@ -103,7 +103,7 @@ impl PointAndEval { #[derive(Clone, Debug)] pub struct ProvingKey> { pub fixed_traces: Option>>, - pub fixed_commit_wd: Option, + pub fixed_commit_wd: Option, pub vk: VerifyingKey, } diff --git a/mpcs/src/basefold.rs b/mpcs/src/basefold.rs index a3657422e..1aec0fb9d 100644 --- a/mpcs/src/basefold.rs +++ b/mpcs/src/basefold.rs @@ -58,7 +58,7 @@ type SumCheck = ClassicSumCheck>; mod structure; pub use structure::{ - Basefold, BasefoldBasecodeParams, BasefoldCommitment, BasefoldCommitmentWithData, + Basefold, BasefoldBasecodeParams, BasefoldCommitment, BasefoldCommitmentWithWitness, BasefoldDefault, BasefoldParams, BasefoldProverParams, BasefoldRSParams, BasefoldVerifierParams, }; @@ -273,7 +273,7 @@ where type Param = BasefoldParams; type ProverParam = BasefoldProverParams; type VerifierParam = BasefoldVerifierParams; - type CommitmentWithData = BasefoldCommitmentWithData; + type CommitmentWithWitness = BasefoldCommitmentWithWitness; type Commitment = BasefoldCommitment; type CommitmentChunk = Digest; type Proof = BasefoldProof; @@ -307,7 +307,7 @@ where fn commit( pp: &Self::ProverParam, poly: &DenseMultilinearExtension, - ) -> Result { + ) -> Result { let timer = start_timer!(|| "Basefold::commit"); let is_base = match poly.evaluations { @@ -325,9 +325,9 @@ where PolyEvalsCodeword::Normal((bh_evals, codeword)) => { let codeword_tree = MerkleTree::::from_leaves(codeword); - // All these values are stored in the `CommitmentWithData` because + // All these values are stored in the `CommitmentWithWitness` because // they are useful in opening, and we don't want to recompute them. - Ok(Self::CommitmentWithData { + Ok(Self::CommitmentWithWitness { codeword_tree, polynomials_bh_evals: vec![bh_evals], num_vars: poly.num_vars, @@ -338,9 +338,9 @@ where PolyEvalsCodeword::TooSmall(evals) => { let codeword_tree = MerkleTree::::from_leaves(evals.clone()); - // All these values are stored in the `CommitmentWithData` because + // All these values are stored in the `CommitmentWithWitness` because // they are useful in opening, and we don't want to recompute them. - Ok(Self::CommitmentWithData { + Ok(Self::CommitmentWithWitness { codeword_tree, polynomials_bh_evals: vec![evals], num_vars: poly.num_vars, @@ -359,7 +359,7 @@ where fn batch_commit( pp: &Self::ProverParam, polys: &[DenseMultilinearExtension], - ) -> Result { + ) -> Result { // assumptions // 1. there must be at least one polynomial // 2. all polynomials must exist in the same field type @@ -413,7 +413,7 @@ where }) .collect::<(Vec<_>, Vec<_>)>(); let codeword_tree = MerkleTree::::from_batch_leaves(codewords); - Self::CommitmentWithData { + Self::CommitmentWithWitness { codeword_tree, polynomials_bh_evals: bh_evals, num_vars: polys[0].num_vars, @@ -433,7 +433,7 @@ where }) .collect::>(); let codeword_tree = MerkleTree::::from_batch_leaves(bh_evals.clone()); - Self::CommitmentWithData { + Self::CommitmentWithWitness { codeword_tree, polynomials_bh_evals: bh_evals, num_vars: polys[0].num_vars, @@ -457,7 +457,7 @@ where Ok(()) } - fn get_pure_commitment(comm: &Self::CommitmentWithData) -> Self::Commitment { + fn get_pure_commitment(comm: &Self::CommitmentWithWitness) -> Self::Commitment { comm.to_commitment() } @@ -467,7 +467,7 @@ where fn open( pp: &Self::ProverParam, poly: &DenseMultilinearExtension, - comm: &Self::CommitmentWithData, + comm: &Self::CommitmentWithWitness, point: &[E], _eval: &E, // Opening does not need eval, except for sanity check transcript: &mut impl Transcript, @@ -547,7 +547,7 @@ where fn batch_open( pp: &Self::ProverParam, polys: &[DenseMultilinearExtension], - comms: &[Self::CommitmentWithData], + comms: &[Self::CommitmentWithWitness], points: &[Vec], evals: &[Evaluation], transcript: &mut impl Transcript, @@ -769,7 +769,7 @@ where fn simple_batch_open( pp: &Self::ProverParam, polys: &[ArcMultilinearExtension], - comm: &Self::CommitmentWithData, + comm: &Self::CommitmentWithWitness, point: &[E], evals: &[E], transcript: &mut impl Transcript, diff --git a/mpcs/src/basefold/commit_phase.rs b/mpcs/src/basefold/commit_phase.rs index 7d6e0b949..55a6acea5 100644 --- a/mpcs/src/basefold/commit_phase.rs +++ b/mpcs/src/basefold/commit_phase.rs @@ -27,13 +27,13 @@ use rayon::prelude::{ ParallelSlice, }; -use super::structure::BasefoldCommitmentWithData; +use super::structure::BasefoldCommitmentWithWitness; // outputs (trees, sumcheck_oracles, oracles, bh_evals, eq, eval) pub fn commit_phase>( pp: &>::ProverParameters, point: &[E], - comm: &BasefoldCommitmentWithData, + comm: &BasefoldCommitmentWithWitness, transcript: &mut impl Transcript, num_vars: usize, num_rounds: usize, @@ -179,7 +179,7 @@ where pub fn batch_commit_phase>( pp: &>::ProverParameters, point: &[E], - comms: &[BasefoldCommitmentWithData], + comms: &[BasefoldCommitmentWithWitness], transcript: &mut impl Transcript, num_vars: usize, num_rounds: usize, @@ -350,7 +350,7 @@ pub fn simple_batch_commit_phase>( pp: &>::ProverParameters, point: &[E], batch_coeffs: &[E], - comm: &BasefoldCommitmentWithData, + comm: &BasefoldCommitmentWithWitness, transcript: &mut impl Transcript, num_vars: usize, num_rounds: usize, diff --git a/mpcs/src/basefold/query_phase.rs b/mpcs/src/basefold/query_phase.rs index f0db40890..9ec15d36b 100644 --- a/mpcs/src/basefold/query_phase.rs +++ b/mpcs/src/basefold/query_phase.rs @@ -25,12 +25,12 @@ use rayon::{ use super::{ encoding::EncodingScheme, - structure::{BasefoldCommitment, BasefoldCommitmentWithData, BasefoldSpec}, + structure::{BasefoldCommitment, BasefoldCommitmentWithWitness, BasefoldSpec}, }; pub fn prover_query_phase( transcript: &mut impl Transcript, - comm: &BasefoldCommitmentWithData, + comm: &BasefoldCommitmentWithWitness, trees: &[MerkleTree], num_verifier_queries: usize, ) -> QueriesResult @@ -67,7 +67,7 @@ where pub fn batch_prover_query_phase( transcript: &mut impl Transcript, codeword_size: usize, - comms: &[BasefoldCommitmentWithData], + comms: &[BasefoldCommitmentWithWitness], trees: &[MerkleTree], num_verifier_queries: usize, ) -> BatchedQueriesResult @@ -103,7 +103,7 @@ where pub fn simple_batch_prover_query_phase( transcript: &mut impl Transcript, - comm: &BasefoldCommitmentWithData, + comm: &BasefoldCommitmentWithWitness, trees: &[MerkleTree], num_verifier_queries: usize, ) -> SimpleBatchQueriesResult @@ -411,7 +411,7 @@ where } fn batch_basefold_get_query( - comms: &[BasefoldCommitmentWithData], + comms: &[BasefoldCommitmentWithWitness], trees: &[MerkleTree], codeword_size: usize, x_index: usize, @@ -828,7 +828,7 @@ where pub fn from_single_query_result( single_query_result: SingleQueryResult, oracle_trees: &[MerkleTree], - commitment: &BasefoldCommitmentWithData, + commitment: &BasefoldCommitmentWithWitness, ) -> Self { assert!(commitment.codeword_tree.height() > 0); Self { @@ -927,7 +927,7 @@ where pub fn from_query_result( query_result: QueriesResult, oracle_trees: &[MerkleTree], - commitment: &BasefoldCommitmentWithData, + commitment: &BasefoldCommitmentWithWitness, ) -> Self { Self { inner: query_result @@ -1002,7 +1002,7 @@ where pub fn from_batched_single_query_result( batched_single_query_result: BatchedSingleQueryResult, oracle_trees: &[MerkleTree], - commitments: &[BasefoldCommitmentWithData], + commitments: &[BasefoldCommitmentWithWitness], ) -> Self { Self { oracle_query: OracleListQueryResultWithMerklePath::from_query_and_trees( @@ -1147,7 +1147,7 @@ where pub fn from_batched_query_result( batched_query_result: BatchedQueriesResult, oracle_trees: &[MerkleTree], - commitments: &[BasefoldCommitmentWithData], + commitments: &[BasefoldCommitmentWithWitness], ) -> Self { Self { inner: batched_query_result @@ -1307,7 +1307,7 @@ where pub fn from_single_query_result( single_query_result: SimpleBatchSingleQueryResult, oracle_trees: &[MerkleTree], - commitment: &BasefoldCommitmentWithData, + commitment: &BasefoldCommitmentWithWitness, ) -> Self { Self { oracle_query: OracleListQueryResultWithMerklePath::from_query_and_trees( @@ -1403,7 +1403,7 @@ where pub fn from_query_result( query_result: SimpleBatchQueriesResult, oracle_trees: &[MerkleTree], - commitment: &BasefoldCommitmentWithData, + commitment: &BasefoldCommitmentWithWitness, ) -> Self { Self { inner: query_result diff --git a/mpcs/src/basefold/structure.rs b/mpcs/src/basefold/structure.rs index 0cb0748a0..129409efd 100644 --- a/mpcs/src/basefold/structure.rs +++ b/mpcs/src/basefold/structure.rs @@ -58,9 +58,8 @@ pub struct BasefoldVerifierParams> { /// A polynomial commitment together with all the data (e.g., the codeword, and Merkle tree) /// used to generate this commitment and for assistant in opening -#[derive(Clone, Debug, Default, Serialize, Deserialize)] -#[serde(bound(serialize = "E: Serialize", deserialize = "E: DeserializeOwned"))] -pub struct BasefoldCommitmentWithData +#[derive(Clone, Debug, Default)] +pub struct BasefoldCommitmentWithWitness where E::BaseField: Serialize + DeserializeOwned, { @@ -71,7 +70,7 @@ where pub(crate) num_polys: usize, } -impl BasefoldCommitmentWithData +impl BasefoldCommitmentWithWitness where E::BaseField: Serialize + DeserializeOwned, { @@ -133,20 +132,20 @@ where } } -impl From> for Digest +impl From> for Digest where E::BaseField: Serialize + DeserializeOwned, { - fn from(val: BasefoldCommitmentWithData) -> Self { + fn from(val: BasefoldCommitmentWithWitness) -> Self { val.get_root_as() } } -impl From<&BasefoldCommitmentWithData> for BasefoldCommitment +impl From<&BasefoldCommitmentWithWitness> for BasefoldCommitment where E::BaseField: Serialize + DeserializeOwned, { - fn from(val: &BasefoldCommitmentWithData) -> Self { + fn from(val: &BasefoldCommitmentWithWitness) -> Self { val.to_commitment() } } @@ -194,7 +193,7 @@ where } } -impl PartialEq for BasefoldCommitmentWithData +impl PartialEq for BasefoldCommitmentWithWitness where E::BaseField: Serialize + DeserializeOwned, { @@ -204,7 +203,7 @@ where } } -impl Eq for BasefoldCommitmentWithData where +impl Eq for BasefoldCommitmentWithWitness where E::BaseField: Serialize + DeserializeOwned { } @@ -266,7 +265,7 @@ where } } -impl AsRef<[Digest]> for BasefoldCommitmentWithData +impl AsRef<[Digest]> for BasefoldCommitmentWithWitness where E::BaseField: Serialize + DeserializeOwned, { diff --git a/mpcs/src/lib.rs b/mpcs/src/lib.rs index e9c67b866..dcc6b6725 100644 --- a/mpcs/src/lib.rs +++ b/mpcs/src/lib.rs @@ -12,7 +12,8 @@ pub mod util; pub type Commitment = >::Commitment; pub type CommitmentChunk = >::CommitmentChunk; -pub type CommitmentWithData = >::CommitmentWithData; +pub type CommitmentWithWitness = + >::CommitmentWithWitness; pub type Param = >::Param; pub type ProverParam = >::ProverParam; @@ -34,7 +35,7 @@ pub fn pcs_trim>( pub fn pcs_commit>( pp: &Pcs::ProverParam, poly: &DenseMultilinearExtension, -) -> Result { +) -> Result { Pcs::commit(pp, poly) } @@ -42,14 +43,14 @@ pub fn pcs_commit_and_write, transcript: &mut impl Transcript, -) -> Result { +) -> Result { Pcs::commit_and_write(pp, poly, transcript) } pub fn pcs_batch_commit>( pp: &Pcs::ProverParam, polys: &[DenseMultilinearExtension], -) -> Result { +) -> Result { Pcs::batch_commit(pp, polys) } @@ -57,14 +58,14 @@ pub fn pcs_batch_commit_and_write], transcript: &mut impl Transcript, -) -> Result { +) -> Result { Pcs::batch_commit_and_write(pp, polys, transcript) } pub fn pcs_open>( pp: &Pcs::ProverParam, poly: &DenseMultilinearExtension, - comm: &Pcs::CommitmentWithData, + comm: &Pcs::CommitmentWithWitness, point: &[E], eval: &E, transcript: &mut impl Transcript, @@ -75,7 +76,7 @@ pub fn pcs_open>( pub fn pcs_batch_open>( pp: &Pcs::ProverParam, polys: &[DenseMultilinearExtension], - comms: &[Pcs::CommitmentWithData], + comms: &[Pcs::CommitmentWithWitness], points: &[Vec], evals: &[Evaluation], transcript: &mut impl Transcript, @@ -112,7 +113,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { type Param: Clone + Debug + Serialize + DeserializeOwned; type ProverParam: Clone + Debug + Serialize + DeserializeOwned; type VerifierParam: Clone + Debug + Serialize + DeserializeOwned; - type CommitmentWithData: Clone + Debug + Default + Serialize + DeserializeOwned; + type CommitmentWithWitness: Clone + Debug; type Commitment: Clone + Debug + Default + Serialize + DeserializeOwned; type CommitmentChunk: Clone + Debug + Default; type Proof: Clone + Debug + Serialize + DeserializeOwned; @@ -127,13 +128,13 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { fn commit( pp: &Self::ProverParam, poly: &DenseMultilinearExtension, - ) -> Result; + ) -> Result; fn commit_and_write( pp: &Self::ProverParam, poly: &DenseMultilinearExtension, transcript: &mut impl Transcript, - ) -> Result { + ) -> Result { let comm = Self::commit(pp, poly)?; Self::write_commitment(&Self::get_pure_commitment(&comm), transcript)?; Ok(comm) @@ -144,18 +145,18 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { transcript: &mut impl Transcript, ) -> Result<(), Error>; - fn get_pure_commitment(comm: &Self::CommitmentWithData) -> Self::Commitment; + fn get_pure_commitment(comm: &Self::CommitmentWithWitness) -> Self::Commitment; fn batch_commit( pp: &Self::ProverParam, polys: &[DenseMultilinearExtension], - ) -> Result; + ) -> Result; fn batch_commit_and_write( pp: &Self::ProverParam, polys: &[DenseMultilinearExtension], transcript: &mut impl Transcript, - ) -> Result { + ) -> Result { let comm = Self::batch_commit(pp, polys)?; Self::write_commitment(&Self::get_pure_commitment(&comm), transcript)?; Ok(comm) @@ -164,7 +165,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { fn open( pp: &Self::ProverParam, poly: &DenseMultilinearExtension, - comm: &Self::CommitmentWithData, + comm: &Self::CommitmentWithWitness, point: &[E], eval: &E, transcript: &mut impl Transcript, @@ -173,7 +174,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { fn batch_open( pp: &Self::ProverParam, polys: &[DenseMultilinearExtension], - comms: &[Self::CommitmentWithData], + comms: &[Self::CommitmentWithWitness], points: &[Vec], evals: &[Evaluation], transcript: &mut impl Transcript, @@ -186,7 +187,7 @@ pub trait PolynomialCommitmentScheme: Clone + Debug { fn simple_batch_open( pp: &Self::ProverParam, polys: &[ArcMultilinearExtension], - comm: &Self::CommitmentWithData, + comm: &Self::CommitmentWithWitness, point: &[E], evals: &[E], transcript: &mut impl Transcript, @@ -228,7 +229,7 @@ where fn ni_open( pp: &Self::ProverParam, poly: &DenseMultilinearExtension, - comm: &Self::CommitmentWithData, + comm: &Self::CommitmentWithWitness, point: &[E], eval: &E, ) -> Result { @@ -239,7 +240,7 @@ where fn ni_batch_open( pp: &Self::ProverParam, polys: &[DenseMultilinearExtension], - comms: &[Self::CommitmentWithData], + comms: &[Self::CommitmentWithWitness], points: &[Vec], evals: &[Evaluation], ) -> Result { @@ -315,7 +316,7 @@ pub enum Error { mod basefold; pub use basefold::{ Basecode, BasecodeDefaultSpec, Basefold, BasefoldBasecodeParams, BasefoldCommitment, - BasefoldCommitmentWithData, BasefoldDefault, BasefoldParams, BasefoldRSParams, BasefoldSpec, + BasefoldCommitmentWithWitness, BasefoldDefault, BasefoldParams, BasefoldRSParams, BasefoldSpec, EncodingScheme, RSCode, RSCodeDefaultSpec, coset_fft, fft, fft_root_table, one_level_eval_hc, one_level_interp_hc, }; @@ -436,7 +437,7 @@ pub mod test_util { pp: &Pcs::ProverParam, polys: &[DenseMultilinearExtension], transcript: &mut impl Transcript, - ) -> Vec { + ) -> Vec { polys .iter() .map(|poly| Pcs::commit_and_write(pp, poly, transcript).unwrap())