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,
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,
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,
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            commitment_scheme_d: AjtaiScheme::new(
42                ep.gamma_2,
43                Self::challenge_rq_matrix(
44                    ep.kappa_2,
45                    ep.t_1 * ((ep.multiplicity.pow(2)) + ep.multiplicity) / 2,
46                ),
47            )
48            .expect("Invalid Parameters for commitment scheme D"),
49        }
50    }
51
52    fn challenge_rq_matrix(row: usize, col: usize) -> RqMatrix {
53        (0..row)
54            .map(|_| (0..col).map(|_| Rq::random(&mut rng())).collect())
55            .collect()
56    }
57}
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62    use std::time::Instant;
63
64    #[test]
65    fn test_crs() {
66        // set up example environment parameters, use default set for testing.
67        let ep_1 = EnvironmentParameters::default();
68
69        let total_start = Instant::now();
70        // generate the common reference string matrices A, B, C, D
71        let _pp = AjtaiInstances::new(&ep_1);
72
73        println!(
74            "Total time for PublicPrams::new: {:?}",
75            total_start.elapsed()
76        );
77    }
78}