Skip to content

Commit

Permalink
(wip) modify pcs trait
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosma committed Nov 30, 2024
1 parent 05acc95 commit 15d8b62
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/whir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::poly_utils::MultilinearPoint;
pub mod committer;
pub mod iopattern;
pub mod parameters;
pub mod pcs;
pub mod prover;
pub mod verifier;
mod fs_utils;
Expand All @@ -21,7 +22,7 @@ pub struct Statement<F> {
}

// Only includes the authentication paths
#[derive(Clone, CanonicalSerialize, CanonicalDeserialize)]
#[derive(Clone, Debug, CanonicalSerialize, CanonicalDeserialize)]
pub struct WhirProof<MerkleConfig, F>(Vec<(MultiPath<MerkleConfig>, Vec<Vec<F>>)>)
where
MerkleConfig: Config<Leaf = [F]>,
Expand All @@ -38,24 +39,19 @@ where
transcript.len() + whir_proof.serialized_size(ark_serialize::Compress::Yes)
}

pub trait PolynomialCommitmentScheme<E: ExtensionField>: 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 Commitment: Clone + Debug + Default + Serialize + DeserializeOwned;
type CommitmentChunk: Clone + Debug + Default;
type Proof: Clone + Debug + Serialize + DeserializeOwned;
type Poly: Clone + Debug;
type Transcript: Clone + Debug;
pub trait PolynomialCommitmentScheme<E: ExtensionField>: Clone {
type Param: Clone;
type ProverParam: Clone;
type VerifierParam: Clone;
type CommitmentWithData;
type Commitment: Clone + Default + CanonicalSerialize + CanonicalDeserialize;
type CommitmentChunk: Clone + Default;
type Proof: Clone + CanonicalSerialize + CanonicalDeserialize;
type Poly: Clone;
type Transcript: Clone;

fn setup(poly_size: usize) -> Result<Self::Param, Error>;

fn trim(
param: Self::Param,
poly_size: usize,
) -> Result<(Self::ProverParam, Self::VerifierParam), Error>;

fn commit(pp: &Self::ProverParam, poly: &Self::Poly)
-> Result<Self::CommitmentWithData, Error>;

Expand Down
126 changes: 126 additions & 0 deletions src/whir/pcs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
use crate::crypto::merkle_tree::blake3::{CompressH, MerkleTreeParams};
use crate::whir::committer::Witness;
use crate::whir::parameters::WhirConfig;
use crate::whir::Error;
use crate::whir::PolynomialCommitmentScheme;
use crate::whir::WhirProof;

use ark_crypto_primitives::crh::TwoToOneCRHScheme;
use ark_ff::FftField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use goldilocks::ExtensionField;
use std::fmt::Debug;
use std::marker::PhantomData;

#[derive(Debug, Clone)]
pub struct Whir<E>(PhantomData<E>);

type WhirPCSConfig<E> = WhirConfig<E, MerkleTreeParams<E>, ()>;

impl<E> PolynomialCommitmentScheme<E> for Whir<E>
where
E: FftField + ExtensionField + CanonicalSerialize + CanonicalDeserialize,
{
type Param = WhirPCSConfig<E>;
type ProverParam = WhirPCSConfig<E>;
type VerifierParam = WhirPCSConfig<E>;
type CommitmentWithData = Witness<E, MerkleTreeParams<E>>;
type Commitment = <CompressH as TwoToOneCRHScheme>::Output;
type CommitmentChunk = <CompressH as TwoToOneCRHScheme>::Output;
type Proof = WhirProof<MerkleTreeParams<E>, E>;
type Poly = ();
type Transcript = ();

fn setup(_poly_size: usize) -> Result<Self::Param, Error> {
todo!()
}

fn commit(
_pp: &Self::ProverParam,
_poly: &Self::Poly,
) -> Result<Self::CommitmentWithData, Error> {
todo!()
}

fn commit_and_write(
pp: &Self::ProverParam,
poly: &Self::Poly,
transcript: &mut Self::Transcript,
) -> Result<Self::CommitmentWithData, Error> {
let comm = Self::commit(pp, poly)?;
Self::write_commitment(&Self::get_pure_commitment(&comm), transcript)?;
Ok(comm)
}

fn write_commitment(
_comm: &Self::Commitment,
_transcript: &mut Self::Transcript,
) -> Result<(), Error> {
todo!()
}

fn get_pure_commitment(_comm: &Self::CommitmentWithData) -> Self::Commitment {
todo!()
}

fn batch_commit(
_pp: &Self::ProverParam,
_polys: &[Self::Poly],
) -> Result<Self::CommitmentWithData, Error> {
todo!()
}

fn batch_commit_and_write(
pp: &Self::ProverParam,
polys: &[Self::Poly],
transcript: &mut Self::Transcript,
) -> Result<Self::CommitmentWithData, Error> {
let comm = Self::batch_commit(pp, polys)?;
Self::write_commitment(&Self::get_pure_commitment(&comm), transcript)?;
Ok(comm)
}

fn open(
_pp: &Self::ProverParam,
_poly: &Self::Poly,
_comm: &Self::CommitmentWithData,
_point: &[E],
_eval: &E,
_transcript: &mut Self::Transcript,
) -> Result<Self::Proof, Error> {
todo!()
}

fn batch_open(
_pp: &Self::ProverParam,
_polys: &[Self::Poly],
_comm: &Self::CommitmentWithData,
_point: &[E],
_evals: &[E],
_transcript: &mut Self::Transcript,
) -> Result<Self::Proof, Error> {
todo!()
}

fn verify(
_vp: &Self::VerifierParam,
_comm: &Self::Commitment,
_point: &[E],
_eval: &E,
_proof: &Self::Proof,
_transcript: &mut Self::Transcript,
) -> Result<(), Error> {
todo!()
}

fn batch_verify(
_vp: &Self::VerifierParam,
_comm: &Self::Commitment,
_point: &[E],
_evals: &[E],
_proof: &Self::Proof,
_transcript: &mut Self::Transcript,
) -> Result<(), Error> {
todo!()
}
}

0 comments on commit 15d8b62

Please sign in to comment.