use alloc::vec;
use alloc::vec::Vec;
use core::fmt::Debug;
use p3_matrix::dense::RowMajorMatrix;
use p3_matrix::{Dimensions, Matrix};
use serde::de::DeserializeOwned;
use serde::Serialize;
pub trait Mmcs<T: Send + Sync>: Clone {
type ProverData<M>;
type Commitment: Clone + Serialize + DeserializeOwned;
type Proof: Clone + Serialize + DeserializeOwned;
type Error: Debug;
fn commit<M: Matrix<T>>(&self, inputs: Vec<M>) -> (Self::Commitment, Self::ProverData<M>);
fn commit_matrix<M: Matrix<T>>(&self, input: M) -> (Self::Commitment, Self::ProverData<M>) {
self.commit(vec![input])
}
fn commit_vec(&self, input: Vec<T>) -> (Self::Commitment, Self::ProverData<RowMajorMatrix<T>>)
where
T: Clone + Send + Sync,
{
self.commit_matrix(RowMajorMatrix::new_col(input))
}
fn open_batch<M: Matrix<T>>(
&self,
index: usize,
prover_data: &Self::ProverData<M>,
) -> (Vec<Vec<T>>, Self::Proof);
fn get_matrices<'a, M: Matrix<T>>(&self, prover_data: &'a Self::ProverData<M>) -> Vec<&'a M>;
fn get_matrix_heights<M: Matrix<T>>(&self, prover_data: &Self::ProverData<M>) -> Vec<usize> {
self.get_matrices(prover_data)
.iter()
.map(|matrix| matrix.height())
.collect()
}
fn get_max_height<M: Matrix<T>>(&self, prover_data: &Self::ProverData<M>) -> usize {
self.get_matrix_heights(prover_data)
.into_iter()
.max()
.unwrap_or_else(|| panic!("No committed matrices?"))
}
fn verify_batch(
&self,
commit: &Self::Commitment,
dimensions: &[Dimensions],
index: usize,
opened_values: &[Vec<T>],
proof: &Self::Proof,
) -> Result<(), Self::Error>;
}