arnaucube
arnaucube/hyperplonkPublic Self-hosted repository
hyperplonk/pcs/src/lib.rs
pcs/src/lib.rsRaw
 1mod commit;
 2mod errors;
 3mod param;
 4mod util;
 5
 6use ark_ec::PairingEngine;
 7use ark_poly::MultilinearExtension;
 8use ark_std::rand::RngCore;
 9use poly_iop::IOPTranscript;
10use std::marker::PhantomData;
11
12pub use errors::PCSErrors;
13pub use param::{ProverParam, UniversalParams, VerifierParam};
14
15/// KZG Polynomial Commitment Scheme on multilinear extensions.
16pub struct KZGMultilinearPC<E: PairingEngine> {
17    #[doc(hidden)]
18    phantom: PhantomData<E>,
19}
20
21pub trait MultilinearCommitmentScheme<E: PairingEngine> {
22    type ProverParam;
23    type VerifierParam;
24    type SRS;
25    type Commitment;
26    type Proof;
27    type BatchProof;
28    type Transcript;
29
30    /// Generate SRS from RNG.
31    /// WARNING: THIS FUNCTION IS FOR TESTING PURPOSE ONLY.
32    /// THE OUTPUT SRS SHOULD NOT BE USED IN PRODUCTION.
33    fn setup<R: RngCore>(rng: &mut R, num_vars: usize) -> Result<Self::SRS, PCSErrors>;
34
35    /// Generate a commitment for a polynomial
36    fn commit(
37        prover_param: &Self::ProverParam,
38        poly: &impl MultilinearExtension<E::Fr>,
39    ) -> Result<Self::Commitment, PCSErrors>;
40
41    /// Generate a commitment for a list of polynomials
42    fn multi_commit(
43        prover_param: &Self::ProverParam,
44        polys: &[impl MultilinearExtension<E::Fr>],
45    ) -> Result<Self::Commitment, PCSErrors>;
46
47    /// On input a polynomial `p` and a point `point`, outputs a proof for the
48    /// same.
49    fn open(
50        prover_param: &Self::ProverParam,
51        polynomial: &impl MultilinearExtension<E::Fr>,
52        point: &[E::Fr],
53    ) -> Result<Self::Proof, PCSErrors>;
54
55    /// Input a list of MLEs, and a same number of points, and a transcript,
56    /// compute a multi-opening for all the polynomials.
57    #[allow(clippy::type_complexity)]
58    // TODO: remove after we KZG-commit q(x)
59    fn multi_open(
60        prover_param: &Self::ProverParam,
61        polynomials: &[impl MultilinearExtension<E::Fr>],
62        point: &[&[E::Fr]],
63        transcript: &mut Self::Transcript,
64    ) -> Result<Self::BatchProof, PCSErrors>;
65
66    /// Verifies that `value` is the evaluation at `x` of the polynomial
67    /// committed inside `comm`.
68    fn verify(
69        verifier_param: &Self::VerifierParam,
70        commitment: &Self::Commitment,
71        point: &[E::Fr],
72        value: &E::Fr,
73        proof: &Self::Proof,
74    ) -> Result<bool, PCSErrors>;
75
76    /// Verifies that `value_i` is the evaluation at `x_i` of the polynomial
77    /// `poly_i` committed inside `comm`.
78    fn batch_verify(
79        verifier_param: &Self::VerifierParam,
80        multi_commitment: &Self::Commitment,
81        points: &[&[E::Fr]],
82        batch_proof: &Self::BatchProof,
83        transcript: &mut IOPTranscript<E::Fr>,
84    ) -> Result<bool, PCSErrors>;
85}