-
-
Notifications
You must be signed in to change notification settings - Fork 138
refactor: move to coincurve #843
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
Conversation
ee7845d to
642ca28
Compare
further fixes serialize() -> to_hex() fix step2_bob_dleq more fixes fix p2pk nonce + format test_crypto fix fix tests && non-determinism of schnorr signing more fixes type: ignore
642ca28 to
45343b8
Compare
| PublicKey.__neg__ = PublicKeyExt.__neg__ # type: ignore | ||
| PublicKey.__sub__ = PublicKeyExt.__sub__ # type: ignore | ||
| PublicKey.mult = PublicKeyExt.mult # type: ignore | ||
| PublicKey.__mul__ = PublicKeyExt.__mul__ # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dumb comment: but it's nice when things fit nicely. 😄
|
This PR addresses #592 |
| signature: str, | ||
| ) -> bool: | ||
| pubkey = PublicKey(bytes.fromhex(public_key), raw=True) | ||
| pubkey = PublicKeyXOnly(bytes.fromhex(public_key)[1:]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a PublicKeyCompressed in coincurve? Should be a tiny bit faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed https://ofek.dev/coincurve/api/ and it doesn't appear to have it.
|
awesome addition of benchmarks! |
|
Benchmarks show a drastic drop in performance. I'm questioning whether we should go ahead with this regardless. |
|
The original motivation behind this move was because coincurve was better maintained than secp256k1 and others like CLN used it for their python plugins? That is at least what was in the initial issue/suggestion from July 2024. Are there other driving factors that came up in the last 18 months? |
Yes this was the motivation, but we also want to keep performance in mind. |
|
I'm changing my take. secp256k1-py was last released November 2021. That was a bit more than a year before the first official release (0.2.0) of the secp256k1 library its composed of. They are now at 0.7.0, so a considerable amount of work has continued. And that work is missing from secp256k1-py. On the other hand, coincurve 21 explicitly upgraded the internal libsecp256k1 to version 0.6.0. It sounds like coincurve has moved towards removing all external runtime dependencies in v21 to reduce attack vectors. Its testing against modern python versions and has made a bunch of other security focused changes. It seems like it's a big hit, especially when we look at the benchmarks, but I guess I wonder how it feels in the "real world". And I would personally be happy to trade some performance for safety in this space. edit: |
a18ebf0 to
45343b8
Compare
|
Benchmarks are now moved to a different branch |
Any ideas why this is happening? Both packages just wrap the native C code. Is the performance hit in the C code (old libsecp256k1 vs new one) or is it because of binding code in Python? |
|
@prusnak From a line of Gemini questioning. It was pointing to Python-to-C translation layer and object lifecycle management as the slowdown. And it was stating that bench-marking is "over-blowing" the slowness vs what anyone would see in real world use cases.
And the areas to clean up if we see real world performance hits would be around
It looks like Coincurve is the definitive standard now for python bindings to the secp256k1 curve, and I think the trade offs between safety and robustness/maintained code between the two should trump the performance hits we see when thrown in sandboxed benchmarks. |
I think this might be the cause of most of the performance issue we probably.
+1
+1
+1 |
|
LGTM |

Migrate from
secp256k1-pytocoincurvebindings for the secp256k1 library.fixes #592