p3_commit/
pcs.rs

1//! Traits for polynomial commitment schemes.
2
3use alloc::vec::Vec;
4use core::fmt::Debug;
5
6use p3_field::ExtensionField;
7use p3_matrix::dense::RowMajorMatrix;
8use p3_matrix::Matrix;
9use serde::de::DeserializeOwned;
10use serde::Serialize;
11
12use crate::PolynomialSpace;
13
14pub type Val<D> = <D as PolynomialSpace>::Val;
15
16/// A (not necessarily hiding) polynomial commitment scheme, for committing to (batches of) polynomials
17// TODO: Should we have a super-trait for weakly-binding PCSs, like FRI outside unique decoding radius?
18pub trait Pcs<Challenge, Challenger>
19where
20    Challenge: ExtensionField<Val<Self::Domain>>,
21{
22    type Domain: PolynomialSpace;
23
24    /// The commitment that's sent to the verifier.
25    type Commitment: Clone + Serialize + DeserializeOwned;
26
27    /// Data that the prover stores for committed polynomials, to help the prover with opening.
28    type ProverData;
29
30    /// The opening argument.
31    type Proof: Clone + Serialize + DeserializeOwned;
32
33    type Error: Debug;
34
35    /// This should return a coset domain (s.t. Domain::next_point returns Some)
36    fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain;
37
38    #[allow(clippy::type_complexity)]
39    fn commit(
40        &self,
41        evaluations: Vec<(Self::Domain, RowMajorMatrix<Val<Self::Domain>>)>,
42    ) -> (Self::Commitment, Self::ProverData);
43
44    fn get_evaluations_on_domain<'a>(
45        &self,
46        prover_data: &'a Self::ProverData,
47        idx: usize,
48        domain: Self::Domain,
49    ) -> impl Matrix<Val<Self::Domain>> + 'a;
50
51    fn open(
52        &self,
53        // For each round,
54        rounds: Vec<(
55            &Self::ProverData,
56            // for each matrix,
57            Vec<
58                // points to open
59                Vec<Challenge>,
60            >,
61        )>,
62        challenger: &mut Challenger,
63    ) -> (OpenedValues<Challenge>, Self::Proof);
64
65    #[allow(clippy::type_complexity)]
66    fn verify(
67        &self,
68        // For each round:
69        rounds: Vec<(
70            Self::Commitment,
71            // for each matrix:
72            Vec<(
73                // its domain,
74                Self::Domain,
75                // for each point:
76                Vec<(
77                    // the point,
78                    Challenge,
79                    // values at the point
80                    Vec<Challenge>,
81                )>,
82            )>,
83        )>,
84        proof: &Self::Proof,
85        challenger: &mut Challenger,
86    ) -> Result<(), Self::Error>;
87}
88
89pub type OpenedValues<F> = Vec<OpenedValuesForRound<F>>;
90pub type OpenedValuesForRound<F> = Vec<OpenedValuesForMatrix<F>>;
91pub type OpenedValuesForMatrix<F> = Vec<OpenedValuesForPoint<F>>;
92pub type OpenedValuesForPoint<F> = Vec<F>;