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: optimize Verify and BatchVerifyMultiPoints methods #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

yelhousni
Copy link
Contributor

@yelhousni yelhousni commented Jul 22, 2024

This PR ports two optimizations from gnark-crypto:

  • Re-arranging the Verify pairing equation so that instead of doing a G1 scalar mul and a G2 scalar mul, we do a G1 2-MSM with Strauss-Shamir trick.
// [f(z)]G₁ + [-z]([H(α)]G₁) = [f(z) - z*H(α)]G₁
  • Re-arranging the pairing equations in Verify and BatchVerifyMultiPoints makes it possible to pre-compute the lines in pairing computation corresponding to G₂ and [α]G₂
 // e([f(α)-f(z)+aH(α)]G₁], G₂).e([-H(α)]G₁, [α]G₂) == 1

These pre-computed lines can be stored in the SRS.

Bench

On a z1d.large AWS machine

goos: linux
goarch: amd64
pkg: github.com/crate-crypto/go-kzg-4844/internal/kzg
cpu: Intel(R) Xeon(R) Platinum 8151 CPU @ 3.40GHz

First optimisation saving for Verify:

benchmark                old ns/op     new ns/op     delta
BenchmarkKZGVerify-2     1121344       982636        -12.37%

The two optimisations combined:

benchmark                old ns/op     new ns/op     delta
BenchmarkKZGVerify-2     1121344       822792        -26.62%

@yelhousni
Copy link
Contributor Author

Last commit reverts the use of pre-computed lines which are not currently compatible with Ethereum SRS.

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 this pull request may close these issues.

1 participant