From 44fdd136ac0d981e952ff6551a395a3576ef4960 Mon Sep 17 00:00:00 2001 From: danielsanchezq Date: Thu, 13 Jun 2024 18:02:55 +0200 Subject: [PATCH] Implement fft_g1 --- nomos-da/kzgrs/Cargo.toml | 1 + nomos-da/kzgrs/src/fft.rs | 49 ++++++++++++++++++++++++++++++++++++++ nomos-da/kzgrs/src/fk20.rs | 20 ++++++++++++++++ nomos-da/kzgrs/src/lib.rs | 2 ++ 4 files changed, 72 insertions(+) create mode 100644 nomos-da/kzgrs/src/fft.rs create mode 100644 nomos-da/kzgrs/src/fk20.rs diff --git a/nomos-da/kzgrs/Cargo.toml b/nomos-da/kzgrs/Cargo.toml index ba7dfb07..e15fcfd5 100644 --- a/nomos-da/kzgrs/Cargo.toml +++ b/nomos-da/kzgrs/Cargo.toml @@ -15,6 +15,7 @@ ark-poly = { version = "0.4.2" } ark-poly-commit = { version = "0.4.0" } ark-serialize = { version = "0.4" } blst = "0.3.11" +derive_more = "0.99" num-bigint = "0.4.4" thiserror = "1.0.58" num-traits = "0.2.18" diff --git a/nomos-da/kzgrs/src/fft.rs b/nomos-da/kzgrs/src/fft.rs new file mode 100644 index 00000000..6ecfb38b --- /dev/null +++ b/nomos-da/kzgrs/src/fft.rs @@ -0,0 +1,49 @@ +use ark_bls12_381::{Fr, G1Affine}; +use ark_ec::CurveGroup; + +pub fn fft_g1(vals: &[G1Affine], roots_of_unity: &[Fr]) -> Vec { + if vals.len() == 1 { + return vals.to_vec(); + } + let half_roots: Vec<_> = roots_of_unity.iter().step_by(2).copied().collect(); + + let l = fft_g1( + vals.iter() + .step_by(2) + .copied() + .collect::>() + .as_slice(), + half_roots.as_slice(), + ); + + let r = fft_g1( + vals.iter() + .skip(1) + .step_by(2) + .copied() + .collect::>() + .as_slice(), + half_roots.as_slice(), + ); + + let y_times_root = r + .into_iter() + .cycle() + .enumerate() + .map(|(i, y)| (y * roots_of_unity[i % vals.len()]).into_affine()); + + l.into_iter() + .cycle() + .take(vals.len()) + .zip(y_times_root) + .enumerate() + .map(|(i, (x, y_times_root))| { + if i < vals.len() / 2 { + x + y_times_root + } else { + x - y_times_root + } + .into_affine() + }) + .collect() +} diff --git a/nomos-da/kzgrs/src/fk20.rs b/nomos-da/kzgrs/src/fk20.rs new file mode 100644 index 00000000..6b5d732f --- /dev/null +++ b/nomos-da/kzgrs/src/fk20.rs @@ -0,0 +1,20 @@ +use crate::{GlobalParameters, Polynomial, Proof}; +use ark_bls12_381::{Bls12_381, Fq, Fr, G1Affine, G1Projective}; +use ark_ec::mnt4::G1Prepared; +use ark_ec::{AffineRepr, CurveGroup}; + +use ark_poly::univariate::DensePolynomial; +use ark_poly::{EvaluationDomain, Radix2EvaluationDomain}; +use num_traits::Zero; +fn toeplitz1(global_parameters: &GlobalParameters, polynomial_degree: usize) -> Vec { + debug_assert_eq!(global_parameters.powers_of_g.len(), polynomial_degree); + debug_assert!(polynomial_degree.is_power_of_two()); + unimplemented!() +} + +pub fn fk20_batch_generate_elements_proofs( + polynomial: &DensePolynomial, + global_parameters: &GlobalParameters, +) -> Vec { + unimplemented!() +} diff --git a/nomos-da/kzgrs/src/lib.rs b/nomos-da/kzgrs/src/lib.rs index 188bee30..833d959f 100644 --- a/nomos-da/kzgrs/src/lib.rs +++ b/nomos-da/kzgrs/src/lib.rs @@ -1,4 +1,6 @@ pub mod common; +mod fft; +mod fk20; pub mod global_parameters; pub mod kzg; pub mod rs;