ark_poly_commit/hyrax/
data_structures.rs1use crate::{
2 utils::Matrix, PCCommitment, PCCommitmentState, PCCommitterKey, PCUniversalParams,
3 PCVerifierKey,
4};
5use ark_ec::AffineRepr;
6use ark_ff::PrimeField;
7use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
8use ark_std::{rand::RngCore, vec::Vec};
9
10#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
12#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
13pub struct HyraxUniversalParams<G: AffineRepr> {
14 pub com_key: Vec<G>,
16 pub h: G,
18}
19
20impl<G: AffineRepr> PCUniversalParams for HyraxUniversalParams<G> {
21 fn max_degree(&self) -> usize {
22 1
24 }
25}
26
27pub type HyraxCommitterKey<G> = HyraxUniversalParams<G>;
29
30pub type HyraxVerifierKey<G> = HyraxCommitterKey<G>;
32
33impl<G: AffineRepr> PCCommitterKey for HyraxCommitterKey<G> {
34 fn max_degree(&self) -> usize {
35 1
37 }
38 fn supported_degree(&self) -> usize {
39 1
41 }
42}
43
44impl<G: AffineRepr> PCVerifierKey for HyraxVerifierKey<G> {
45 fn max_degree(&self) -> usize {
47 1
48 }
49 fn supported_degree(&self) -> usize {
51 1
52 }
53}
54
55#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
58#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
59pub struct HyraxCommitment<G: AffineRepr> {
60 pub row_coms: Vec<G>,
63}
64
65impl<G: AffineRepr> PCCommitment for HyraxCommitment<G> {
66 #[inline]
67 fn empty() -> Self {
68 HyraxCommitment {
69 row_coms: Vec::new(),
70 }
71 }
72
73 fn has_degree_bound(&self) -> bool {
76 true
77 }
78}
79
80pub(crate) type HyraxRandomness<F> = Vec<F>;
81
82#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
85#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
86pub struct HyraxCommitmentState<F>
87where
88 F: PrimeField,
89{
90 pub(crate) randomness: HyraxRandomness<F>,
91 pub(crate) mat: Matrix<F>,
92}
93
94impl<F: PrimeField> PCCommitmentState for HyraxCommitmentState<F> {
97 type Randomness = HyraxRandomness<F>;
98 fn empty() -> Self {
99 unimplemented!()
100 }
101
102 fn rand<R: RngCore>(
103 num_queries: usize,
104 _has_degree_bound: bool,
105 _num_vars: Option<usize>,
106 rng: &mut R,
107 ) -> Self::Randomness {
108 (0..num_queries).map(|_| F::rand(rng)).collect()
109 }
110}
111
112#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
115#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
116pub struct HyraxProof<G: AffineRepr> {
117 pub com_eval: G,
119 pub com_d: G,
121 pub com_b: G,
123 pub z: Vec<G::ScalarField>,
125 pub z_d: G::ScalarField,
127 pub z_b: G::ScalarField,
129}