Perf: variant of the Karabina cyclotomic squaring #933
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.
Description
Currently we implement Theorem 3.2 from https://eprint.iacr.org/2010/542.pdf whenever we have 3 repeated squaring or more in the final exponentiation. It is the fastest variant of cyclotomic squaring but in-circuit the selector logic to handle branching cases when denominators are zero makes it not always the best in some cases. This PR compares different variants in Sec. 5 and proposes a tradeoff:
For the native case, when repeated squaring size is:
So nothing changes concretely for BLS12-377 since we do not encouter the case of size 3.
For emulated case, it difficult to theoretically set a threshold due to emulated arithmetic but empirically for BW6-761:
Type of change
How has this been tested?
TestExptFp6andTestFinalExponentiationTestSolveare used here to test the new Karabina variants. Otherwise we need to implement the go version of these in gnark-crypto.How has this been benchmarked?
For BW6-761, this saves 290826 SCS in the Final exp.
Checklist:
golangci-lintdoes not output errors locally