BIP 371 noncompliance: Taproot fields remain after adding `PSBT_IN_FINAL_SCRIPTWITNESS` in finalize_psbt
Describe the bug
Finalizers should remove PSBT_IN_TAP_* and PSBT_OUT_TAP_BIP32_DERIVATION after PSBT_IN_FINAL_SCRIPTWITNESS is constructed according to BIP 371 spec
To Reproduce
Fund a psbt with a taproot input. Call wallet.sign on it. See PSBT_IN_TAP_KEY_SIG present on output.
Expected behavior
Fund a psbt with a taproot input. Call wallet.sign on it. See PSBT_IN_TAP_KEY_SIG not present.
Build environment
- BDK-CLI tag/commit: 1.0.0-alpha.1
- Rust/Cargo version: 1.63.0, 1.76.0-nightly
- Rust/Cargo target: wasm32-unknown-unknown
Additional context
I ran into this problem trying to take payjoin BDK-output Original PSBTs and process them at the receiver with walletprocesspsbt on bitcoind, and bitcoind failed to skip the inputs that it encountered having PSBT_IN_TAP_KEY_SIG belonging to the sender. Typically it'd just skip them.
I believe the issue could be fixed by calling clear() on the aforementioned fields here
https://github.com/bitcoindevkit/bdk/blob/b13505c1c3e4d38c3cf47f34e7b18efb822b3b33/crates/bdk/src/wallet/mod.rs#L1883-L1887
I did verify the faulty behavior as you described - fields in a Psbt taproot input, such as tap_key_sig and others, hanging around after finalization, where the BIP clearly states they should be removed. I'll look at implementing a fix and report on any other findings. Thanks @DanGould for spotting the issue and giving a detailed description of what's expected.
Thanks for tackling this @evanlinjin
Thanks for tackling this @evanlinjin
It was mostly @ValuedMammal! I only reviewed and merged 😅