Skip to content

perf: twisted Edwards affine arithmetic#743

Merged
yelhousni merged 2 commits intomasterfrom
perf/tEd
Oct 21, 2025
Merged

perf: twisted Edwards affine arithmetic#743
yelhousni merged 2 commits intomasterfrom
perf/tEd

Conversation

@yelhousni
Copy link
Copy Markdown
Collaborator

@yelhousni yelhousni commented Sep 11, 2025

Description

  • Affine arithmetic in twisted Edwards to use extended coordinates with Z1=Z2=1.
  • Affine scalar multiplication to use mixed addition.

Type of change

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

How has this been tested?

Current tests in twistededwards/ and eddsa/ pass.

How has this been benchmarked?

  • e.g. baby-jubjub:
benchmark                 old ns/op     new ns/op     delta
BenchmarkAdd/Affine-8     4191          2277          -45.67%
benchmark             old ns/op     new ns/op     delta
BenchmarkDouble/Affine-8     2186          1198          -45.20%
benchmark                      old ns/op     new ns/op     delta
BenchmarkScalarMulAffine-8     50688         49545         -2.25%
  • Saves 2-3% in EdDSA verify across different curves.

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 marked this pull request as draft September 11, 2025 13:20
@yelhousni yelhousni requested a review from Copilot September 11, 2025 22:53
@yelhousni yelhousni self-assigned this Sep 11, 2025
@yelhousni yelhousni added this to the v0.10.0 milestone Sep 11, 2025
@yelhousni yelhousni marked this pull request as ready for review September 11, 2025 22:53
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 refactors the twisted Edwards affine arithmetic to use extended coordinates with Z1=Z2=1 for performance improvements. The change replaces the existing point addition and doubling formulas with optimized implementations based on extended coordinates.

  • Implements new extended coordinate formulas for Add and Double operations
  • Reduces the number of field inversions from 2 to 1 per operation
  • Uses optimized variable naming conventions (A, B, C, D, E, F, G, H) following standard extended coordinate algorithms

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/generator/edwards/template/point.go.tmpl Template file with new extended coordinate arithmetic implementations
ecc/bw6-761/twistededwards/point.go Generated code with optimized Add/Double methods
ecc/bw6-633/twistededwards/point.go Generated code with optimized Add/Double methods
ecc/bn254/twistededwards/point.go Generated code with optimized Add/Double methods
ecc/bls24-317/twistededwards/point.go Generated code with optimized Add/Double methods
ecc/bls24-315/twistededwards/point.go Generated code with optimized Add/Double methods
ecc/bls12-381/twistededwards/point.go Generated code with optimized Add/Double methods
ecc/bls12-381/bandersnatch/point.go Generated code with optimized Add/Double methods
ecc/bls12-377/twistededwards/point.go Generated code with optimized Add/Double methods

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ivokub ivokub removed this from the v0.10.0 milestone Oct 7, 2025
Copy link
Copy Markdown
Contributor

@YaoJGalteland YaoJGalteland left a comment

Choose a reason for hiding this comment

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

LGTM. The rearrangement is correct, and the optimization reduces two DIV operations to one inverse operation.

@yelhousni yelhousni merged commit e6314e3 into master Oct 21, 2025
7 checks passed
@yelhousni yelhousni deleted the perf/tEd branch October 21, 2025 17:26
@ivokub ivokub mentioned this pull request Dec 3, 2025
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