From 82baca12c1790a1b1f7d9593424dd07a5b46e8b8 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 9 Oct 2024 16:59:04 +0100 Subject: [PATCH] add a check for zero --- cryptography/polynomial/src/fft.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cryptography/polynomial/src/fft.rs b/cryptography/polynomial/src/fft.rs index 04e8c080..44edbb88 100644 --- a/cryptography/polynomial/src/fft.rs +++ b/cryptography/polynomial/src/fft.rs @@ -1,19 +1,30 @@ -use bls12_381::{ff::Field, G1Projective, Scalar}; +use bls12_381::{ff::Field, group::Group, G1Projective, Scalar}; use std::ops::{Add, Mul, Neg, Sub}; trait FFTElement: Sized + Copy + + PartialEq + + Eq + Add + Sub + Mul + Neg { + fn zero() -> Self; } -impl FFTElement for Scalar {} +impl FFTElement for Scalar { + fn zero() -> Self { + Scalar::ZERO + } +} -impl FFTElement for G1Projective {} +impl FFTElement for G1Projective { + fn zero() -> Self { + G1Projective::identity() + } +} fn fft_inplace(twiddle_factors: &[Scalar], a: &mut [T]) { let n = a.len(); @@ -37,6 +48,8 @@ fn fft_inplace(twiddle_factors: &[Scalar], a: &mut [T]) { a[k + j + m] } else if w == -Scalar::ONE { -a[k + j + m] + } else if a[k + j + m] == T::zero() { + T::zero() } else { a[k + j + m] * w };