-
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
Problem at use secp256k1 0.22.1 with wasm #470
Comments
Hmm, I worry that this grounds out in the Your backtrace doesn't obviously go through our library ... are you able to re-run with |
Yeah most probably is in that crate. Thanks. |
I believe you have to enable debug symbols or just avoid |
I seem to remember something related to rerandomization and static contexts and wasm... |
I'm using wasm-pack build |
I suspect that wasm (Rust support of wasm?) doesn't support thread locals, but couldn't find anything reasonable on the topic yet. |
Okay, in #385 we started doing rerandomization on context creation ... this linked to #346 (comment). I need to read further but I think this old discussion is relevant. |
Okay it looks like this was "resolved" in #407 where we added the @josediegorobles can you try enabling that feature and see if it fixes your problem? The issue here is that the |
Ok. The issue is that all is working great with previous versions (bitcoin 0.27 - sec256k1 0.20.2). |
What would you like it to do? It doesn't seem there's an obvious better solution. |
@Kixunil it could return a result. Or they could provide an alternate method that would just return bad randomness. I think for now we should disable this line of code when compiling for wasm. |
@apoelstra how can i pass the feature to secp256k1 if i'm using it throught the rust-bitcoin crate? |
Maybe How about requiring either |
@josediegorobles just add it explicitly as another dependency and activate the future. It will activate globally. |
@Kixunil thanks. I was trying that, but i wanted to know if there are a more direct alternative. |
I added secp256k1 = { version = "0.22.1", features = ["global-context-less-secure"] } last line on cargo.toml It's not working but i'm cleaning and compiling again |
You must use the exact same version |
Yeah, is the version it's using rust-bitcoin |
You can see my Cargo.toml here: https://github.com/diba-io/bitmask-core/blob/update-bdk-19/Cargo.toml |
I'm a bit confused ... the new behavior showed up in rust-secp 0.23, but rust-bitcoin is using 0.22, so this shouldn't be an issue? |
Ok. And the branch is not working say: |
Check with |
So why is the problem with 0.22.1 and how i can get rid of that? |
I don't understand the difference between works but gives error and fails. |
@josediegorobles ok, I was just confused about versions. The issue was actually introduced in rust-secp 0.21. In the latest release of rust-bitcoin we jumped form 0.20 to 0.22, which is why you're seeing the problem crop up now.
Can you elaborate on this? |
Ok, @apoelstra I'm adding directly secp256k1 0.22.1 with the feature you said and it does exactly the same. You can see in the Cargo.toml that i link previously, or in the Cargo.lock of same branch, I have to change something more? I have to try to use bitcoin 0.28 with secp256k1 0.23 or something like that? |
@josediegorobles oh! I see the issue. We have disabled randomness for the global context with On our end, we should fix this to disable randomization for local contexts as well, but on your end you shouldn't be calling |
Ok, thanks! |
@josediegorobles exactly. Meanwhile we will fix our library so that you don't need to think about these things :) |
@apoelstra do you have an issue for tracking this? I'm using bdk and apparently they are with this problem so if I solve my part is going to be the same. So, do you think this issue is going to be solved soon or is very problematic? Maybe I can help with something with some guide. |
This is the issue for tracking it :). And no, it's not hard at all. We just need to
I will try to do it later today. |
That's great, I will keep update about that |
@apoelstra isn't it dangerous to silently decrease security just because it's a specific platform? |
@Kixunil yes, but it's also dangerous to stick unexpected panics into library functions. If they could not return a |
We could make it not compile unless the consumer acknowledges lower security or provides custom RNG. Also thankfully these panics are in init functions which is not that bad. |
I don't think it's reasonable to ask a non-cryptographer user to have an opinion about the context rerandomization behavior ... or even a cryptographer user who is unfamiliar with libsecp. For our part IMO we should just disable rerandomization on wasm. |
Why is disabling rerandomization better than forcing the user to provide RNG? |
@Kixunil because if the user can't get a rng from the closest thing that exists to a standard rng package, they won't be able to get a rng from anywhere. |
Isn't the problem with wasm that there's no standardized API for RNG but at least in browsers you can bind JS functions which do have the crypto API? |
So appart from the solution of this issue, what steps could be necessary to make secure the use of secp256k1 on wasm? |
@josediegorobles none of this is required to make secp256k1 secure. There are no additional steps required on your part. Probably we will not be able to solve the issue until @Kixunil returns after the weekend and we come to an agreement on how much of an ergonomic and coginitive load we ought to impose on our users. |
Ok, thanks for the reply. |
so @Kixunil and @apoelstra we are going to have this soon? |
I will open a PR to fix it today or tomorrow.. |
Describe the bug
I have the error that i describe later with last release of rust-bitcoin ( no problem with previous versions).
Build environment
OS+version: 20.04.01
Rust/Cargo version: 1.61.0
Rust/Cargo target: wasm32-unknown-unknown
That's the error:
If anyone wants to repro, check out this commit:
diba-io/bitmask-core@76e83c9
The text was updated successfully, but these errors were encountered: