hyperplonk/subroutines/src/pcs/mod.rs
subroutines/src/pcs/mod.rsRaw
1mod errors;
2mod multilinear_kzg;
3mod structs;
4mod univariate_kzg;
5
6pub mod prelude;
7
8use ark_ec::PairingEngine;
9use ark_ff::Field;
10use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
11use ark_std::rand::{CryptoRng, RngCore};
12use errors::PCSError;
13use std::{borrow::Borrow, fmt::Debug, hash::Hash};
14use transcript::IOPTranscript;
15
16/// This trait defines APIs for polynomial commitment schemes.
17/// Note that for our usage of PCS, we do not require the hiding property.
18pub trait PolynomialCommitmentScheme<E: PairingEngine> {
19 /// Prover parameters
20 type ProverParam: Clone + Sync;
21 /// Verifier parameters
22 type VerifierParam: Clone + CanonicalSerialize + CanonicalDeserialize;
23 /// Structured reference string
24 type SRS: Clone + Debug;
25 /// Polynomial and its associated types
26 type Polynomial: Clone + Debug + Hash + PartialEq + Eq;
27 /// Polynomial input domain
28 type Point: Clone + Ord + Debug + Sync + Hash + PartialEq + Eq;
29 /// Polynomial Evaluation
30 type Evaluation: Field;
31 /// Commitments
32 type Commitment: Clone + CanonicalSerialize + CanonicalDeserialize + Debug + PartialEq + Eq;
33 /// Proofs
34 type Proof: Clone + CanonicalSerialize + CanonicalDeserialize + Debug + PartialEq + Eq;
35 /// Batch proofs
36 type BatchProof;
37
38 /// Build SRS for testing.
39 ///
40 /// - For univariate polynomials, `supported_size` is the maximum degree.
41 /// - For multilinear polynomials, `supported_size` is the number of
42 /// variables.
43 ///
44 /// WARNING: THIS FUNCTION IS FOR TESTING PURPOSE ONLY.
45 /// THE OUTPUT SRS SHOULD NOT BE USED IN PRODUCTION.
46 fn gen_srs_for_testing<R: RngCore + CryptoRng>(
47 rng: &mut R,
48 supported_size: usize,
49 ) -> Result<Self::SRS, PCSError>;
50
51 /// Trim the universal parameters to specialize the public parameters.
52 /// Input both `supported_degree` for univariate and
53 /// `supported_num_vars` for multilinear.
54 /// ## Note on function signature
55 /// Usually, data structure like SRS and ProverParam are huge and users
56 /// might wish to keep them in heap using different kinds of smart pointers
57 /// (instead of only in stack) therefore our `impl Borrow<_>` interface
58 /// allows for passing in any pointer type, e.g.: `trim(srs: &Self::SRS,
59 /// ..)` or `trim(srs: Box<Self::SRS>, ..)` or `trim(srs: Arc<Self::SRS>,
60 /// ..)` etc.
61 fn trim(
62 srs: impl Borrow<Self::SRS>,
63 supported_degree: Option<usize>,
64 supported_num_vars: Option<usize>,
65 ) -> Result<(Self::ProverParam, Self::VerifierParam), PCSError>;
66
67 /// Generate a commitment for a polynomial
68 /// ## Note on function signature
69 /// Usually, data structure like SRS and ProverParam are huge and users
70 /// might wish to keep them in heap using different kinds of smart pointers
71 /// (instead of only in stack) therefore our `impl Borrow<_>` interface
72 /// allows for passing in any pointer type, e.g.: `commit(prover_param:
73 /// &Self::ProverParam, ..)` or `commit(prover_param:
74 /// Box<Self::ProverParam>, ..)` or `commit(prover_param:
75 /// Arc<Self::ProverParam>, ..)` etc.
76 fn commit(
77 prover_param: impl Borrow<Self::ProverParam>,
78 poly: &Self::Polynomial,
79 ) -> Result<Self::Commitment, PCSError>;
80
81 /// On input a polynomial `p` and a point `point`, outputs a proof for the
82 /// same.
83 fn open(
84 prover_param: impl Borrow<Self::ProverParam>,
85 polynomial: &Self::Polynomial,
86 point: &Self::Point,
87 ) -> Result<(Self::Proof, Self::Evaluation), PCSError>;
88
89 /// Input a list of multilinear extensions, and a same number of points, and
90 /// a transcript, compute a multi-opening for all the polynomials.
91 fn multi_open(
92 _prover_param: impl Borrow<Self::ProverParam>,
93 _polynomials: &[Self::Polynomial],
94 _points: &[Self::Point],
95 _evals: &[Self::Evaluation],
96 _transcript: &mut IOPTranscript<E::Fr>,
97 ) -> Result<Self::BatchProof, PCSError> {
98 // the reason we use unimplemented!() is to enable developers to implement the
99 // trait without always implementing the batching APIs.
100 unimplemented!()
101 }
102
103 /// Verifies that `value` is the evaluation at `x` of the polynomial
104 /// committed inside `comm`.
105 fn verify(
106 verifier_param: &Self::VerifierParam,
107 commitment: &Self::Commitment,
108 point: &Self::Point,
109 value: &E::Fr,
110 proof: &Self::Proof,
111 ) -> Result<bool, PCSError>;
112
113 /// Verifies that `value_i` is the evaluation at `x_i` of the polynomial
114 /// `poly_i` committed inside `comm`.
115 fn batch_verify(
116 _verifier_param: &Self::VerifierParam,
117 _commitments: &[Self::Commitment],
118 _points: &[Self::Point],
119 _batch_proof: &Self::BatchProof,
120 _transcript: &mut IOPTranscript<E::Fr>,
121 ) -> Result<bool, PCSError> {
122 // the reason we use unimplemented!() is to enable developers to implement the
123 // trait without always implementing the batching APIs.
124 unimplemented!()
125 }
126}
127
128/// API definitions for structured reference string
129pub trait StructuredReferenceString<E: PairingEngine>: Sized {
130 /// Prover parameters
131 type ProverParam;
132 /// Verifier parameters
133 type VerifierParam;
134
135 /// Extract the prover parameters from the public parameters.
136 fn extract_prover_param(&self, supported_size: usize) -> Self::ProverParam;
137 /// Extract the verifier parameters from the public parameters.
138 fn extract_verifier_param(&self, supported_size: usize) -> Self::VerifierParam;
139
140 /// Trim the universal parameters to specialize the public parameters
141 /// for polynomials to the given `supported_size`, and
142 /// returns committer key and verifier key.
143 ///
144 /// - For univariate polynomials, `supported_size` is the maximum degree.
145 /// - For multilinear polynomials, `supported_size` is 2 to the number of
146 /// variables.
147 ///
148 /// `supported_log_size` should be in range `1..=params.log_size`
149 fn trim(
150 &self,
151 supported_size: usize,
152 ) -> Result<(Self::ProverParam, Self::VerifierParam), PCSError>;
153
154 /// Build SRS for testing.
155 ///
156 /// - For univariate polynomials, `supported_size` is the maximum degree.
157 /// - For multilinear polynomials, `supported_size` is the number of
158 /// variables.
159 ///
160 /// WARNING: THIS FUNCTION IS FOR TESTING PURPOSE ONLY.
161 /// THE OUTPUT SRS SHOULD NOT BE USED IN PRODUCTION.
162 fn gen_srs_for_testing<R: RngCore + CryptoRng>(
163 rng: &mut R,
164 supported_size: usize,
165 ) -> Result<Self, PCSError>;
166}