Repository navigation
BLS12-381: avoid inversion in G2 square roots - #2579
Open
carstenartur wants to merge 1 commit into
Open
carstenartur wants to merge 1 commit into
carstenartur wants to merge 1 commit into
Conversation
carstenartur
marked this pull request as ready for review
November 26, 2026 04:19
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.
Motivation
The non-real Fp² square-root branch used by BLS12-381 G2 hash-to-curve currently uses one or two component exponentiations and a field inversion. This change derives both root coordinates from one inverse-square-root exponentiation, removing the inversion and conditional second exponentiation from that branch.
The patch changes only the implementation and its regression tests. The comparison baseline is upstream commit
6560e91d0a164b8ab58266f141ee6daeec21a340.Correctness
For
p = 3 (mod 4),i² = -1,b != 0, and a supplied norm rootg² = a² + b², compute:Return
(c,d)ifc² = delta, otherwise(d,-c).Here
delta != 0: otherwiseg = -awould implyb² = 0. Euler's criterion givesepsilon = delta*t²in{1,-1}. The norm relation impliesdelta² - b²/4 = a*delta, hence(c+d*i)² = epsilon*(a+b*i). Whenepsilon = -1, multiplying by-igives the required root. Testingc² = deltaidentifies the branch without another exponentiation.The zero/real-input path is retained. The helper may choose the opposite root, which the existing RFC 9380 sign normalization maps to the same curve point. There is no public API change or constant-time claim.
This applies a known technique: Michael Scott, A note on the calculation of some functions in finite fields: Tricks of the Trade, including the quadratic-extension discussion. Sign normalization follows RFC 9380, Appendix F.2.
Measurements
Identical compilation, inputs and JVM settings for baseline and optimized sources; Temurin 21.0.13.1 on AMD EPYC 7763. Each operation used three paired forks per variant, five 1-second warmup iterations, eight 1-second measurement iterations, one benchmark thread and GC profiling.
sqrtOrSqrtZhashToCurveBoth verification speedup intervals include 1; no verification gain is claimed. Helper allocation decreased from 16,196 to 13,115 B/op. These measurements describe this machine and workload.
The complete evidence is retained separately at immutable commit
8fb34a6, whose production and test sources are byte-identical to this patch:Validation
-Xlint:all -Werrorwith Error Prone enabled under the existing check policy. Ordinary Java 8 compatibility compilation was retained; the additional strict diagnostics pass used release 11.The broader core test suite was interrupted before completion and is not claimed as passing. The recorded validation and measurements above use the same production and test sources retained in this focused patch.
AI tools were used in preparing and checking this contribution.