Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the final exponentiation #74

Closed
yelhousni opened this issue Sep 15, 2021 · 1 comment
Closed

Optimize the final exponentiation #74

yelhousni opened this issue Sep 15, 2021 · 1 comment
Assignees

Comments

@yelhousni
Copy link
Collaborator

The cost of the final exponentiation is dominated by Expt(), which is a square-and-multiply exponentiation by the curve seed u. Currently, the squarings are implemented as in the Granger-Scott cyclotomic squaring (GS).

For the curves implemented in gnark-crypto (except for BN254), there is a series of consecutive 0's in the seed and it might be interesting to switch to the Karabina cyclotomic squaring only of this series.

Karabina's method works on compressed GT elements and saves 2 multiplications in F_p^{k/d} compared to GS, where k is the embedding degree and d the twist degree. The cost of decompression, however, is dominated by an inverse in F_p^{k/d}.

Concretely, given a series of s 0's in the seed, the trick is worth it if:

  • For BLS12, 1 inverse over F_p costs less than 6*s-4 muls over F_p
  • For BLS24, 1 inverse over F_p costs less than 18*s-16 muls over F_p
@yelhousni
Copy link
Collaborator Author

If there are more than one series of 0's for which Karabina's cyclotomic square is better, one can use a Montgomery batch inverse to decompress the results of both series at once. Concretely, this happens for BLS24-315 and yields significant speedup and for BLS12-381 but with minor speedup.

@gbotrel gbotrel closed this as completed Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants