use crate::{
utils::Matrix, PCCommitment, PCCommitmentState, PCCommitterKey, PCUniversalParams,
PCVerifierKey,
};
use ark_ec::AffineRepr;
use ark_ff::PrimeField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{rand::RngCore, vec::Vec};
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct HyraxUniversalParams<G: AffineRepr> {
pub com_key: Vec<G>,
pub h: G,
}
impl<G: AffineRepr> PCUniversalParams for HyraxUniversalParams<G> {
fn max_degree(&self) -> usize {
1
}
}
pub type HyraxCommitterKey<G> = HyraxUniversalParams<G>;
pub type HyraxVerifierKey<G> = HyraxCommitterKey<G>;
impl<G: AffineRepr> PCCommitterKey for HyraxCommitterKey<G> {
fn max_degree(&self) -> usize {
1
}
fn supported_degree(&self) -> usize {
1
}
}
impl<G: AffineRepr> PCVerifierKey for HyraxVerifierKey<G> {
fn max_degree(&self) -> usize {
1
}
fn supported_degree(&self) -> usize {
1
}
}
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct HyraxCommitment<G: AffineRepr> {
pub row_coms: Vec<G>,
}
impl<G: AffineRepr> PCCommitment for HyraxCommitment<G> {
#[inline]
fn empty() -> Self {
HyraxCommitment {
row_coms: Vec::new(),
}
}
fn has_degree_bound(&self) -> bool {
true
}
}
pub(crate) type HyraxRandomness<F> = Vec<F>;
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct HyraxCommitmentState<F>
where
F: PrimeField,
{
pub(crate) randomness: HyraxRandomness<F>,
pub(crate) mat: Matrix<F>,
}
impl<F: PrimeField> PCCommitmentState for HyraxCommitmentState<F> {
type Randomness = HyraxRandomness<F>;
fn empty() -> Self {
unimplemented!()
}
fn rand<R: RngCore>(
num_queries: usize,
_has_degree_bound: bool,
_num_vars: Option<usize>,
rng: &mut R,
) -> Self::Randomness {
(0..num_queries).map(|_| F::rand(rng)).collect()
}
}
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
pub struct HyraxProof<G: AffineRepr> {
pub com_eval: G,
pub com_d: G,
pub com_b: G,
pub z: Vec<G::ScalarField>,
pub z_d: G::ScalarField,
pub z_b: G::ScalarField,
}