|
1 | 1 | pub mod raw;
|
2 |
| -pub use self::raw::*; |
| 2 | +pub use raw::*; |
3 | 3 |
|
4 |
| -pub mod poly; |
5 |
| -pub use self::poly::*; |
| 4 | +pub mod basefold; |
| 5 | +pub use basefold::*; |
6 | 6 |
|
7 |
| -pub trait PolynomialCommitment {} |
| 7 | +use std::{borrow::Borrow, fmt::Debug}; |
| 8 | + |
| 9 | +use arith::Field; |
| 10 | +use rand::RngCore; |
| 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. |
| 14 | +/// |
| 15 | +/// Credit: https://github.com/EspressoSystems/hyperplonk/blob/8698369edfe82bd6617a9609602380f21cabd1da/subroutines/src/pcs/mod.rs#L24 |
| 16 | +pub trait PolynomialCommitmentScheme { |
| 17 | + /// Prover parameters |
| 18 | + type ProverParam: Clone + Sync; |
| 19 | + /// Verifier parameters |
| 20 | + type VerifierParam: Clone; |
| 21 | + /// Structured reference string |
| 22 | + type SRS: Clone + Debug; |
| 23 | + /// Polynomial and its associated types |
| 24 | + type Polynomial: Clone + Debug; |
| 25 | + /// Polynomial input domain |
| 26 | + type Point: Clone + Debug + Sync + PartialEq + Eq; |
| 27 | + /// Polynomial Evaluation |
| 28 | + type Evaluation: Field; |
| 29 | + /// Commitments |
| 30 | + type Commitment: Clone + Debug; |
| 31 | + /// Proofs |
| 32 | + type Proof: Clone + Debug; |
| 33 | + /// Batch proofs |
| 34 | + type BatchProof; |
| 35 | + |
| 36 | + /// Build SRS for testing. |
| 37 | + /// |
| 38 | + /// |
| 39 | + /// WARNING: THIS FUNCTION IS FOR TESTING PURPOSE ONLY. |
| 40 | + /// THE OUTPUT SRS SHOULD NOT BE USED IN PRODUCTION. |
| 41 | + fn gen_srs_for_testing(rng: impl RngCore, supported_n: usize, supported_m: usize) -> Self::SRS; |
| 42 | + |
| 43 | + /// Generate a commitment for a polynomial |
| 44 | + /// ## Note on function signature |
| 45 | + /// Usually, data structure like SRS and ProverParam are huge and users |
| 46 | + /// might wish to keep them in heap using different kinds of smart pointers |
| 47 | + /// (instead of only in stack) therefore our `impl Borrow<_>` interface |
| 48 | + /// allows for passing in any pointer type, e.g.: `commit(prover_param: |
| 49 | + /// &Self::ProverParam, ..)` or `commit(prover_param: |
| 50 | + /// Box<Self::ProverParam>, ..)` or `commit(prover_param: |
| 51 | + /// Arc<Self::ProverParam>, ..)` etc. |
| 52 | + fn commit( |
| 53 | + prover_param: impl Borrow<Self::ProverParam>, |
| 54 | + poly: &Self::Polynomial, |
| 55 | + ) -> Self::Commitment; |
| 56 | + |
| 57 | + /// On input a polynomial `p` and a point `point`, outputs a proof for the |
| 58 | + /// same. |
| 59 | + fn open( |
| 60 | + prover_param: impl Borrow<Self::ProverParam>, |
| 61 | + polynomial: &Self::Polynomial, |
| 62 | + point: &Self::Point, |
| 63 | + ) -> (Self::Proof, Self::Evaluation); |
| 64 | + |
| 65 | + /// Input a list of polynomials, and a same number of points, compute a multi-opening for all the polynomials. |
| 66 | + fn multi_open( |
| 67 | + _prover_param: impl Borrow<Self::ProverParam>, |
| 68 | + _polynomials: &[Self::Polynomial], |
| 69 | + _points: &[Self::Point], |
| 70 | + _evals: &[Self::Evaluation], |
| 71 | + ) -> Self::BatchProof { |
| 72 | + // the reason we use unimplemented!() is to enable developers to implement the |
| 73 | + // trait without always implementing the batching APIs. |
| 74 | + unimplemented!() |
| 75 | + } |
| 76 | + |
| 77 | + /// Verifies that `value` is the evaluation at `x` of the polynomial |
| 78 | + /// committed inside `comm`. |
| 79 | + fn verify( |
| 80 | + verifier_param: &Self::VerifierParam, |
| 81 | + commitment: &Self::Commitment, |
| 82 | + point: &Self::Point, |
| 83 | + value: &Self::Evaluation, |
| 84 | + proof: &Self::Proof, |
| 85 | + ) -> bool; |
| 86 | + |
| 87 | + /// Verifies that `value_i` is the evaluation at `x_i` of the polynomial |
| 88 | + /// `poly_i` committed inside `comm`. |
| 89 | + fn batch_verify( |
| 90 | + _verifier_param: &Self::VerifierParam, |
| 91 | + _commitments: &[Self::Commitment], |
| 92 | + _points: &[Self::Point], |
| 93 | + _batch_proof: &Self::BatchProof, |
| 94 | + ) -> bool { |
| 95 | + // the reason we use unimplemented!() is to enable developers to implement the |
| 96 | + // trait without always implementing the batching APIs. |
| 97 | + unimplemented!() |
| 98 | + } |
| 99 | +} |
0 commit comments