Learn / Math / FFT and NTT
23. FFT and NTT
FFT & NTT · Lesson 24 of 26 · 13:00
Why multiplying two polynomials the obvious way costs n × n multiplications, how multiplying their values at the roots of unity instead turns that into a matrix, and how splitting into even and odd parts — the FFT, or NTT over a finite field — brings the cost down to about n × log n.

Last lesson built vectors, matrices, and constraints out of dot products. This lesson meets one of the most important algorithms in ZK: the FFT, and its finite-field version, the NTT. Its job is simple to state — multiply polynomials fast — and it needs exactly the roots of unity from Topic 19 and the matrix-times-vector idea from Topic 22. One example carries the whole lesson: (1+2x)(1 + 2x) times (3+x)(3 + x), mod the prime 1313.

The slow way

Before building something fast, it helps to see exactly what’s slow about the obvious method.

the slow way How do we multiply (1 + 2x) by (3 + x)? STEP 1 — multiply every pair 1 × 3 = 3 1 × x = x 2x × 3 = 6x 2x × x = 2x2 STEP 2 — collect by power of x x0: 3 x1: 1 + 6 = 7 x2: 2 (1 + 2x)(3 + x) = 3 + 7x + 2x2 at x = 1: 3 × 4 = 12 and 3 + 7 + 2 = 12 ✓ 2 numbers times 2 numbers = 4 multiplications. 1000 times 1000 would need 1,000,000 DOUBLE THE SIZE, QUADRUPLE THE WORK Real proofs multiply polynomials with millions of coefficients.
Fig. 1 — multiplying (1 + 2x)(3 + x) the obvious way: multiply every pair of terms, collect by power of x, getting 3 + 7x + 2x². Doubling the degree quadruples the work.
Schoolbook multiplication

(a0+a1x)(b0+b1x)=a0b0+(a0b1+a1b0)x+a1b1x2(a_0 + a_1x)(b_0 + b_1x) = a_0b_0 + (a_0b_1 + a_1b_0)x + a_1b_1x^2

Multiplying two polynomials with nn coefficients each the schoolbook way takes n×nn \times n multiplications — every coefficient of one against every coefficient of the other. For 22 coefficients that’s 44 multiplications; for 1,0001{,}000, that’s a million. Real proofs work with polynomials far larger than that.

Values instead of coefficients

Here’s the key idea that makes everything else in this lesson possible: multiplying polynomials and multiplying their values at the same points are the same operation.

values instead of coefficients Is there an easier way to multiply polynomials? multiplying two polynomials = multiplying their values at the same points use the 4th roots of unity mod 13: 1, 5, 12, 8 STEP 1 — values of f = 1 + 2x f(1) = 3, f(5) = 1 + 10 = 11, f(12) = 1 + 24 = 25 = 12, f(8) = 1 + 16 = 17 = 4 STEP 2 — values of g = 3 + x g(1) = 4, g(5) = 8, g(12) = 15 = 2, g(8) = 11 STEP 3 — multiply point by point 3 × 4 = 12, 11 × 8 = 88 = 10, 12 × 2 = 24 = 11, 4 × 11 = 44 = 5 values of the answer: (12, 10, 11, 5) 3 + 7x + 2x2 at x = 5: 3 + 35 + 50 = 88 = 10 ✓ MULTIPLYING VALUES IS ONE STEP PER POINT 4 points need 4 multiplications, not a grid of pairs.
Fig. 2 — evaluating f = 1 + 2x and g = 3 + x at the four 4th roots of unity mod 13 (1, 5, 12, 8), then multiplying point by point to get the values of the answer.
Pointwise multiplication

(fg)(ωi)=f(ωi)⋅g(ωi)(fg)(\omega^i) = f(\omega^i) \cdot g(\omega^i)

A degree-22 answer needs at least 33 points to pin it down; 44 — the 44th roots of unity — is the convenient choice, because they form a structured set. At each point, multiplying is a single multiplication, not a grid of pairs. The catch: finding the values in the first place still costs something. That’s what the next three sections fix.

The transform as a matrix

Evaluating a polynomial at every root of unity at once has a single formula — and it’s exactly a matrix times a vector, the operation from last lesson.

the transform as a matrix Is there one formula for “evaluate at all four roots”? row j, column k holds ω to the power j × k, where ω = 5 52 = 12, 53 = 8, 54 = 1 1 1 1 1 1 5 12 8 1 12 1 12 1 8 12 5 × (1, 2, 0, 0) = (3, 11, 12, 4) STEP 1 — one row as a dot product third row: 1×1 + 12×2 + 1×0 + 12×0 = 25 = 12 ✓ (3, 11, 12, 4) = the values of f at 1, 5, 12, 8, as before ONE MATRIX EVALUATES AT EVERY ROOT But this is n × n multiplications, the same slow cost. We need a faster way.
Fig. 3 — the matrix whose row j, column k holds ω^(j×k), applied to f's coefficient vector (1, 2, 0, 0) to get its values (3, 11, 12, 4) at all four roots at once.
The DFT matrix

Mjk=ωjk,M⋅(coefficients)=(values at ω0,ω1,…)M_{jk} = \omega^{jk}, \qquad M \cdot (\text{coefficients}) = (\text{values at } \omega^0, \omega^1, \ldots)

Row jj, column kk of this matrix holds ωjk\omega^{jk}, and multiplying it by the coefficient vector evaluates the polynomial at every root of unity simultaneously — each output entry is one row dotted with the coefficients. This matrix has a name, the DFT matrix, but computing MM times a vector directly still costs n×nn \times n multiplications. The structure inside MM is what the next section exploits.

The fast trick

This is the heart of the FFT: split the polynomial into even and odd halves, notice that xx and −x-x square to the same value, and combine two half-size results with a plus and a minus.

the fast trick How can we transform (1, 2, 3, 4) faster? f(x) = 1 + 2x + 3x2 + 4x3 STEP 1 — split into even and odd f(x) = E(x2) + x × O(x2), with E(y) = 1 + 3y and O(y) = 2 + 4y STEP 2 — roots come in pairs x and −x have the same square: 1 and 12 give 1, 5 and 8 give 12 STEP 3 — two small problems E(1) = 4 and E(12) = 1 + 36 = 11 O(1) = 6 and O(12) = 2 + 48 = 11 STEP 4 — combine with plus and minus f(1) = 4 + 1 × 6 = 10 f(12) = 4 − 1 × 6 = −2 = 11 f(5) = 11 + 5 × 11 = 66 = 1 f(8) = 11 − 5 × 11 = −44 = 8 transform = (10, 1, 11, 8) directly: f(5) = 1 + 10 + 75 + 500 = 586 = 45 × 13 + 1 = 1 ✓ ONE BIG PROBLEM BECOMES TWO HALF-SIZE PROBLEMS Repeat the split on each half: about n × log n steps instead of n × n.
Fig. 4 — transforming (1, 2, 3, 4) by splitting f into even part E and odd part O, evaluating each at just two points (1 and 12, since 5 and 8 square to the same values), then combining with ± to get all four values.
The FFT split

f(x)=E(x2)+x⋅O(x2),f(−x)=E(x2)−x⋅O(x2)f(x) = E(x^2) + x \cdot O(x^2), \qquad f(-x) = E(x^2) - x \cdot O(x^2)

Splitting ff into its even-power and odd-power terms gives two half-size polynomials, EE and OO. Because xx and −x-x have the same square, evaluating ff at a root and its negation only needs EE and OO at one shared point each — one addition and one subtraction recovers both values. Repeating this split on each half, recursively, turns n×nn \times n work into about nlog⁡nn \log n: for a million coefficients, roughly 2020 million steps instead of a trillion.

Coming back to coefficients

The round trip needs a way back: from values to coefficients. It turns out to be the exact same algorithm, run with the inverse root, then scaled down.

coming back to coefficients We have the values (12, 10, 11, 5). How do we get the coefficients back? run the same transform with ω−1 = 8, then divide by 4 STEP 1 — the two inverses 5 × 8 = 40 = 1, so ω−1 = 8 4 × 10 = 40 = 1, so 1 ÷ 4 = 10 STEP 2 — transform with 8 (powers of 8 are 1, 8, 12, 5) 12 + 10 + 11 + 5 = 38 = 12 12×1 + 10×8 + 11×12 + 5×5 = 249 = 2 12 + 10×12 + 11 + 5×12 = 203 = 8 12 + 10×5 + 11×12 + 5×8 = 234 = 0 STEP 3 — multiply by 10 12 × 10 = 120 = 3, 2 × 10 = 20 = 7, 8 × 10 = 80 = 2, 0 × 10 = 0 3 + 7x + 2x2 the same answer as the slow way ✓ THE ROUND TRIP RETURNS THE ANSWER Coefficients to values, multiply, values back to coefficients.
Fig. 5 — recovering the coefficients from the values (12, 10, 11, 5) by running the same transform with ω⁻¹ = 8, then dividing every entry by 4 — landing back on 3 + 7x + 2x².
The inverse transform

coefficients=1n⋅transform with ω−1\text{coefficients} = \frac{1}{n} \cdot \text{transform with } \omega^{-1}

Running the transform with ω−1\omega^{-1} instead of ω\omega, then multiplying every entry by n−1n^{-1}, undoes the forward transform exactly — the same matrix structure, just with the inverse root and a final scaling. The full pipeline: transform both polynomials to values, multiply pointwise, transform back — and with the fast trick on both ends, every step is cheap.

Where this shows up

Three ideas: the slow cost that motivates everything, the fast trick that fixes it, and where fields with the right structure make this work at ZK scale.

where this shows up THE SLOW WAY multiply every pair of coefficients n × n steps. THE FAST WAY split into even and odd, combine with plus and minus About n × log n steps. IN ZK fields with many roots of unity, so huge polynomials can be multiplied fast Polynomials at scale. FAST POLYNOMIALS NEED ROOTS OF UNITY Next up: multivariate and multilinear polynomials.
Fig. 6 — the slow way, the fast way, and where this shows up in ZK, and what each one costs.

Schoolbook multiplication costs n×nn \times n; splitting into even and odd parts brings that to about nlog⁡nn \log n. This only works when the field has enough roots of unity to split all the way down — real proof systems choose their field so that p−1p - 1 is divisible by a large power of 22: BN254’s scalar field has roots of unity of order 2282^{28}, and BLS12-381’s has order 2322^{32}. So far every polynomial here has had one variable; the next lesson gives them several.

Key takeaways
  • Multiplying two polynomials the schoolbook way costs n×nn \times n multiplications; multiplying their values at shared points instead costs only nn — one multiplication per point.
  • Evaluating a polynomial at every root of unity at once is a matrix times its coefficient vector, where row jj, column kk holds ωjk\omega^{jk}.
  • The FFT speeds this up by splitting into even and odd parts and using that xx and −x-x square to the same value, so each pair of points shares one dot product; repeating the split brings the cost to about nlog⁡nn \log n.
  • The inverse transform is the same algorithm run with ω−1\omega^{-1} instead of ω\omega, followed by dividing every entry by nn.
  • Real pairing-friendly curves are chosen so p−1p - 1 has a large power of 22 as a factor, giving a field with enough roots of unity for the FFT to split all the way down.