1use alloc::vec;
2use alloc::vec::Vec;
3use core::fmt::Debug;
4
5use p3_matrix::dense::RowMajorMatrix;
6use p3_matrix::{Dimensions, Matrix};
7use serde::de::DeserializeOwned;
8use serde::Serialize;
9
10pub trait Mmcs<T: Send + Sync>: Clone {
19 type ProverData<M>;
20 type Commitment: Clone + Serialize + DeserializeOwned;
21 type Proof: Clone + Serialize + DeserializeOwned;
22 type Error: Debug;
23
24 fn commit<M: Matrix<T>>(&self, inputs: Vec<M>) -> (Self::Commitment, Self::ProverData<M>);
25
26 fn commit_matrix<M: Matrix<T>>(&self, input: M) -> (Self::Commitment, Self::ProverData<M>) {
27 self.commit(vec![input])
28 }
29
30 fn commit_vec(&self, input: Vec<T>) -> (Self::Commitment, Self::ProverData<RowMajorMatrix<T>>)
31 where
32 T: Clone + Send + Sync,
33 {
34 self.commit_matrix(RowMajorMatrix::new_col(input))
35 }
36
37 fn open_batch<M: Matrix<T>>(
42 &self,
43 index: usize,
44 prover_data: &Self::ProverData<M>,
45 ) -> (Vec<Vec<T>>, Self::Proof);
46
47 fn get_matrices<'a, M: Matrix<T>>(&self, prover_data: &'a Self::ProverData<M>) -> Vec<&'a M>;
49
50 fn get_matrix_heights<M: Matrix<T>>(&self, prover_data: &Self::ProverData<M>) -> Vec<usize> {
51 self.get_matrices(prover_data)
52 .iter()
53 .map(|matrix| matrix.height())
54 .collect()
55 }
56
57 fn get_max_height<M: Matrix<T>>(&self, prover_data: &Self::ProverData<M>) -> usize {
59 self.get_matrix_heights(prover_data)
60 .into_iter()
61 .max()
62 .unwrap_or_else(|| panic!("No committed matrices?"))
63 }
64
65 fn verify_batch(
71 &self,
72 commit: &Self::Commitment,
73 dimensions: &[Dimensions],
74 index: usize,
75 opened_values: &[Vec<T>],
76 proof: &Self::Proof,
77 ) -> Result<(), Self::Error>;
78}