Skip to content

Optimize public key generation performance in core C implementation #792

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

Open
peiqing6888 opened this issue May 7, 2025 · 1 comment
Open

Comments

@peiqing6888
Copy link

Hey folks,

While digging through the codebase, I noticed we could squeeze out some extra performance from the public key generation code. The current implementation in secp256k1.c has some room for improvement, particularly in the pubkey creation helper function.

I've been working with this in a high-frequency trading setup, and found we can shave off some unnecessary operations. The main idea is to use variable-time operations where constant-time isn't strictly needed, and clean up the control flow a bit.

Initial benchmarks show around 5-10% speedup in pubkey generation, which adds up in heavy usage scenarios. The changes are pretty straightforward - just optimizing the helper function without touching the core crypto stuff.

Happy to put together a PR if this sounds interesting. Thoughts?

Cheers

@apoelstra
Copy link
Member

Hi @peiqing6888,

We are always happy to take PRs to improve performance. If you want to update the C code then the right venue is the upstream secp256k1 library.

I'm skeptical though that we'll be able to accept a change that makes pubkey generation variable-time. In what contexts is this acceptable? Note that we already have pubkey_tweak_add which takes an existing key and adds an offset to it in variable time.

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

No branches or pull requests

2 participants