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

secp256k1: Expose Jacobian point equivalency func. #3436

Merged
merged 5 commits into from
Sep 6, 2024

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Sep 4, 2024

This exposes a new function on the JacobianPoint type named EquivalentNonConst which efficiently determines if two Jacobian points represent the same affine point without actually converting the points to affine.

This provides a significant speedup versus first converting to affine for use cases that need the functionality. One example where it is useful is adaptor signatures.

It includes comprehensive tests for edge conditions as well as ongoing randomized testing.

Finally, it also includes some preliminary commits to make the benchmark structure more consistent and introduce a new benchmark for testing Jacobian point equivalency.

The following benchmark shows a before and after comparison of checking Jacobian point equivalency with the new method versus the affine conversion approach:

name                       old time/op   new time/op  delta
--------------------------------------------------------------------------------
JacobianPointEquivalency   17.2µs ± 2%   0.5µs ± 1%   -97.24%  (p=0.000 n=10+10)

Copy link

@martonp martonp left a comment

Choose a reason for hiding this comment

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

LGTM. NBD, but should it be called EquivalentNonConst?

@davecgh davecgh force-pushed the secp256k1_jacobian_point_equals branch from 22760ba to 3e8b1b1 Compare September 5, 2024 10:10
@davecgh
Copy link
Member Author

davecgh commented Sep 5, 2024

LGTM. NBD, but should it be called EquivalentNonConst?

Good point. That would be less likely to potentially cause confusion of exact equality versus equivalent points. Updated.

@davecgh davecgh changed the title secp256k1: Expose EqualsNonConst on jacobian point. secp256k1: Expose Jacobian point equivalency func. Sep 5, 2024
Copy link
Member

@jrick jrick left a comment

Choose a reason for hiding this comment

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

ok with trivial suggestion

dcrec/secp256k1/curve_test.go Outdated Show resolved Hide resolved
dcrec/secp256k1/curve_test.go Outdated Show resolved Hide resolved
dcrec/secp256k1/curve_test.go Outdated Show resolved Hide resolved
dcrec/secp256k1/curve_test.go Outdated Show resolved Hide resolved
dcrec/secp256k1/curve_test.go Outdated Show resolved Hide resolved
@davecgh davecgh force-pushed the secp256k1_jacobian_point_equals branch 2 times, most recently from 7dd885a to 352daf3 Compare September 5, 2024 21:21
dcrec/secp256k1/curve.go Outdated Show resolved Hide resolved
@davecgh davecgh force-pushed the secp256k1_jacobian_point_equals branch from 352daf3 to d0e846e Compare September 6, 2024 18:19
This splits the benchmarks related to curve operations into their own
file to be more consistent with other benchmarks in the package.
This move the benchmarks related to public keys into their own file to
be more consistent with other benchmarks in the package.

It also removes the now empty bench_test.go file.
This splits the closure that determines if two Jacobian represent the same
affine point by first converting them to affine points to a separate
func for use in upcoming tests and benchmarks.
This exposes a new function on the JacobianPoint type named
EquivalentNonConst which efficiently determines if two Jacobian points
represent the same affine point without actually converting the points
to affine.

This provides a significant speedup versus first converting to affine
for use cases that need the functionality.  One example where it is
useful is adaptor signatures.

It includes comprehensive tests for edge conditions as well as ongoing
randomized testing.

The following benchmark shows a before and after comparison of checking
Jacobian point equivalency with the new method versus the affine
conversion approach:

name                       old time/op   new time/op  delta
--------------------------------------------------------------------------------
JacobianPointEquivalency   17.2µs ± 2%   0.5µs ± 1%   -97.24%  (p=0.000 n=10+10)
@davecgh davecgh force-pushed the secp256k1_jacobian_point_equals branch from d0e846e to 809d21b Compare September 6, 2024 19:15
@davecgh davecgh merged commit 809d21b into decred:master Sep 6, 2024
2 checks passed
@davecgh davecgh deleted the secp256k1_jacobian_point_equals branch September 6, 2024 19:23
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