-
Notifications
You must be signed in to change notification settings - Fork 281
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
Provide more ergonomic APIs using global-context
#330
Comments
We'll most probably have static precomputation tables soon in upstream. And then the contexts upstream would need a redesign anyway because the only function that remains is randomization. In a sense, I'm not sure if that means we should wait in this PR. Probably not. We could offer the API here, and if upstream moves towards the mentioned direction, we could simply get rid of the |
@real-or-random I don't think you're correct. the context also includes the callback, so I don't think the upstream API will change much. On the other hand, we provide our own callbacks, so we can use a static global context in everything except for signing (due to the randomization). (Although I'd argue that upstream should remove the ability to change the callbacks in runtime but that's a discussion for an upstream issue) |
Indeed, this will need to be discussed. I'd probably also be in favor of this.
Yeah, and here we can randomize the global context, too (as we already do now!) |
I don't follow any upstream discussions but from what I understand, the proposed APIs would be welcomed because that is what upstream might move to anyway? How would we support the no-std usecase then? |
Indeed.
Oh you mean we currently have:
And it may not be a good idea to remove Yeah that's an issue, we need to think about this... edit: Okay, here's a very vague idea: Couldn't we make the context type itself loud? So there will be |
No, I meant how will upstream support a no-std usecase with memory constraints that are tighter than what the global-context uses by default? Correct me if I am wrong but isn't the whole idea of having the context explicit that people can chose how to initialize it, thus providing flexility for no-std, no-allocator, etc? If upstream already provides APIs that imply the global context, this would become impossible?
Generally yes. Cargo's features play well with adding / removing code. Changing functionality of existing code (like randomizing or not randomizing) may lead to weird bugs. So ideally, there are two global contexts and they are activated by different feature flags. |
The context will be static in the binary, and in a size that should work for almost all targets we know about. If some user will actually present an even smaller target then we'll have to handle that, but I don't think that's probable. as for fine details, Maybe we could even hard code the size of that context such that it can be in stack instead of on the heap? (as it should be just a couple of function pointers and a small array) |
Yes, the main point is that you can have this now in flash memory and not in RAM, and usually RAM is the issue here. And if you really want to get rid of one of the two tables in flash, LTO should prune it (including the code that uses it). I'm not sure if this will work across C and Rust but if not, we can still provide |
Okay, interesting! Thanks for the insight! With this outlook, I agree with @real-or-random that going for the above suggestion APIs is the way to go. Once upstream lands the changes to context, we can simply drop the |
When the
global-context
feature is enabled, we could provide more ergonomic APIs:We've been working with
rust-secp256k1
directly a lot lately and found ourselves defaulting to the global context in practically all cases.The text was updated successfully, but these errors were encountered: