Skip to content

perf: optimize pubkey generation by removing unnecessary constant-tim… #793

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

Closed

Conversation

peiqing6888
Copy link

Hey folks.

Recently, while doing high frequency trading, I realized that the public key generation part could be faster.

I took a closer look at the code and found that some constant time operations in pubkey_create_helper can be optimized.

The change is very simple, that is, some of the operations that do not require constant time are replaced with variable time operations.

For example, scalar_set_b32_seckey is replaced by scalar_set_b32, ge_set_gej is replaced by ge_set_gej_var, and the use of constant time operations in these places is a bit of a killjoy.

The measured performance improvement is around 5-10%.

For high-frequency trading, a little bit faster is a little bit faster.

I have carefully reviewed the security aspects, the confidentiality is still confidential, just the fastest place to make it faster.
Benchmark numbers.

Before: ~123k pubkey/sec
After: ~132k pubkey/sec
Feel free to review and discuss any questions you may have.

Cheers!

@apoelstra
Copy link
Member

As I mentioned in #792 -- you probably want to PR this upstream rather than here (in fact, our CI will reject these changes which make nontrivial changes to the vendored C code). I also don't believe that these changes are safe in general. But to consolidate discussion probably we want to discuss it on an upstream PR.

@apoelstra apoelstra closed this May 7, 2025
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.

2 participants