arnaucube
arnaucube/shockwave-plusPublic Self-hosted repository
shockwave-plus/tensor_pcs/src/rs_config/ecfft.rs
tensor_pcs/src/rs_config/ecfft.rsRaw
 1use crate::FieldExt;
 2use ecfft::{find_coset_offset, prepare_domain, prepare_matrices, GoodCurve, Matrix2x2};
 3
 4#[derive(Clone, Debug)]
 5pub struct ECFFTConfig<F: FieldExt> {
 6    pub domain: Vec<Vec<F>>,
 7    pub matrices: Vec<Vec<Matrix2x2<F>>>,
 8    pub inverse_matrices: Vec<Vec<Matrix2x2<F>>>,
 9}
10
11pub fn gen_config_form_curve<F: FieldExt>(
12    good_curve: GoodCurve<F>,
13    coset_offset: (F, F),
14) -> ECFFTConfig<F> {
15    let domain = prepare_domain(good_curve, coset_offset.0, coset_offset.1);
16    let (matrices, inverse_matrices) = prepare_matrices(&domain);
17
18    ECFFTConfig {
19        domain,
20        matrices,
21        inverse_matrices,
22    }
23}
24
25pub fn gen_config<F: FieldExt>(num_cols: usize) -> ECFFTConfig<F> {
26    assert!(num_cols.is_power_of_two());
27    let expansion_factor = 2;
28    let codeword_len = num_cols * expansion_factor;
29
30    let k = (codeword_len as f64).log2() as usize;
31
32    let good_curve = GoodCurve::<F>::find_k(k);
33    let (coset_offset_x, coset_offset_y) =
34        find_coset_offset(good_curve.a, good_curve.B_sqrt.square());
35    let domain = prepare_domain(good_curve, coset_offset_x, coset_offset_y);
36    let (matrices, inverse_matrices) = prepare_matrices(&domain);
37
38    ECFFTConfig {
39        domain,
40        matrices,
41        inverse_matrices,
42    }
43}