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: Return normalized val from DecompressY. #3441

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Sep 7, 2024

The result of the DecompressY function, as the documentation describes, currently returns a value that either has a maximum magnitude of 1 or 2 which also implies that it is not necessarily normalized either. This means the caller is currently responsible for normalization.

While there is no logic issue with that approach, it does mean that callers realistically have to unconditionally normalize the result for almost all realistic use cases even though it might not actually need it.

Those extra normalizations can result in a minor average comparative performance loss when amortized across millions of point decompressions. Further, putting the responsibility on the caller makes it easier make a mistake.

To improve both of those cases, this updates the DecompressY function to normalize the result in all cases when the result is a valid point on the secp256k1 curve (aka the function returns true) before returning it and updates the callers accordingly.

This change also means the result will now always have a max magnitude of 1.

The result of the DecompressY function, as the documentation describes,
currently returns a value that either has a maximum magnitude of 1 or 2
which also implies that it is not necessarily normalized either.  This
means the caller is currently responsible for normalization.

While there is no logic issue with that approach, it does mean that
callers realistically have to unconditionally normalize the result for
almost all realistic use cases even though it might not actually need
it.

Those extra normalizations can result in a minor average comparative
performance loss when amortized across millions of point decompressions.
Further, putting the responsibility on the caller makes it easier make a
mistake.

To improve both of those cases, this updates the DecompressY function to
normalize the result in all cases when the result is a valid point on
the secp256k1 curve (aka the function returns true) before returning it
and updates the callers accordingly.

This change also means the result will now always have a max magnitude
of 1.
@davecgh davecgh force-pushed the secp256k1_decompress_y_normalize branch from cfcea69 to 7333f80 Compare September 12, 2024 22:51
@davecgh davecgh merged commit 7333f80 into decred:master Sep 19, 2024
2 checks passed
@davecgh davecgh deleted the secp256k1_decompress_y_normalize branch September 19, 2024 04:22
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.

2 participants