ark_poly_commit/hyrax/
data_structures.rs

1use 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/// `UniversalParams` amounts to a Pederson commitment key of sufficient length
11#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
12#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
13pub struct HyraxUniversalParams<G: AffineRepr> {
14    /// A list of generators of the group.
15    pub com_key: Vec<G>,
16    /// A generator of the group.
17    pub h: G,
18}
19
20impl<G: AffineRepr> PCUniversalParams for HyraxUniversalParams<G> {
21    fn max_degree(&self) -> usize {
22        // Only MLEs are supported
23        1
24    }
25}
26
27/// The committer key, which coincides with the universal parameters
28pub type HyraxCommitterKey<G> = HyraxUniversalParams<G>;
29
30/// The verifier key, which coincides with the committer key
31pub type HyraxVerifierKey<G> = HyraxCommitterKey<G>;
32
33impl<G: AffineRepr> PCCommitterKey for HyraxCommitterKey<G> {
34    fn max_degree(&self) -> usize {
35        // Only MLEs are supported
36        1
37    }
38    fn supported_degree(&self) -> usize {
39        // Only MLEs are supported
40        1
41    }
42}
43
44impl<G: AffineRepr> PCVerifierKey for HyraxVerifierKey<G> {
45    // Only MLEs are supported
46    fn max_degree(&self) -> usize {
47        1
48    }
49    // Only MLEs are supported
50    fn supported_degree(&self) -> usize {
51        1
52    }
53}
54
55/// Hyrax commitment to a polynomial consisting of one multi-commit per row of
56/// the coefficient matrix
57#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
58#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
59pub struct HyraxCommitment<G: AffineRepr> {
60    /// A list of multi-commits to each row of the matrix representing the
61    /// polynomial.
62    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    // The degree bound is always 1, since only multilinear polynomials are
74    // supported
75    fn has_degree_bound(&self) -> bool {
76        true
77    }
78}
79
80pub(crate) type HyraxRandomness<F> = Vec<F>;
81
82/// Hyrax Commitment state: matrix of polynomial coefficients and list of random
83/// scalars used in each of the row-wise Pedersen commitments
84#[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
94/// A vector of scalars, each of which multiplies the distinguished group
95/// element in the Pederson commitment key for a different commitment
96impl<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/// Proof of a Hyrax opening, containing various commitments
113/// and auxiliary values generated randomly during the opening
114#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
115#[derivative(Default(bound = ""), Clone(bound = ""), Debug(bound = ""))]
116pub struct HyraxProof<G: AffineRepr> {
117    /// Commitment to the evaluation of the polynomial at the requested point
118    pub com_eval: G,
119    /// Commitment to auxiliary random vector `d`
120    pub com_d: G,
121    /// Commitment to auxiliary random scalar `b`
122    pub com_b: G,
123    /// Auxiliary random vector
124    pub z: Vec<G::ScalarField>,
125    /// Auxiliary random scalar
126    pub z_d: G::ScalarField,
127    /// Auxiliary random scalar
128    pub z_b: G::ScalarField,
129}