feat: batch field inversions in the Solidity Honk verifier#24080
Open
0xedwen wants to merge 1 commit into
Open
feat: batch field inversions in the Solidity Honk verifier#240800xedwen wants to merge 1 commit into
0xedwen wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces clusters of individual
.invert()calls (each hitting the MODEXP precompile) with Montgomery batch inversion—one MODEXP per batch, with linearmulmodoperations for the remaining work. Includes several additional optimizations in the same code paths.Changes
FrLib.batchInvert()Introduces a new library function implementing the standard prefix-product batch inversion technique.
InvertOfZeroif any element is zero, matching the behavior of individual.invert()calls.Sumcheck barycentric evaluation
Each round now:
(roundChallenge - i)a single time per iteration and reuses it for both the numerator product and denominator.Gemini folding
logSizedenominators are precomputed and batch-inverted before entering the fold loop.Shplonk denominators
2 * LOG_N + 1values in non-ZK mode.2 * LOG_N + 2values in ZK mode (including the Libra denominator).ZK-specific optimizations
Additional improvements for the ZK verifier:
256⁻¹ mod pwith a precomputed constant.geminiR^256using 8 squarings instead ofpow().checkEvalsConsistencydenominators.These changes account for most of the observed ZK gas reduction.
MSM seeding
Since
shplonkQalways has scalar1:ecMul.ecAddin the loop.Results
Median
verify()gas usage viaforge test --gas-report:Summary
log_n.checkEvalsConsistencydenominators (256 MODEXP calls → 1).Tests
batchInvertinFrLib.t.sol.test_OffCurve_ShplonkQto verify that MSM seeding does not weaken off-curve validation forshplonkQ.honk_contract.hppandhonk_zk_contract.hppviacopy_to_cpp.sh.