Repository navigation
Conversation
444929f to
a5b945f
Compare
| @Test | ||
| fun createExtendedWPKHDescriptors() { | ||
| Descriptor("wpkh($TEST_EXTENDED_PRIVKEY/$BIP84_TEST_RECEIVE_PATH/*)", NetworkKind.TEST) | ||
| val dec = Descriptor("wpkh($TEST_EXTENDED_PRIVKEY/$BIP84_TEST_RECEIVE_PATH/*)", NetworkKind.TEST) |
There was a problem hiding this comment.
This file should be removed.
b9ef430 to
29cd018
Compare
|
Just did a rebase on this one and I see errors. Because I am changing the structure of keymap in this PR any other PR that makes use of keymap will cause this PR to fail after rebase. I will fix this and alert you when its done. But we might want to consider reviewing this and merging this soon, to reduce the number of iterations. Or I fix it when we are almost ready for it. |
yeah feel free to just ping me here when it gets un-drafted so I can try to review it |
29cd018 to
841c17d
Compare
|
Shaping up nice, a couple questions: |
Yes, I agree. Theres nothing else users are using the wrapper for. I will update to reflect this.
No, that was not intended. At the very least error should be return if error (I guess I got too excited once i saw sign worked 😂). But I did intentionally discard the rust-bitcoins result. Just like keymapwrapper, do our users have use for SigningKeysMap (rust-bitcoin’s signing result) I was not sure. |
c407880 to
ef814ee
Compare
|
Updated error message |
| ); | ||
| } | ||
| let bdk_wrapper = bdk_wallet::miniscript::descriptor::KeyMapWrapper::from(bdk_map); | ||
| let sign_result = psbt.sign(&bdk_wrapper, &secp); |
There was a problem hiding this comment.
Could we fix the origin-path handling in the pinned KeyMapWrapper before exposing this? With tr([fingerprint/86h/1h/0h]account_xprv/0/*) and a matching PSBT, signing returns no errors but produces a tap_key_sig that fails Schnorr verification. Miniscript 12.3.7 derives the full origin path again from the account xprv; the equivalent master-xprv case verifies successfully. Please use a corrected key lookup and add a regression that verifies the signature rather than only checking its presence.
There was a problem hiding this comment.
Can you provide example of valid psbt you used for sign test? Also how did you verify schnorr were you expecting schnorr signature after signing ?
There was a problem hiding this comment.
Yes, I expected Schnorr here because this is a Taproot (tr(...)) input. I verified tap_key_sig against the tweaked output key using the transaction’s Taproot sighash.
I reran the test: the account-xprv case fails verification, while the equivalent master-xprv case passes. Neither reports a signing error. Just to clarify, this is a synthetic unit-test PSBT, not an on-chain funded transaction.
PSBT and signing descriptor (disposable test key)
Unsigned PSBT:
cHNidP8BAF4CAAAAAU1jsXk14vinaw/FavxEf6I13DTTWcQ3W3qfEO45TulmAAAAAAD/////ASgjAAAAAAAAIlEgXnzxN1lKw2Se0nelATBRTNfinxJWqjQNKLqvwkspeREAAAAAAAEBKxAnAAAAAAAAIlEgXnzxN1lKw2Se0nelATBRTNfinxJWqjQNKLqvwkspeREhFtXKImYR1dqFkU+0ktlTKKLzI4vHT1o4Ukyt7xYanJ5zGQBRWcFzVgAAgAEAAIAAAACAAAAAAAAAAAABFyDVyiJmEdXahZFPtJLZUyii8yOLx09aOFJMre8WGpyecwAA
Account descriptor (checksum omitted):
tr([5159c173/86h/1h/0h]tprv8gfBCLYgHZLJLhg1DUSY6NN6eNAee3aqt3SE3M1hywpAiFWYGsm6U6B17VDKh8W1SQnatRpZujU5xseJ84nYZmkxPGCngNhmBMVRY2sAZhY/0/*)
There was a problem hiding this comment.
Thanks. Will try with your examples by tomorrow.
Maybe a good place for you to check is bdk-wallet. So we see the results there as well.
There was a problem hiding this comment.
Sorry I am just getting back, its been a busy couple of weeks. After some digging, I have confirmed that your findings are correct. Account level xprv descriptor fails when the keyMapWrapper is used. It seems like getkey implementation in miniscript fails to recognise that the path as already walked up until 86h/1h/0h and recomputes the full path again creating a key for 86h/1h/0h/86h/1h/0h/0/0 which is wrong. Should be 86h/1h/0h/0/0
I have tried this in bdk-wallet too and got the same issue. The error shows up when we try to do a finalize on the psbt. I also tried a getkey implementation of Signer from bdk_tx and that worked fine. It is indeed a miniscript issue like you said (at least 12.3.7). I have a feeling its been updated/fixed in more recent versions of miniscript as I skimmed through its recent getkey implementations and it looked updated. Not withstanding, 12.3 is still the version our latest bdk-wallet is on.
I will open an issue on bdk-wallet as we use keymapwrapper a lot in examples and in tests on there. It shouldnt be the case that they (miniscript) are assuming we will always pass a master-xpr in our descriptor anytime we are using KeyMapWrapper. Only master-xpr seems to be working with KeyMapWrapper. Opens a bigger conversation about exposing bdk_tx::Signer and using that instead of KeyMapWrapper getkey implementation.
I shall link the issue here as soon as I open it.
ef814ee to
842812b
Compare
|
This is now ready for review |
a364463 to
43908e6
Compare
There was a problem hiding this comment.
Thanks for the simplified API! This is much easier to work with at the cost of having to wrap a few things ourselves.
As is however I think it's hard to use. Here are some problems I suspect I'd be facing if I was using it:
- The sign method only take a single descriptor but a lot of wallets would have 2, and you don't really know if any given transaction has inputs from both keychains or only one, so you'd need to always call it twice. Let's pass a vector of Descriptors to the method instead of a single one.
- The signing result is not super usable and could be reworked. For example, which public keys signed which input (SigningKeys) is a debugging detail. It's untyped (Vec) and splits ECDSA from Schnorr in a way callers don't really care about I don't think. At the moment, you also don't know if your call signed anything. You might have passed the wrong descriptor, or passed a public descriptor.
How do you feel about this:
#[derive(uniffi::Record)]
pub struct PsbtSignResult {
/// Inputs that received at least one new signature in this call.
pub signed_inputs: Vec<u64>,
/// Inputs that could not be processed, keyed by input index.
pub errors: HashMap<u64, PsbtSignError>,
}This gives you an error per-input, and number of inputs signed. You still need to check whether all inputs are signed and the psbt is ready for finalizing using psbt.finalize().
You could also throw for public descriptors: if every descriptor's key_map is empty, return Err(NoSecretKeys). So the signature would become Result<PsbtSignResult, PsbtSignError>.
Note: the API docs on Psbt::sign are copy/pasted from rust-bitcoin but they refer to things that don't make sense for us, so I'd write them for our flow instead.
|
All the concerns I raised earlier are resolved. I’ll let Thunder’s review comments #1051 (review) get addressed. Otherwise this LGTM |
|
Thanks for the review! On the result type:
signing_keys_map does tell us: an input with a non-empty key list was signed. One catch is that rust-bitcoin also inserts inputs with an empty list when no key matched, so callers have to check the list rather than the index. That's the thing signed_inputs would simplify, and I'm fine with that. |
|
I think an empty vector of input signed makes sense for signalling that no keys or conditions in the descriptors matched the requirements in the PSBT. If the user expected some signatures, then they'd have to investigate input per input, but for the base case a check that I'd be ok with a method on the type that would return this more explicitly if you like, something like |
43908e6 to
bd9a33e
Compare
Description
Addresses #866
Notes to the reviewers
See comment - #866 (comment)
Documentation
bdk_walletbitcoinuniffiChangelog
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingchangelog:*labelNew Features: