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    /// Type of the output of `get_evaluations_on_domain`.
31    type EvaluationsOnDomain<'a>: Matrix<Val<Self::Domain>> + 'a;
32
33    /// The opening argument.
34    type Proof: Clone + Serialize + DeserializeOwned;
35
36    type Error: Debug;
37
38    /// This should return a coset domain (s.t. Domain::next_point returns Some)
39    fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain;
40
41    #[allow(clippy::type_complexity)]
42    fn commit(
43        &self,
44        evaluations: Vec<(Self::Domain, RowMajorMatrix<Val<Self::Domain>>)>,
45    ) -> (Self::Commitment, Self::ProverData);
46
47    fn get_evaluations_on_domain<'a>(
48        &self,
49        prover_data: &'a Self::ProverData,
50        idx: usize,
51        domain: Self::Domain,
52    ) -> Self::EvaluationsOnDomain<'a>;
53
54    fn open(
55        &self,
56        // For each round,
57        rounds: Vec<(
58            &Self::ProverData,
59            // for each matrix,
60            Vec<
61                // points to open
62                Vec<Challenge>,
63            >,
64        )>,
65        challenger: &mut Challenger,
66    ) -> (OpenedValues<Challenge>, Self::Proof);
67
68    #[allow(clippy::type_complexity)]
69    fn verify(
70        &self,
71        // For each round:
72        rounds: Vec<(
73            Self::Commitment,
74            // for each matrix:
75            Vec<(
76                // its domain,
77                Self::Domain,
78                // for each point:
79                Vec<(
80                    // the point,
81                    Challenge,
82                    // values at the point
83                    Vec<Challenge>,
84                )>,
85            )>,
86        )>,
87        proof: &Self::Proof,
88        challenger: &mut Challenger,
89    ) -> Result<(), Self::Error>;
90}
91
92pub type OpenedValues<F> = Vec<OpenedValuesForRound<F>>;
93pub type OpenedValuesForRound<F> = Vec<OpenedValuesForMatrix<F>>;
94pub type OpenedValuesForMatrix<F> = Vec<OpenedValuesForPoint<F>>;
95pub type OpenedValuesForPoint<F> = Vec<F>;