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

Perf: faster final exponentiation (hard part) for BW6 curves #459

Merged
merged 6 commits into from
Oct 17, 2023

Conversation

yelhousni
Copy link
Collaborator

@yelhousni yelhousni commented Oct 12, 2023

Description

This PR otpimizes the final exponentiation (hard part) of BW6 curves.
Fixes #457.

Todo:

  • BW6-761
  • BW6-756
  • BW6-633

The PR also removes some unnecessary computations in the Miller loop (some cases do not occur given the loopCounters).

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested?

Existing pairing tests still apply to the new version.

How has this been benchmarked?

  • Benchmark A, on Macbook Air M1, 16GB RAM
  • BW6-761
benchmark              old ns/op     new ns/op     delta
BenchmarkPairing-8     2592580       2343537       -9.61%
  • BW6-756
benchmark              old ns/op     new ns/op     delta
BenchmarkPairing-8     2566568       2353209       -8.31%
  • BW6-633
benchmark              old ns/op     new ns/op     delta
BenchmarkPairing-8     1574459       1463099       -7.07%
  • Benchmark B, on AWS z1d.large (Intel(R) Xeon(R) Platinum 8151 CPU @ 3.40GHz)
  • BW6-761
benchmark              old ns/op     new ns/op     delta
BenchmarkPairing-2     2250893       2099406       -6.73%
  • BW6-756
benchmark              old ns/op     new ns/op     delta
BenchmarkPairing-2     2453394       2321157       -5.39%
  • BW6-633
benchmark              old ns/op     new ns/op     delta
BenchmarkPairing-2     1579874       1478325       -6.43%

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@github-actions
Copy link

Summary

✅ Passed: 5943
❌ Failed: 0
🚧 Skipped: 5

🚧 Skipped

  • TestAppend (github.com/consensys/gnark-crypto/ecc/bn254/fr/tensor-commitment)
  • TestAppendSis (github.com/consensys/gnark-crypto/ecc/bn254/fr/tensor-commitment)
  • TestCommitmentSis (github.com/consensys/gnark-crypto/ecc/bn254/fr/tensor-commitment)
  • TestReference (github.com/consensys/gnark-crypto/ecc/bn254/fr/sis)
  • TestLimbDecomposition (github.com/consensys/gnark-crypto/ecc/bn254/fr/sis)

@github-actions
Copy link

Summary

✅ Passed: 5943
❌ Failed: 0
🚧 Skipped: 5

🚧 Skipped

  • TestReference (github.com/consensys/gnark-crypto/ecc/bn254/fr/sis)
  • TestAppend (github.com/consensys/gnark-crypto/ecc/bn254/fr/tensor-commitment)
  • TestLimbDecomposition (github.com/consensys/gnark-crypto/ecc/bn254/fr/sis)
  • TestAppendSis (github.com/consensys/gnark-crypto/ecc/bn254/fr/tensor-commitment)
  • TestCommitmentSis (github.com/consensys/gnark-crypto/ecc/bn254/fr/tensor-commitment)

Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yelhousni
Copy link
Collaborator Author

@ivokub I just added BW6-756 and BW6-633 new final exponentiations. For BW6-756 it's the same algorithm as the BW6-761 you reviewed (case t % r % x₀ = 3 in BW6-BLS12 family and algorithm 4.4 from [PhD:Housni22]). It just happens that Expc1 is a Conjugate and Expc2 is the identity map. For BW6-633, it is different (case t % r % x₀ = 0 in BW6-BLS24 family and algorithm 4.5).

@yelhousni yelhousni requested a review from ivokub October 16, 2023 15:58
Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good to me.

Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good to me.

@yelhousni yelhousni merged commit 6652a8b into master Oct 17, 2023
7 checks passed
@yelhousni yelhousni deleted the perf/bw6-finalExp branch October 17, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize BW6 final exponentiation
2 participants