You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[PlonK] Optimize PlonK setup and prover with O(n log n) FFT / coset NTT polynomial evaluations #38
In PlonKSetupBLS381.java and PlonKProverBLS381.java, polynomial evaluations and coset evaluations currently use quadratic loops in certain hotspots (cosetEval, evalOmegaPow).
This $O(n^2)$ behavior throttles PlonK proving for larger circuit sizes ($n > 2^{14}$).
Scope & Tasks
Replace naive evaluation loops with radix-2 Fast Fourier Transforms (FFT / IFFT) and coset NTTs over the BLS12-381 scalar field.
Implement fast domain evaluation structures for powers of roots of unity.
Validate polynomial arithmetic against existing PlonK test vectors.
Benchmark setup and prover throughput on larger PlonK circuits.
Risk Classification
R1: Proof system performance & algorithmic scalability.
Right symptom, wrong diagnosis — and the real fix is about ten lines, not an FFT implementation.
The proposed remedy is already in the repo
Task 1 says "Replace naive evaluation loops with radix-2 Fast Fourier Transforms (FFT / IFFT) and coset NTTs." Those exist and are already used throughout: FieldFFTBLS381.fft/ifft runs across PlonKSetupBLS381.java:118-125, and cosetEval itself ends in an FFT (PlonKProverBLS381.java:467-473). Anyone picking this up as written would implement an FFT that is already there.
Where the Θ(n²) actually is
powFr(base, exp) is a linear loop:
// PlonKProverBLS381.java:554privatestaticMontFr381powFr(MontFr381base, intexp) {
if (exp == 0) returnMontFr381.ONE;
MontFr381r = base;
for (inti = 1; i < exp; i++) r = r.mul(base); // O(exp)returnr;
}
and cosetEval calls it inside a loop over i:
// PlonKProverBLS381.java:467-473for (inti = 0; i < n; i++)
padded[i] = i < coeffs.length ? coeffs[i].mul(powFr(shift, i)) : MontFr381.ZERO;
That is Θ(n²) field multiplications, and cosetEval is called ~15 times per proof (:234-259).
The same pattern is in setup — evalOmegaPow (PlonKSetupBLS381.java:300-304) is the identical linear loop, called as evalOmegaPow(omega, i) in the domainSize loop (:102) and three more times per gate via decodeSigmaTarget (:153). So PlonK setup is Θ(n²) too, which is the harder wall.
Minor, same family: zetaN at PlonKProverBLS381.java:394-395 is an O(n) loop where square-and-multiply is O(log n).
The fix
A running-product accumulator — which cosetIFFT, twelve lines below cosetEval in the same file, already does correctly:
// PlonKProverBLS381.java:476-491 — the correct pattern, already presentMontFr381power = MontFr381.ONE;
for (inti = 0; i < coeffs.length; i++) {
coeffs[i] = coeffs[i].mul(power);
power = power.mul(shiftInv);
}
Apply that shape in cosetEval, precompute one omega-power table in setup, and switch zetaN/powFr to square-and-multiply. Orders of magnitude at n ≥ 2¹⁴, for roughly ten lines.
Suggested retitle
"Fix Θ(n²) power-of-root loops in PlonK setup and prover (powFr / evalOmegaPow)". Existing PlonK test vectors are the validation gate — the outputs must be unchanged, this is pure algorithmic substitution. R1 is right, but this is the best effort-to-value ratio in the batch.
Superseded by #127: the O(n^2) loops in PlonKSetupBLS381 and PlonKProverBLS381 were eliminated in PR #125 (ADR-0068), and the remaining large-circuit scaling and benchmarking work is now consolidated in #127.
Activity
satran004 commentedon Aug 18, 2026
Right symptom, wrong diagnosis — and the real fix is about ten lines, not an FFT implementation.
The proposed remedy is already in the repo
Task 1 says "Replace naive evaluation loops with radix-2 Fast Fourier Transforms (FFT / IFFT) and coset NTTs." Those exist and are already used throughout:
FieldFFTBLS381.fft/ifftruns acrossPlonKSetupBLS381.java:118-125, andcosetEvalitself ends in an FFT (PlonKProverBLS381.java:467-473). Anyone picking this up as written would implement an FFT that is already there.Where the Θ(n²) actually is
powFr(base, exp)is a linear loop:and
cosetEvalcalls it inside a loop overi:That is Θ(n²) field multiplications, and
cosetEvalis called ~15 times per proof (:234-259).The same pattern is in setup —
evalOmegaPow(PlonKSetupBLS381.java:300-304) is the identical linear loop, called asevalOmegaPow(omega, i)in thedomainSizeloop (:102) and three more times per gate viadecodeSigmaTarget(:153). So PlonK setup is Θ(n²) too, which is the harder wall.Minor, same family:
zetaNatPlonKProverBLS381.java:394-395is an O(n) loop where square-and-multiply is O(log n).The fix
A running-product accumulator — which
cosetIFFT, twelve lines belowcosetEvalin the same file, already does correctly:Apply that shape in
cosetEval, precompute one omega-power table in setup, and switchzetaN/powFrto square-and-multiply. Orders of magnitude at n ≥ 2¹⁴, for roughly ten lines.Suggested retitle
"Fix Θ(n²) power-of-root loops in PlonK setup and prover (
powFr/evalOmegaPow)". Existing PlonK test vectors are the validation gate — the outputs must be unchanged, this is pure algorithmic substitution. R1 is right, but this is the best effort-to-value ratio in the batch.satran004 commentedon Nov 22, 2026
Superseded by #127: the O(n^2) loops in PlonKSetupBLS381 and PlonKProverBLS381 were eliminated in PR #125 (ADR-0068), and the remaining large-circuit scaling and benchmarking work is now consolidated in #127.