use crate::{linear_codes::utils::SprsMat, utils::Matrix, PCCommitment, PCCommitmentState};
use ark_crypto_primitives::{
crh::CRHScheme,
merkle_tree::{Config, LeafParam, Path, TwoToOneParam},
};
use ark_ff::PrimeField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
use ark_std::{marker::PhantomData, rand::RngCore};
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Clone(bound = ""), Debug(bound = ""))]
pub struct BrakedownPCParams<F: PrimeField, C: Config, H: CRHScheme> {
pub(crate) sec_param: usize,
pub(crate) alpha: (usize, usize),
pub(crate) beta: (usize, usize),
pub(crate) rho_inv: (usize, usize),
pub(crate) base_len: usize,
pub(crate) n: usize,
pub(crate) m: usize,
pub(crate) m_ext: usize,
pub(crate) a_dims: Vec<(usize, usize, usize)>,
pub(crate) b_dims: Vec<(usize, usize, usize)>,
pub(crate) start: Vec<usize>,
pub(crate) end: Vec<usize>,
pub(crate) a_mats: Vec<SprsMat<F>>,
pub(crate) b_mats: Vec<SprsMat<F>>,
pub(crate) check_well_formedness: bool,
#[derivative(Debug = "ignore")]
pub(crate) leaf_hash_param: LeafParam<C>,
#[derivative(Debug = "ignore")]
pub(crate) two_to_one_hash_param: TwoToOneParam<C>,
#[derivative(Debug = "ignore")]
pub(crate) col_hash_params: H::Parameters,
}
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Clone(bound = ""), Debug(bound = ""))]
pub struct LigeroPCParams<F: PrimeField, C: Config, H: CRHScheme> {
pub(crate) _field: PhantomData<F>,
pub(crate) sec_param: usize,
pub(crate) rho_inv: usize,
pub(crate) check_well_formedness: bool,
#[derivative(Debug = "ignore")]
pub(crate) leaf_hash_param: LeafParam<C>,
#[derivative(Debug = "ignore")]
pub(crate) two_to_one_hash_param: TwoToOneParam<C>,
#[derivative(Debug = "ignore")]
pub(crate) col_hash_params: H::Parameters,
}
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub(crate) struct Metadata {
pub(crate) n_rows: usize,
pub(crate) n_cols: usize,
pub(crate) n_ext_cols: usize,
}
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct LinCodePCCommitment<C: Config> {
pub(crate) metadata: Metadata,
pub(crate) root: C::InnerDigest,
}
impl<C: Config> PCCommitment for LinCodePCCommitment<C> {
fn empty() -> Self {
LinCodePCCommitment::default()
}
fn has_degree_bound(&self) -> bool {
false
}
}
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct LinCodePCCommitmentState<F, H>
where
F: PrimeField,
H: CRHScheme,
{
pub(crate) mat: Matrix<F>,
pub(crate) ext_mat: Matrix<F>,
pub(crate) leaves: Vec<H::Output>,
}
impl<F, H> PCCommitmentState for LinCodePCCommitmentState<F, H>
where
F: PrimeField,
H: CRHScheme,
{
type Randomness = ();
fn empty() -> Self {
unimplemented!()
}
fn rand<R: RngCore>(
_num_queries: usize,
_has_degree_bound: bool,
_num_vars: Option<usize>,
_rng: &mut R,
) -> Self::Randomness {
unimplemented!()
}
}
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub(crate) struct LinCodePCProofSingle<F, C>
where
F: PrimeField,
C: Config,
{
pub(crate) paths: Vec<Path<C>>,
pub(crate) v: Vec<F>,
pub(crate) columns: Vec<Vec<F>>,
}
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct LinCodePCProof<F, C>
where
F: PrimeField,
C: Config,
{
pub(crate) opening: LinCodePCProofSingle<F, C>,
pub(crate) well_formedness: Option<Vec<F>>,
}
pub(crate) type LPCPArray<F, C> = Vec<LinCodePCProof<F, C>>;