bdk
bdk copied to clipboard
Problem at use bdk 0.19 with wasm
Describe the bug
Bdk fails on the web.
I think must be some thing related to rand crate.
To Reproduce
Create a wallet and call synchronize
Expected behavior
Working as in the console, without problems (and as in 0.18 and previous versions).
Build environment
- BDK tag/commit: 0.19
- OS+version: 20.04.01
- Rust/Cargo version: 1.61.0
- Rust/Cargo target: wasm32-unknown-unknown
Additional context
That's the error:
Uncaught (in promise) RuntimeError: unreachable
at __rust_start_panic (67d29ce8a8f7d806078e.module.wasm:0xc6d5d8)
at rust_panic (67d29ce8a8f7d806078e.module.wasm:0xc55f4c)
at std::panicking::rust_panic_with_hook::he2a025723e105e28 (67d29ce8a8f7d806078e.module.wasm:0x960d29)
at std::panicking::begin_panic_handler::{{closure}}::hd9f8c213ec91b9d5 (67d29ce8a8f7d806078e.module.wasm:0xa6ac56)
at std::sys_common::backtrace::__rust_end_short_backtrace::h6efd730283875809 (67d29ce8a8f7d806078e.module.wasm:0xc6c185)
at rust_begin_unwind (67d29ce8a8f7d806078e.module.wasm:0xc16d18)
at core::panicking::panic_fmt::hb02133958c1e7d35 (67d29ce8a8f7d806078e.module.wasm:0xc24531)
at rand::rngs::thread::THREAD_RNG_KEY::__init::{{closure}}::ha2ad45ff6630e75f (67d29ce8a8f7d806078e.module.wasm:0xa55aef)
at core::result::Result<T,E>::unwrap_or_else::hdc727ae752f97c76 (67d29ce8a8f7d806078e.module.wasm:0x73eae4)
at rand::rngs::thread::THREAD_RNG_KEY::__init::hfb75fbbba2c214fb (67d29ce8a8f7d806078e.module.wasm:0x80efe3)
If anyone wants to repro, check out this commit: https://github.com/diba-io/bitmask-core/pull/53/commits/76e83c953b0c7ecd5006b1c9d32c01e4cb644c6d
Apparentely is an error of rust-bitcoin/secp256k1 https://github.com/rust-bitcoin/rust-secp256k1/issues/470 https://github.com/rust-bitcoin/rust-bitcoin/issues/1086
Thanks for getting to the bottom of this with the rust-bitcoin team. Please keep us updated on when bdk can update to a new rust-bitcoin or secp256k1 library to support WASM.
Hi, yeah it will be necessary to update for what I see. Would you think better to keep open this issue?
Something of interest was said about that in the call?
I think it's good to keep this issue open until what ever changes we need in rust-bitcoin and rust-secp256k1 are released. I just made the rest of the team on the call aware of the research you did on this for anyone else working with bdk and WASM.
rust-seccp256k1 was corrected (https://github.com/rust-bitcoin/rust-secp256k1/issues/470#event-7018099093) and is realeased with new changes, version 0.24.
rust-bitcoin is updated to new rust-secp256k1 version on master branch but it's not released a new version yet, so we must to wait until that.
rust-bitcoin new version is going to be released soon: https://github.com/rust-bitcoin/rust-bitcoin/issues/1117#issuecomment-1191189467
Let us know once a release candidate is out, I'll update bdk asap
They have this milestone: https://github.com/rust-bitcoin/rust-bitcoin/milestone/13 appears that it's going to be soon.
rust-bitcoin 0.29 is released yet
With rust-bitcoin 0.29 ready, here's a list of PRs / issues currently at play in order to update BDK to rust-bitcoin 0.29:
- https://github.com/rust-bitcoin/rust-miniscript/issues/452
- https://github.com/rust-bitcoin/rust-bitcoincore-rpc/pull/234
- https://github.com/rust-bitcoin/rust-bitcoincore-rpc/pull/222
- https://github.com/RCasatta/bitcoind/issues/82
rust-bicoincore-rpc part is done yet, now is time for https://github.com/RCasatta/bitcoind/issues/82 and https://github.com/rust-bitcoin/rust-miniscript/issues/452, but they need a new release of rust-bitcoin-rpc: https://github.com/rust-bitcoin/rust-bitcoincore-rpc/issues/239
What I'm doing for the BDK playground is using a patched version of BDK that doesn't use rand:
# TODO: somehow apply use this only on wasm?
# See https://github.com/rust-lang/cargo/issues/1197
bdk = { git = "https://github.com/bitcoindevkit/bdk.git", branch = "patch_without_rand_for_wasm" }
Since the secp documentation states:
To generate random keys or to re-randomize a context object, compile with the rand-std feature. If you are willing to use the rand-std feature, we have enabled an additional defense-in-depth sidechannel protection for our context objects, which re-blinds certain operations on secret key data.
I suppose this quick fix is not really safe to use in mainnet - the playground is testnet only, so good enough.
Consider this only if your application is still in a testing phase and not being used by anyone in production.
Thanks, I think is probable that we try something like this while we are testing.
New release of rust-bitcoincore-rpc https://github.com/rust-bitcoin/rust-bitcoincore-rpc/releases/tag/v0.16.0
To help me understand, the dependency PRs that need to be released to fix this issue:
- https://github.com/rust-bitcoin/rust-secp256k1/issues/474, released in 0.23.4
- https://github.com/rust-bitcoin/rust-bitcoin/pull/1066, released in 0.29.0
- https://github.com/rust-bitcoin/rust-bitcoincore-rpc/pull/234, released in 0.16.0
- https://github.com/RCasatta/bitcoind/pull/84, released in 0.27.0
- https://github.com/rust-bitcoin/rust-miniscript/pull/450, released 8.0.0
- https://github.com/bitcoindevkit/rust-electrum-client/pull/81, released in 0.12.0
- https://github.com/RCasatta/electrsd/pull/42, released in 0.21.0
- #770 , bdk release 0.24.0
I'll update this comment as PRs get added, merged, and released. Please leave a comment below if I missed anything and I will add.
TBD electrsd, bump bitcoind dependency to 0.27.0
Tried to bump the dep but at the moment I've got https://github.com/RCasatta/electrsd/issues/39
Do we need to update with bitcoin 0.29.0 also rust-electrum-client?
Do we need to update with bitcoin 0.29.0 also rust-electrum-client?
Yeah, it seems like that from cargo tree
I added rust-electrum-client to above TODO list.
Re-opening as https://github.com/bitcoindevkit/rust-electrum-client/commit/3adfbd783ff68e3f668b4bd6e1d7d0654e2bf662 moved towards the fix, but didn't really fix this :)
In rust-miniscript this PR is needed to finnnish: https://github.com/rust-bitcoin/rust-miniscript/pull/450
Hi, rust-miniscript master branch is with rust-bitcoin 0.29 yet; but they don't have a release for now, they have this draft PR: https://github.com/rust-bitcoin/rust-miniscript/pull/462
I was able to find a workaround for https://github.com/bitcoindevkit/bdk-cli/pull/117, try adding these lines to the Cargo.toml:
[target.'cfg(target_arch = "wasm32")'.dependencies]
rand = { version = "^0.6", features = ["wasm-bindgen"] }
Let me know if it works for you, so that we can close the issue
We're another step closer to being able to upgrade to rust-bitcoin 0.29, the rust-miniscript PR (https://github.com/rust-bitcoin/rust-miniscript/pull/450) was merged 🎉 we just need it to be published in their next release, 8.0.0
I'll start working on the update but I don't think we'll make it in time for this release unfortunately
@afilini That's fine now that we have @danielabrozzoni 's workaround. It's much more important for us at DIBA to get #757 in.
@danielabrozzoni Found a problem with the rand 0.6 workaround: https://github.com/rustwasm/wasm-bindgen/issues/3098#issuecomment-1270783733 ngl, i'm ded :skull:
There's not much we can do about that, BDK itself depends on rand 0.7 so we are not the issue. secp256k1 has been updated to use rand 0.8, but the new secp is only used in rust-bitcoin 0.29, which we can't update to because miniscript hasn't been released yet. I was hoping we could do it in time for our 0.23 release, but it turns out there's still some work left to do there.
I have a PR already open, in draft, if you want to follow the process: #770
I've subscribed to the discussion there, thanks!