perf: optimize pubkey generation by removing unnecessary constant-tim… #793
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!