arnaucube
arnaucube/hyperplonkPublic Self-hosted repository
hyperplonk/pcs/src/lib.rs
pcs/src/lib.rsRaw
  1mod errors;
  2mod multilinear_kzg;
  3mod structs;
  4mod univariate_kzg;
  5
  6pub mod prelude;
  7
  8use ark_ec::PairingEngine;
  9use ark_std::rand::RngCore;
 10use errors::PCSErrors;
 11
 12/// This trait defines APIs for polynomial commitment schemes.
 13/// Note that for our usage of PCS, we do not require the hiding property.
 14pub trait PolynomialCommitmentScheme<E: PairingEngine> {
 15    // Parameters
 16    type ProverParam;
 17    type VerifierParam;
 18    type SRS;
 19    // Polynomial and its associated types
 20    type Polynomial;
 21    type Point;
 22    type Evaluation;
 23    // Commitments and proofs
 24    type Commitment;
 25    type Proof;
 26    type BatchProof;
 27    type BatchCommitment;
 28
 29    /// Build SRS for testing.
 30    ///
 31    /// - For univariate polynomials, `log_size` is the log of maximum degree.
 32    /// - For multilinear polynomials, `log_size` is the number of variables.
 33    ///
 34    /// WARNING: THIS FUNCTION IS FOR TESTING PURPOSE ONLY.
 35    /// THE OUTPUT SRS SHOULD NOT BE USED IN PRODUCTION.
 36    fn gen_srs_for_testing<R: RngCore>(
 37        rng: &mut R,
 38        log_size: usize,
 39    ) -> Result<Self::SRS, PCSErrors>;
 40
 41    /// Generate a commitment for a polynomial
 42    fn commit(
 43        prover_param: &Self::ProverParam,
 44        poly: &Self::Polynomial,
 45    ) -> Result<Self::Commitment, PCSErrors>;
 46
 47    /// Generate a commitment for a list of polynomials
 48    fn multi_commit(
 49        prover_param: &Self::ProverParam,
 50        polys: &[Self::Polynomial],
 51    ) -> Result<Self::BatchCommitment, PCSErrors>;
 52
 53    /// On input a polynomial `p` and a point `point`, outputs a proof for the
 54    /// same.
 55    fn open(
 56        prover_param: &Self::ProverParam,
 57        polynomial: &Self::Polynomial,
 58        point: &Self::Point,
 59    ) -> Result<(Self::Proof, Self::Evaluation), PCSErrors>;
 60
 61    /// Input a list of MLEs, and a same number of points, and a transcript,
 62    /// compute a multi-opening for all the polynomials.
 63    fn multi_open(
 64        prover_param: &Self::ProverParam,
 65        multi_commitment: &Self::Commitment,
 66        polynomials: &[Self::Polynomial],
 67        points: &[Self::Point],
 68    ) -> Result<(Self::BatchProof, Vec<Self::Evaluation>), PCSErrors>;
 69
 70    /// Verifies that `value` is the evaluation at `x` of the polynomial
 71    /// committed inside `comm`.
 72    fn verify(
 73        verifier_param: &Self::VerifierParam,
 74        commitment: &Self::Commitment,
 75        point: &Self::Point,
 76        value: &E::Fr,
 77        proof: &Self::Proof,
 78    ) -> Result<bool, PCSErrors>;
 79
 80    /// Verifies that `value_i` is the evaluation at `x_i` of the polynomial
 81    /// `poly_i` committed inside `comm`.
 82    fn batch_verify<R: RngCore>(
 83        verifier_param: &Self::VerifierParam,
 84        multi_commitment: &Self::BatchCommitment,
 85        points: &[Self::Point],
 86        values: &[E::Fr],
 87        batch_proof: &Self::BatchProof,
 88        rng: &mut R,
 89    ) -> Result<bool, PCSErrors>;
 90}
 91
 92/// API definitions for structured reference string
 93pub trait StructuredReferenceString<E: PairingEngine>: Sized {
 94    type ProverParam;
 95    type VerifierParam;
 96
 97    /// Extract the prover parameters from the public parameters.
 98    fn extract_prover_param(&self, supported_log_size: usize) -> Self::ProverParam;
 99    /// Extract the verifier parameters from the public parameters.
100    fn extract_verifier_param(&self, supported_log_size: usize) -> Self::VerifierParam;
101
102    /// Trim the universal parameters to specialize the public parameters
103    /// for polynomials to the given `supported_log_size`, and
104    /// returns committer key and verifier key.
105    ///
106    /// - For univariate polynomials, `supported_log_size` is the log of maximum
107    ///   degree.
108    /// - For multilinear polynomials, `supported_log_size` is the number of
109    ///   variables.
110    ///
111    /// `supported_log_size` should be in range `1..=params.log_size`
112    fn trim(
113        &self,
114        supported_log_size: usize,
115    ) -> Result<(Self::ProverParam, Self::VerifierParam), PCSErrors>;
116
117    /// Build SRS for testing.
118    ///
119    /// - For univariate polynomials, `log_size` is the log of maximum degree.
120    /// - For multilinear polynomials, `log_size` is the number of variables.
121    ///
122    /// WARNING: THIS FUNCTION IS FOR TESTING PURPOSE ONLY.
123    /// THE OUTPUT SRS SHOULD NOT BE USED IN PRODUCTION.
124    fn gen_srs_for_testing<R: RngCore>(rng: &mut R, log_size: usize) -> Result<Self, PCSErrors>;
125}