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 {
20 type ProverData<M>;
21 type Commitment: Clone + Serialize + DeserializeOwned;
22 type Proof: Clone + Serialize + DeserializeOwned;
23 type Error: Debug;
24
25 fn commit<M: Matrix<T>>(&self, inputs: Vec<M>) -> (Self::Commitment, Self::ProverData<M>);
26
27 fn commit_matrix<M: Matrix<T>>(&self, input: M) -> (Self::Commitment, Self::ProverData<M>) {
28 self.commit(vec![input])
29 }
30
31 fn commit_vec(&self, input: Vec<T>) -> (Self::Commitment, Self::ProverData<RowMajorMatrix<T>>)
32 where
33 T: Clone + Send + Sync,
34 {
35 self.commit_matrix(RowMajorMatrix::new_col(input))
36 }
37
38 fn open_batch<M: Matrix<T>>(
43 &self,
44 index: usize,
45 prover_data: &Self::ProverData<M>,
46 ) -> (Vec<Vec<T>>, Self::Proof);
47
48 fn get_matrices<'a, M: Matrix<T>>(&self, prover_data: &'a Self::ProverData<M>) -> Vec<&'a M>;
50
51 fn get_matrix_heights<M: Matrix<T>>(&self, prover_data: &Self::ProverData<M>) -> Vec<usize> {
52 self.get_matrices(prover_data)
53 .iter()
54 .map(|matrix| matrix.height())
55 .collect()
56 }
57
58 fn get_max_height<M: Matrix<T>>(&self, prover_data: &Self::ProverData<M>) -> usize {
60 self.get_matrix_heights(prover_data)
61 .into_iter()
62 .max()
63 .unwrap_or_else(|| panic!("No committed matrices?"))
64 }
65
66 fn verify_batch(
72 &self,
73 commit: &Self::Commitment,
74 dimensions: &[Dimensions],
75 index: usize,
76 opened_values: &[Vec<T>],
77 proof: &Self::Proof,
78 ) -> Result<(), Self::Error>;
79}