Skip to content
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 bdk 0.19 with wasm #646

Closed
josediegorobles opened this issue Jun 30, 2022 · 32 comments · Fixed by bitcoindevkit/rust-electrum-client#81
Closed

Problem at use bdk 0.19 with wasm #646

josediegorobles opened this issue Jun 30, 2022 · 32 comments · Fixed by bitcoindevkit/rust-electrum-client#81
Assignees
Labels
bug Something isn't working

Comments

@josediegorobles
Copy link

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)

@josediegorobles josediegorobles added the bug Something isn't working label Jun 30, 2022
@cryptoquick
Copy link

If anyone wants to repro, check out this commit:
diba-io/bitmask-core@76e83c9

@josediegorobles
Copy link
Author

Apparentely is an error of rust-bitcoin/secp256k1
rust-bitcoin/rust-secp256k1#470
rust-bitcoin/rust-bitcoin#1086

@notmandatory
Copy link
Member

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.

@josediegorobles
Copy link
Author

Hi, yeah it will be necessary to update for what I see. Would you think better to keep open this issue?

@josediegorobles
Copy link
Author

Something of interest was said about that in the call?

@notmandatory
Copy link
Member

notmandatory commented Jul 5, 2022

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.

@josediegorobles
Copy link
Author

rust-seccp256k1 was corrected (rust-bitcoin/rust-secp256k1#470 (comment)) 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.

@josediegorobles
Copy link
Author

rust-bitcoin new version is going to be released soon: rust-bitcoin/rust-bitcoin#1117 (comment)

@afilini
Copy link
Member

afilini commented Jul 21, 2022

Let us know once a release candidate is out, I'll update bdk asap

@josediegorobles
Copy link
Author

They have this milestone: https://github.com/rust-bitcoin/rust-bitcoin/milestone/13 appears that it's going to be soon.

@josediegorobles
Copy link
Author

rust-bitcoin 0.29 is released yet

@cryptoquick
Copy link

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:

@josediegorobles
Copy link
Author

rust-bicoincore-rpc part is done yet, now is time for rust-bitcoin/bitcoind#82 and rust-bitcoin/rust-miniscript#452, but they need a new release of rust-bitcoin-rpc: rust-bitcoin/rust-bitcoincore-rpc#239

@danielabrozzoni
Copy link
Member

danielabrozzoni commented Aug 24, 2022

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.

@josediegorobles
Copy link
Author

Thanks, I think is probable that we try something like this while we are testing.

@josediegorobles
Copy link
Author

New release of rust-bitcoincore-rpc https://github.com/rust-bitcoin/rust-bitcoincore-rpc/releases/tag/v0.16.0

@notmandatory
Copy link
Member

notmandatory commented Aug 26, 2022

To help me understand, the dependency PRs that need to be released to fix this issue:

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.

@RCasatta
Copy link
Member

TBD electrsd, bump bitcoind dependency to 0.27.0

Tried to bump the dep but at the moment I've got RCasatta/electrsd#39

Do we need to update with bitcoin 0.29.0 also rust-electrum-client?

@danielabrozzoni
Copy link
Member

Do we need to update with bitcoin 0.29.0 also rust-electrum-client?

Yeah, it seems like that from cargo tree

@notmandatory
Copy link
Member

I added rust-electrum-client to above TODO list.

@danielabrozzoni
Copy link
Member

danielabrozzoni commented Sep 5, 2022

Re-opening as bitcoindevkit/rust-electrum-client@3adfbd7 moved towards the fix, but didn't really fix this :)

@josediegorobles
Copy link
Author

In rust-miniscript this PR is needed to finnnish: rust-bitcoin/rust-miniscript#450

@josediegorobles
Copy link
Author

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: rust-bitcoin/rust-miniscript#462

@danielabrozzoni
Copy link
Member

I was able to find a workaround for bitcoindevkit/bdk-cli#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

@notmandatory
Copy link
Member

We're another step closer to being able to upgrade to rust-bitcoin 0.29, the rust-miniscript PR (rust-bitcoin/rust-miniscript#450) was merged 🎉 we just need it to be published in their next release, 8.0.0

@afilini
Copy link
Member

afilini commented Sep 26, 2022

I'll start working on the update but I don't think we'll make it in time for this release unfortunately

@cryptoquick
Copy link

@afilini That's fine now that we have @danielabrozzoni 's workaround. It's much more important for us at DIBA to get #757 in.

@cryptoquick
Copy link

@danielabrozzoni Found a problem with the rand 0.6 workaround:
rustwasm/wasm-bindgen#3098 (comment)
ngl, i'm ded 💀

@afilini
Copy link
Member

afilini commented Oct 10, 2022

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

@cryptoquick
Copy link

I've subscribed to the discussion there, thanks!

@notmandatory
Copy link
Member

A new release 0.8.0 of rust-miniscript with rust-bitcoin 0.29 was released! 🎉 https://github.com/rust-bitcoin/rust-miniscript/releases/tag/8.0.0

@notmandatory
Copy link
Member

this issue should be fixed by #770

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants