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