Skip to content

Feat: Jacobian Triple for j=0 curves#715

Merged
gbotrel merged 10 commits intomasterfrom
feat/triple
Aug 25, 2025
Merged

Feat: Jacobian Triple for j=0 curves#715
gbotrel merged 10 commits intomasterfrom
feat/triple

Conversation

@yelhousni
Copy link
Copy Markdown
Collaborator

@yelhousni yelhousni commented Aug 4, 2025

Description

This PR introduces Jacobian Triple for j=0 curves, i.e. [3]P in Jacobian coordinates for curves in the form y^2=x^3+b. This works for all curves supported by gnark-crypto (both G1 and G2) except STARK curve. We follow [XuHanTian24]. The cost is 4S+6M instead of 10S+13M (double+add). The PR also uses Triple in several places across the curves packages.

Type of change

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

How has this been tested?

Testing [3]P == [2]P+P and all the methods which now use Triple method.

How has this been benchmarked?

e.g. BLS12-381 on my MBA M1:

goos: darwin
goarch: arm64
pkg: github.com/consensys/gnark-crypto/ecc/bls12-381
cpu: Apple M1
BenchmarkG1Triple
BenchmarkG1Triple/method=double-and-add
BenchmarkG1Triple/method=double-and-add-8                1435972               818.2 ns/op
BenchmarkG1Triple/method=triple
BenchmarkG1Triple/method=triple-8                        3346026               358.0 ns/op
BenchmarkG2Triple
BenchmarkG2Triple/method=double-and-add
BenchmarkG2Triple/method=double-and-add-8                 539943              2215 ns/op
BenchmarkG2Triple/method=triple
BenchmarkG2Triple/method=triple-8                        1205182               997.0 ns/op

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

@yelhousni yelhousni requested review from Copilot and gbotrel August 4, 2025 17:44
@yelhousni yelhousni self-assigned this Aug 4, 2025
@yelhousni yelhousni added this to the v0.10.0 milestone Aug 4, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new Triple method for computing [3]P (scalar multiplication by 3) in Jacobian coordinates for j=0 elliptic curves. The implementation follows the XuHanTian24 paper and provides significant performance improvements over the traditional double-and-add approach, reducing costs from 10S+13M to 4S+6M.

  • Adds optimized Triple method for all j=0 curves (all supported curves except STARK)
  • Integrates Triple into existing scalar multiplication methods and precomputation tables
  • Optimizes several curve-specific operations like mulBySeed and ClearCofactor to use Triple

Reviewed Changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 11 comments.

File Description
internal/generator/ecc/template/tests/point.go.tmpl Adds test property verifying [3]P == [2]P+P
internal/generator/ecc/template/point.go.tmpl Implements Triple method and integrates it into various multiplication routines
Multiple curve files (g1.go, g2.go, g1_test.go, g2_test.go) Generated implementations of Triple method and optimizations for specific curves

cursor[bot]

This comment was marked as outdated.

ThomasPiellard
ThomasPiellard previously approved these changes Aug 22, 2025
@gbotrel gbotrel merged commit 1200870 into master Aug 25, 2025
7 checks passed
@gbotrel gbotrel deleted the feat/triple branch August 25, 2025 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants