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

Avoid computing square roots where possible in hash_to_curve #73

Closed
huitseeker opened this issue Jul 31, 2023 · 1 comment · Fixed by #77
Closed

Avoid computing square roots where possible in hash_to_curve #73

huitseeker opened this issue Jul 31, 2023 · 1 comment · Fixed by #77
Assignees

Comments

@huitseeker
Copy link
Contributor

The (S)SWU hash_to_curve methods (RFC), introduced in #47 for grumpkin (see also #70 for secp256k1), simply require finding if an element is a quadratic residue in several places in the computation.

This is currently implemented as foo.sqrt().is_some(), which resolves to a square root computation.

I suspect it may be faster to implement a real Legendre symbol there, see e.g. Arkworks:
https://github.com/arkworks-rs/algebra/blob/13fd33e33c1186b2757e3fd3948b6eee16ee9e4b/ff/src/fields/mod.rs#L256-L260

@mratsim
Copy link
Contributor

mratsim commented Aug 23, 2023

For (S)SWU methods you can fuse square root, legendre symbol and sqrt(u/v).

For SVDW method you can optimize the 2 legendre symbols + 3 sqrt in the specs to

  • either 2 legendre and 1 sqrt
  • or 3 fused legendre+sqrt

https://github.com/mratsim/constantine/pull/190/files#diff-5f77dfe5a8625615eb2e4e4d504159b5daa4841864de9161cab1da73e68cb2ebR80-R85

You can accelerate Legendre symbol about 7x using either Pornin or Bernstein-Yang GCD as described here: mratsim/constantine#199

We have a Bernstein-Yang inversion currently being developed for Halo2 which is 8.5x faster than the current implementation (taikoxyz#2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants