labrador/commitments/
common_instances.rs

1use rand::rng;
2
3use crate::commitments::ajtai_commitment::AjtaiScheme;
4use crate::relation::env_params::EnvironmentParameters;
5use crate::ring::rq::Rq;
6use crate::ring::rq_matrix::RqMatrix;
7
8pub struct AjtaiInstances {
9    // A \in R_q^(k*n)
10    pub commitment_scheme_a: AjtaiScheme,
11    // B_{ik} \in R_q^(k_1*k), for i \in [1,r] and k \in [0, t_1-1]
12    pub commitment_scheme_b: AjtaiScheme,
13    // C_{ijk} \in R_q^(k_2*1), for i \in [1,r], j \in [i, r], and k \in [0, t_2-1]
14    pub commitment_scheme_c: AjtaiScheme,
15    // D_{ijk} \in R_q^(k_2*1), for i \in [1,r], j \in [i, r], and k \in [0, t_1-1]
16    pub commitment_scheme_d: AjtaiScheme,
17}
18
19impl AjtaiInstances {
20    pub fn new(ep: &EnvironmentParameters) -> Self {
21        Self {
22            commitment_scheme_a: AjtaiScheme::new(
23                ep.beta_sq,
24                Self::challenge_rq_matrix(ep.kappa, ep.rank),
25            )
26            .expect("Invalid Parameters for commitment scheme A"),
27            commitment_scheme_b: AjtaiScheme::new(
28                ep.gamma_1_sq,
29                Self::challenge_rq_matrix(ep.kappa_1, ep.multiplicity * ep.t_1 * ep.kappa),
30            )
31            .expect("Invalid Parameters for commitment scheme B"),
32            // Todo: gamma_1 should be changed to a valid witness bound
33            commitment_scheme_c: AjtaiScheme::new(
34                ep.gamma_1_sq,
35                Self::challenge_rq_matrix(
36                    ep.kappa_1,
37                    ep.t_2 * ((ep.multiplicity.pow(2)) + ep.multiplicity) / 2,
38                ),
39            )
40            .expect("Invalid Parameters for commitment scheme C"),
41            // Note: A factor of 4 is applied because each h_ij cell in the implementation is twice the value specified in
42            // the paper (division by 2 is omitted, as we are not operating on a field).
43            commitment_scheme_d: AjtaiScheme::new(
44                ep.gamma_2_sq * 4,
45                Self::challenge_rq_matrix(
46                    ep.kappa_2,
47                    ep.t_1 * ((ep.multiplicity.pow(2)) + ep.multiplicity) / 2,
48                ),
49            )
50            .expect("Invalid Parameters for commitment scheme D"),
51        }
52    }
53
54    fn challenge_rq_matrix(row: usize, col: usize) -> RqMatrix {
55        (0..row)
56            .map(|_| (0..col).map(|_| Rq::random(&mut rng())).collect())
57            .collect()
58    }
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64    use std::time::Instant;
65
66    #[test]
67    fn test_crs() {
68        // set up example environment parameters, use default set for testing.
69        let ep_1 = EnvironmentParameters::default();
70
71        let total_start = Instant::now();
72        // generate the common reference string matrices A, B, C, D
73        let _pp = AjtaiInstances::new(&ep_1);
74
75        println!(
76            "Total time for PublicPrams::new: {:?}",
77            total_start.elapsed()
78        );
79    }
80}