Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPCS: Rename CommitmentWithData to CommitmentWithWitness & remove unnecessary trait requirement. #745

Merged
merged 3 commits into from
Dec 13, 2024
Merged
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
4 changes: 2 additions & 2 deletions ceno_zkvm/src/scheme/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
pp: &PCS::ProverParam,
circuit_pk: &ProvingKey<E, PCS>,
witnesses: Vec<ArcMultilinearExtension<'_, E>>,
wits_commit: PCS::CommitmentWithData,
wits_commit: PCS::CommitmentWithWitness,
pi: &[ArcMultilinearExtension<'_, E>],
num_instances: usize,
transcript: &mut impl Transcript<E>,
Expand Down Expand Up @@ -661,7 +661,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
pp: &PCS::ProverParam,
circuit_pk: &ProvingKey<E, PCS>,
witnesses: Vec<ArcMultilinearExtension<'_, E>>,
wits_commit: PCS::CommitmentWithData,
wits_commit: PCS::CommitmentWithWitness,
pi: &[ArcMultilinearExtension<'_, E>],
transcript: &mut impl Transcript<E>,
challenges: &[E; 2],
Expand Down
2 changes: 1 addition & 1 deletion ceno_zkvm/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<F: Clone> PointAndEval<F> {
#[derive(Clone, Debug)]
pub struct ProvingKey<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> {
pub fixed_traces: Option<Vec<DenseMultilinearExtension<E>>>,
pub fixed_commit_wd: Option<PCS::CommitmentWithData>,
pub fixed_commit_wd: Option<PCS::CommitmentWithWitness>,
pub vk: VerifyingKey<E, PCS>,
}

Expand Down
28 changes: 14 additions & 14 deletions mpcs/src/basefold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type SumCheck<F> = ClassicSumCheck<CoefficientsProver<F>>;

mod structure;
pub use structure::{
Basefold, BasefoldBasecodeParams, BasefoldCommitment, BasefoldCommitmentWithData,
Basefold, BasefoldBasecodeParams, BasefoldCommitment, BasefoldCommitmentWithWitness,
BasefoldDefault, BasefoldParams, BasefoldProverParams, BasefoldRSParams,
BasefoldVerifierParams,
};
Expand Down Expand Up @@ -273,7 +273,7 @@ where
type Param = BasefoldParams<E, Spec>;
type ProverParam = BasefoldProverParams<E, Spec>;
type VerifierParam = BasefoldVerifierParams<E, Spec>;
type CommitmentWithData = BasefoldCommitmentWithData<E>;
type CommitmentWithWitness = BasefoldCommitmentWithWitness<E>;
type Commitment = BasefoldCommitment<E>;
type CommitmentChunk = Digest<E::BaseField>;
type Proof = BasefoldProof<E>;
Expand Down Expand Up @@ -307,7 +307,7 @@ where
fn commit(
pp: &Self::ProverParam,
poly: &DenseMultilinearExtension<E>,
) -> Result<Self::CommitmentWithData, Error> {
) -> Result<Self::CommitmentWithWitness, Error> {
let timer = start_timer!(|| "Basefold::commit");

let is_base = match poly.evaluations {
Expand All @@ -325,9 +325,9 @@ where
PolyEvalsCodeword::Normal((bh_evals, codeword)) => {
let codeword_tree = MerkleTree::<E>::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,
Expand All @@ -338,9 +338,9 @@ where
PolyEvalsCodeword::TooSmall(evals) => {
let codeword_tree = MerkleTree::<E>::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,
Expand All @@ -359,7 +359,7 @@ where
fn batch_commit(
pp: &Self::ProverParam,
polys: &[DenseMultilinearExtension<E>],
) -> Result<Self::CommitmentWithData, Error> {
) -> Result<Self::CommitmentWithWitness, Error> {
// assumptions
// 1. there must be at least one polynomial
// 2. all polynomials must exist in the same field type
Expand Down Expand Up @@ -413,7 +413,7 @@ where
})
.collect::<(Vec<_>, Vec<_>)>();
let codeword_tree = MerkleTree::<E>::from_batch_leaves(codewords);
Self::CommitmentWithData {
Self::CommitmentWithWitness {
codeword_tree,
polynomials_bh_evals: bh_evals,
num_vars: polys[0].num_vars,
Expand All @@ -433,7 +433,7 @@ where
})
.collect::<Vec<_>>();
let codeword_tree = MerkleTree::<E>::from_batch_leaves(bh_evals.clone());
Self::CommitmentWithData {
Self::CommitmentWithWitness {
codeword_tree,
polynomials_bh_evals: bh_evals,
num_vars: polys[0].num_vars,
Expand All @@ -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()
}

Expand All @@ -467,7 +467,7 @@ where
fn open(
pp: &Self::ProverParam,
poly: &DenseMultilinearExtension<E>,
comm: &Self::CommitmentWithData,
comm: &Self::CommitmentWithWitness,
point: &[E],
_eval: &E, // Opening does not need eval, except for sanity check
transcript: &mut impl Transcript<E>,
Expand Down Expand Up @@ -547,7 +547,7 @@ where
fn batch_open(
pp: &Self::ProverParam,
polys: &[DenseMultilinearExtension<E>],
comms: &[Self::CommitmentWithData],
comms: &[Self::CommitmentWithWitness],
points: &[Vec<E>],
evals: &[Evaluation<E>],
transcript: &mut impl Transcript<E>,
Expand Down Expand Up @@ -769,7 +769,7 @@ where
fn simple_batch_open(
pp: &Self::ProverParam,
polys: &[ArcMultilinearExtension<E>],
comm: &Self::CommitmentWithData,
comm: &Self::CommitmentWithWitness,
point: &[E],
evals: &[E],
transcript: &mut impl Transcript<E>,
Expand Down
8 changes: 4 additions & 4 deletions mpcs/src/basefold/commit_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E: ExtensionField, Spec: BasefoldSpec<E>>(
pp: &<Spec::EncodingScheme as EncodingScheme<E>>::ProverParameters,
point: &[E],
comm: &BasefoldCommitmentWithData<E>,
comm: &BasefoldCommitmentWithWitness<E>,
transcript: &mut impl Transcript<E>,
num_vars: usize,
num_rounds: usize,
Expand Down Expand Up @@ -179,7 +179,7 @@ where
pub fn batch_commit_phase<E: ExtensionField, Spec: BasefoldSpec<E>>(
pp: &<Spec::EncodingScheme as EncodingScheme<E>>::ProverParameters,
point: &[E],
comms: &[BasefoldCommitmentWithData<E>],
comms: &[BasefoldCommitmentWithWitness<E>],
transcript: &mut impl Transcript<E>,
num_vars: usize,
num_rounds: usize,
Expand Down Expand Up @@ -350,7 +350,7 @@ pub fn simple_batch_commit_phase<E: ExtensionField, Spec: BasefoldSpec<E>>(
pp: &<Spec::EncodingScheme as EncodingScheme<E>>::ProverParameters,
point: &[E],
batch_coeffs: &[E],
comm: &BasefoldCommitmentWithData<E>,
comm: &BasefoldCommitmentWithWitness<E>,
transcript: &mut impl Transcript<E>,
num_vars: usize,
num_rounds: usize,
Expand Down
22 changes: 11 additions & 11 deletions mpcs/src/basefold/query_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use rayon::{

use super::{
encoding::EncodingScheme,
structure::{BasefoldCommitment, BasefoldCommitmentWithData, BasefoldSpec},
structure::{BasefoldCommitment, BasefoldCommitmentWithWitness, BasefoldSpec},
};

pub fn prover_query_phase<E: ExtensionField>(
transcript: &mut impl Transcript<E>,
comm: &BasefoldCommitmentWithData<E>,
comm: &BasefoldCommitmentWithWitness<E>,
trees: &[MerkleTree<E>],
num_verifier_queries: usize,
) -> QueriesResult<E>
Expand Down Expand Up @@ -67,7 +67,7 @@ where
pub fn batch_prover_query_phase<E: ExtensionField>(
transcript: &mut impl Transcript<E>,
codeword_size: usize,
comms: &[BasefoldCommitmentWithData<E>],
comms: &[BasefoldCommitmentWithWitness<E>],
trees: &[MerkleTree<E>],
num_verifier_queries: usize,
) -> BatchedQueriesResult<E>
Expand Down Expand Up @@ -103,7 +103,7 @@ where

pub fn simple_batch_prover_query_phase<E: ExtensionField>(
transcript: &mut impl Transcript<E>,
comm: &BasefoldCommitmentWithData<E>,
comm: &BasefoldCommitmentWithWitness<E>,
trees: &[MerkleTree<E>],
num_verifier_queries: usize,
) -> SimpleBatchQueriesResult<E>
Expand Down Expand Up @@ -411,7 +411,7 @@ where
}

fn batch_basefold_get_query<E: ExtensionField>(
comms: &[BasefoldCommitmentWithData<E>],
comms: &[BasefoldCommitmentWithWitness<E>],
trees: &[MerkleTree<E>],
codeword_size: usize,
x_index: usize,
Expand Down Expand Up @@ -828,7 +828,7 @@ where
pub fn from_single_query_result(
single_query_result: SingleQueryResult<E>,
oracle_trees: &[MerkleTree<E>],
commitment: &BasefoldCommitmentWithData<E>,
commitment: &BasefoldCommitmentWithWitness<E>,
) -> Self {
assert!(commitment.codeword_tree.height() > 0);
Self {
Expand Down Expand Up @@ -927,7 +927,7 @@ where
pub fn from_query_result(
query_result: QueriesResult<E>,
oracle_trees: &[MerkleTree<E>],
commitment: &BasefoldCommitmentWithData<E>,
commitment: &BasefoldCommitmentWithWitness<E>,
) -> Self {
Self {
inner: query_result
Expand Down Expand Up @@ -1002,7 +1002,7 @@ where
pub fn from_batched_single_query_result(
batched_single_query_result: BatchedSingleQueryResult<E>,
oracle_trees: &[MerkleTree<E>],
commitments: &[BasefoldCommitmentWithData<E>],
commitments: &[BasefoldCommitmentWithWitness<E>],
) -> Self {
Self {
oracle_query: OracleListQueryResultWithMerklePath::from_query_and_trees(
Expand Down Expand Up @@ -1147,7 +1147,7 @@ where
pub fn from_batched_query_result(
batched_query_result: BatchedQueriesResult<E>,
oracle_trees: &[MerkleTree<E>],
commitments: &[BasefoldCommitmentWithData<E>],
commitments: &[BasefoldCommitmentWithWitness<E>],
) -> Self {
Self {
inner: batched_query_result
Expand Down Expand Up @@ -1307,7 +1307,7 @@ where
pub fn from_single_query_result(
single_query_result: SimpleBatchSingleQueryResult<E>,
oracle_trees: &[MerkleTree<E>],
commitment: &BasefoldCommitmentWithData<E>,
commitment: &BasefoldCommitmentWithWitness<E>,
) -> Self {
Self {
oracle_query: OracleListQueryResultWithMerklePath::from_query_and_trees(
Expand Down Expand Up @@ -1403,7 +1403,7 @@ where
pub fn from_query_result(
query_result: SimpleBatchQueriesResult<E>,
oracle_trees: &[MerkleTree<E>],
commitment: &BasefoldCommitmentWithData<E>,
commitment: &BasefoldCommitmentWithWitness<E>,
) -> Self {
Self {
inner: query_result
Expand Down
21 changes: 10 additions & 11 deletions mpcs/src/basefold/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ pub struct BasefoldVerifierParams<E: ExtensionField, Spec: BasefoldSpec<E>> {

/// 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<E: ExtensionField>
#[derive(Clone, Debug, Default)]
pub struct BasefoldCommitmentWithWitness<E: ExtensionField>
where
E::BaseField: Serialize + DeserializeOwned,
{
Expand All @@ -71,7 +70,7 @@ where
pub(crate) num_polys: usize,
}

impl<E: ExtensionField> BasefoldCommitmentWithData<E>
impl<E: ExtensionField> BasefoldCommitmentWithWitness<E>
where
E::BaseField: Serialize + DeserializeOwned,
{
Expand Down Expand Up @@ -133,20 +132,20 @@ where
}
}

impl<E: ExtensionField> From<BasefoldCommitmentWithData<E>> for Digest<E::BaseField>
impl<E: ExtensionField> From<BasefoldCommitmentWithWitness<E>> for Digest<E::BaseField>
where
E::BaseField: Serialize + DeserializeOwned,
{
fn from(val: BasefoldCommitmentWithData<E>) -> Self {
fn from(val: BasefoldCommitmentWithWitness<E>) -> Self {
val.get_root_as()
}
}

impl<E: ExtensionField> From<&BasefoldCommitmentWithData<E>> for BasefoldCommitment<E>
impl<E: ExtensionField> From<&BasefoldCommitmentWithWitness<E>> for BasefoldCommitment<E>
where
E::BaseField: Serialize + DeserializeOwned,
{
fn from(val: &BasefoldCommitmentWithData<E>) -> Self {
fn from(val: &BasefoldCommitmentWithWitness<E>) -> Self {
val.to_commitment()
}
}
Expand Down Expand Up @@ -194,7 +193,7 @@ where
}
}

impl<E: ExtensionField> PartialEq for BasefoldCommitmentWithData<E>
impl<E: ExtensionField> PartialEq for BasefoldCommitmentWithWitness<E>
where
E::BaseField: Serialize + DeserializeOwned,
{
Expand All @@ -204,7 +203,7 @@ where
}
}

impl<E: ExtensionField> Eq for BasefoldCommitmentWithData<E> where
impl<E: ExtensionField> Eq for BasefoldCommitmentWithWitness<E> where
E::BaseField: Serialize + DeserializeOwned
{
}
Expand Down Expand Up @@ -266,7 +265,7 @@ where
}
}

impl<E: ExtensionField> AsRef<[Digest<E::BaseField>]> for BasefoldCommitmentWithData<E>
impl<E: ExtensionField> AsRef<[Digest<E::BaseField>]> for BasefoldCommitmentWithWitness<E>
where
E::BaseField: Serialize + DeserializeOwned,
{
Expand Down
Loading