Overview
Thefft module implements Fast Fourier Transform operations for polynomial arithmetic over finite fields. These operations are fundamental to zkSNARK construction, enabling O(n log n) polynomial evaluation and interpolation.
EvaluationDomain
Overview
Represents a multiplicative subgroup of a finite field for FFT operations.u64
Size of the domain (must be a power of 2)
F
Generator of the multiplicative subgroup
F
Multiplicative inverse of the size
Construction
new
Creates a new evaluation domain.usize
Number of coefficients (will be rounded up to next power of 2)
Result<EvaluationDomain<F>>
Evaluation domain of size that is the smallest power of 2 >= num_coeffs
FFT Operations
fft
Performs forward FFT on polynomial coefficients.&[T]
Polynomial coefficients in monomial basis
Vec<T>
Evaluations over the domain
ifft
Performs inverse FFT (interpolation).&[T]
Evaluations over the domain
Vec<T>
Polynomial coefficients in monomial basis
fft_in_place
In-place FFT that modifies the input vector.&mut Vec<T>
Polynomial coefficients (will be replaced with evaluations)
ifft_in_place
In-place inverse FFT.Coset Operations
coset_fft
Performs FFT over a coset of the domain.&[T]
Polynomial coefficients
Vec<T>
Evaluations over coset g * domain
coset_ifft
Interpolates from coset evaluations.Domain Queries
size
Returns the size of the domain.usize
Size of the evaluation domain
elements
Returns all elements of the domain.Vec<F>
All elements in the domain (powers of the generator)
evaluate_vanishing_polynomial
Evaluates the vanishing polynomial Z_H(x) = x^n - 1.F
Point to evaluate at
F
Value of vanishing polynomial at x
DensePolynomial
Overview
Polynomial stored in coefficient form.Vec<F>
Coefficients in ascending degree order (coeffs[i] is coefficient of x^i)
Construction
from_coefficients_vec
Creates polynomial from coefficient vector.Vec<F>
Polynomial coefficients
DensePolynomial<F>
Polynomial with given coefficients (trailing zeros removed)
zero
Creates the zero polynomial.DensePolynomial<F>
The zero polynomial
rand
Generates a random polynomial.usize
Degree of the polynomial
&mut R
Random number generator
DensePolynomial<F>
Random polynomial of specified degree
Polynomial Operations
degree
Returns the degree of the polynomial.usize
Degree of the polynomial (0 for zero polynomial)
evaluate
Evaluates the polynomial at a point.F
Point to evaluate at
F
Value of polynomial at point (using Horner’s method)
divide_by_vanishing_poly
Divides by the vanishing polynomial of a domain.&EvaluationDomain<F>
The evaluation domain
Result<DensePolynomial<F>>
Quotient polynomial p(x) / (x^n - 1)
Arithmetic Operations
DensePolynomial implements standard arithmetic:SparsePolynomial
Overview
Polynomial with few non-zero coefficients.Construction
from_coefficients_vec
Creates sparse polynomial from (degree, coefficient) pairs.Vec<(usize, F)>
Vector of (degree, coefficient) pairs
SparsePolynomial<F>
Sparse polynomial
Methods
degree
Returns the degree.evaluate
Evaluates at a point.Evaluations
Overview
Polynomial represented in evaluation form (Lagrange basis).Vec<F>
Polynomial evaluations over the domain
EvaluationDomain<F>
The evaluation domain
Construction
from_vec_and_domain
Creates Evaluations from vector and domain.Vec<F>
Evaluation values
EvaluationDomain<F>
Evaluation domain
Evaluations<F>
Polynomial in evaluation form
Methods
interpolate
Converts to coefficient form.DensePolynomial<F>
Polynomial in coefficient form
interpolate_by_ref
Interpolates without consuming.DomainCoeff Trait
Defines types that can be FFT-transformed.Polynomial Trait
Common interface for polynomial types.Complete Example
Performance Considerations
Parallelization
FFT operations are parallelized using Rayon:In-Place Operations
Use in-place variants to avoid allocations:Domain Size Selection
Choose domain sizes that are powers of 2:Common Patterns
Quotient Polynomial Computation
Lagrange Interpolation
See Also
- Polynomial Commitments - Uses FFT for commitment
- SNARK Implementations - Uses FFT in AHP
- Cryptographic Hash Functions - Field arithmetic