Skip to content

Commit ae7f460

Browse files
committed
wip
1 parent bbbc463 commit ae7f460

File tree

5 files changed

+217
-4
lines changed

5 files changed

+217
-4
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub use config::*;
99
pub mod hash;
1010
pub use hash::*;
1111

12+
pub mod poly;
13+
pub use poly::*;
14+
1215
pub mod poly_commit;
1316
pub use poly_commit::*;
1417

File renamed without changes.

src/poly_commit.rs

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,99 @@
11
pub mod raw;
2-
pub use self::raw::*;
2+
pub use raw::*;
33

4-
pub mod poly;
5-
pub use self::poly::*;
4+
pub mod basefold;
5+
pub use basefold::*;
66

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+
}

src/poly_commit/basefold.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
mod config;
2+
3+
use std::borrow::Borrow;
4+
5+
use arith::Field;
6+
use config::BasefoldConfig;
7+
use rand::RngCore;
8+
9+
use super::PolynomialCommitmentScheme;
10+
11+
#[derive(Clone, Debug)]
12+
pub struct BaseFold<C> {
13+
phantom: std::marker::PhantomData<C>,
14+
}
15+
16+
impl<C: BasefoldConfig> PolynomialCommitmentScheme for BaseFold<C> {
17+
/// Prover parameters
18+
type ProverParam = ();
19+
/// Verifier parameters
20+
type VerifierParam = ();
21+
/// Structured reference string
22+
type SRS = ();
23+
/// Polynomial and its associated types
24+
type Polynomial = ();
25+
/// Polynomial input domain
26+
type Point = Vec<C::BaseField>;
27+
/// Polynomial Evaluation
28+
type Evaluation = C::BaseField;
29+
/// Commitments
30+
type Commitment = ();
31+
/// Proofs
32+
type Proof = ();
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(
42+
_rng: impl RngCore,
43+
_supported_n: usize,
44+
_supported_m: usize,
45+
) -> Self::SRS {
46+
unimplemented!("basefold does not need an SRS")
47+
}
48+
49+
/// Generate a commitment for a polynomial
50+
/// ## Note on function signature
51+
/// Usually, data structure like SRS and ProverParam are huge and users
52+
/// might wish to keep them in heap using different kinds of smart pointers
53+
/// (instead of only in stack) therefore our `impl Borrow<_>` interface
54+
/// allows for passing in any pointer type, e.g.: `commit(prover_param:
55+
/// &Self::ProverParam, ..)` or `commit(prover_param:
56+
/// Box<Self::ProverParam>, ..)` or `commit(prover_param:
57+
/// Arc<Self::ProverParam>, ..)` etc.
58+
fn commit(
59+
prover_param: impl Borrow<Self::ProverParam>,
60+
poly: &Self::Polynomial,
61+
) -> Self::Commitment {
62+
unimplemented!()
63+
}
64+
65+
/// On input a polynomial `p` and a point `point`, outputs a proof for the
66+
/// same.
67+
fn open(
68+
prover_param: impl Borrow<Self::ProverParam>,
69+
polynomial: &Self::Polynomial,
70+
point: &Self::Point,
71+
) -> (Self::Proof, Self::Evaluation) {
72+
unimplemented!()
73+
}
74+
75+
/// Verifies that `value` is the evaluation at `x` of the polynomial
76+
/// committed inside `comm`.
77+
fn verify(
78+
verifier_param: &Self::VerifierParam,
79+
commitment: &Self::Commitment,
80+
point: &Self::Point,
81+
value: &Self::Evaluation,
82+
proof: &Self::Proof,
83+
) -> bool {
84+
unimplemented!()
85+
}
86+
}

src/poly_commit/basefold/config.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::marker::PhantomData;
2+
3+
use arith::{BabyBear, BabyBearExt3, ExtensionField, Field};
4+
5+
pub trait BasefoldConfig {
6+
type BaseField: Field + Eq + Sync;
7+
type ExtField: ExtensionField<BaseField = Self::BaseField>;
8+
9+
const RATE_BITS: usize;
10+
11+
const VERIFIER_QUERIES: usize;
12+
13+
#[inline]
14+
fn codeword_bits(&self, num_vars: usize) -> usize {
15+
Self::RATE_BITS + num_vars
16+
}
17+
}
18+
19+
#[derive(Clone, Debug)]
20+
pub struct BabybearConfig;
21+
22+
23+
impl BasefoldConfig for BabybearConfig {
24+
25+
type BaseField = BabyBear;
26+
27+
type ExtField = BabyBearExt3;
28+
29+
const RATE_BITS: usize = 128;
30+
31+
const VERIFIER_QUERIES: usize = 33;
32+
}

0 commit comments

Comments
 (0)