Repository navigation
fix(wallet): sign mixed taproot and non-taproot inputs - #641
Conversation
Since 3.2.0, the wallet refused to sign these because taproot inputs never get `non_witness_utxo`. Verify taproot amounts against the parent tx stored in the wallet instead. Also verify amounts when ANYONECANPAY is used.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #641 +/- ##
==========================================
+ Coverage 81.87% 82.02% +0.14%
==========================================
Files 25 25
Lines 6291 6310 +19
Branches 302 308 +6
==========================================
+ Hits 5151 5176 +25
+ Misses 1035 1031 -4
+ Partials 105 103 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
fametrano
left a comment
There was a problem hiding this comment.
tACK 32dd8d8
I checked the signatures with btclib, a library I maintain, against the outputs in the wallet's own graph, not the PSBT. At 32dd8d8 the wallet signs a taproot input beside a p2wpkh or p2pkh input, once with the default sighash and once with ALL|ANYONECANPAY on every input, and each transaction verifies; on master 91d3f8e each fails with MissingNonWitnessUtxo. The two new tests fail on master, and the suite passes here.
Following nymius's point on #423 about PSBTs passed to other signers, I had a second wallet sign its p2pkh input in the same transaction: it refuses until the taproot input carries its parent, then signs, and all three inputs verify. On master that step fails with WrongSigningAlgorithm.
The probe and its output: https://gist.github.com/fametrano/a53b5adf339fce067dc8b30f894c7e73/9000bfb6205a78820260bd1e14ad201831d137f3
There was a problem hiding this comment.
ACK 32dd8d8
I ran local tests and manually reviewed the change and ran it through LLM review. The LLM found a related issue that could be fixed in this PR or I'll open a new one, up to you.
| { | ||
| return match input.witness_utxo.as_ref() { | ||
| Some(witness) if witness != prevout => Err(SignerError::InvalidNonWitnessUtxo), | ||
| _ => Ok(()), |
There was a problem hiding this comment.
| _ => Ok(()), | |
| Some(_) => Ok(()), | |
| None => Err(SignerError::MissingWitnessUtxo), |
LLM found issue where this should throw an error if no witness_utxo exists. Example test:
/// A missing later UTXO must not leave signatures from earlier ANYONECANPAY inputs.
#[test]
fn test_psbt_taproot_anyone_can_pay_missing_later_utxo_does_not_sign() {
use bitcoin::sighash::TapSighashType;
let descriptor = get_test_tr_single_sig_xprv();
let (mut wallet, _) = get_funded_wallet_single(descriptor);
receive_output_in_latest_block(&mut wallet, Amount::from_sat(30_000));
let recipient = wallet.next_unused_address(KeychainKind::External);
let mut builder = wallet.build_tx();
builder
.drain_to(recipient.script_pubkey())
.drain_wallet()
.sighash(TapSighashType::AllPlusAnyoneCanPay.into());
let mut psbt = builder.finish().unwrap();
assert_eq!(psbt.inputs.len(), 2);
assert!(psbt.inputs[1].non_witness_utxo.is_none());
psbt.inputs[1].witness_utxo = None;
let signers = signers_from_descriptor(&wallet, descriptor);
let result = wallet.sign_with_signers(
&mut psbt,
&[&signers],
SignOptions {
allow_all_sighashes: true,
..Default::default()
},
);
assert!(matches!(result, Err(SignerError::MissingWitnessUtxo)));
assert!(
psbt.inputs
.iter()
.all(|input| input.tap_key_sig.is_none() && input.tap_script_sigs.is_empty()), "a failed signing attempt must not leave signatures behind"
);
}|
tACK 32dd8d8 I ran just pre-push (nightly fmt, check, clippy -D warnings, stable and unstable test suites, doc build): all pass. I traced that the all_taproot gate is present in v3.2.0 ( I see the backport is already open in PR #643. |
…ackport #641) cb20372 test(wallet): sign mixed taproot and non-taproot inputs (Noah Joeris) 896224f fix(wallet): sign mixed taproot and non-taproot inputs (Noah Joeris) Pull request description: ### Description Backport of #641 to `release/3.x`. Cherry-picked from #641: d01c07d, 32dd8d8. Depends on #636. ### Changelog notice Fixed signing of mixed taproot/non-taproot inputs. ### Before submitting - [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk_wallet/blob/master/CONTRIBUTING.md) ACKs for top commit: Musab1258: tACK cb20372 reez: ACK cb20372 notmandatory: ACK cb20372 Tree-SHA512: da7488479cf3c83ab7543a01f16a440250c74c2cf9fdaf814831e8b96e523e7f1d6a99da66547c71851ded91db7849f78ef151271bf97c5f66f9b9bb5926ef87
…igning 5ed098b test(wallet): cover missing taproot witness utxo with anyonecanpay (Noah Joeris) 7eca236 fix(wallet): reject missing taproot witness utxo before signing (Noah Joeris) Pull request description: ### Description A missing `witness_utxo` on a later Taproot ANYONECANPAY input could leave earlier inputs signed before returning an error. Reject missing `witness_utxo` during input amount validation, before signing. Add a regression test checking that no signatures remain. Addresses [notmandatory’s review comment](#641 (comment)). Targets `release/3.x`. ### Changelog notice #### Fixed - Reject missing Taproot witness UTXOs before signing ANYONECANPAY inputs. ### Before submitting - [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk_wallet/blob/master/CONTRIBUTING.md) - [ ] This PR breaks the existing API Top commit has no ACKs. Tree-SHA512: e80e52d129c13c1dff91248bc123bd9af87909a16030539fbf157dda4c875e0f984e6c3c766681f88b088d63f3905a2147371ee2b1b2fe7dec879279771c22c5
Description
Fix a 3.2.0 regression where mixed Taproot/non-Taproot transactions fail signing with
MissingNonWitnessUtxo.Verify Taproot amounts against parent transactions already stored in the wallet. Skip verification only when all inputs are verified Taproot without
ANYONECANPAY.Thanks @nymius for prompting a closer look #423 (comment).
Changelog notice
Before submitting