bdk icon indicating copy to clipboard operation
bdk copied to clipboard

"Missing non_witness_utxo on foreign utxo <utxo>"

Open stevenroose opened this issue 1 year ago • 6 comments

I'm getting this error. What does BDK use to determine whether or not it needs the non_witness_utxo? The UTXO itself is an OP_TRUE p2wsh dust fee anchor, and my wallet is using taproot addresses, so I don't see why it needs that info?

It's annoying for me to have to actually provide entire prev txs for every fee anchor I'm spending, so I'm tempted to just provide a fake tx in that field to avoid this error, but it might actually check if the txid matches the utxo I provided and that would be really annoying..

stevenroose avatar Feb 01 '24 15:02 stevenroose

FWIW the reason we require it is because hardware wallets often require it for segwitv0. We could add an option to wave the requirement I guess.

[EDIT] We already have an option to wave the requirement see only_witness_utxo

LLFourn avatar Feb 02 '24 11:02 LLFourn

See also https://github.com/rust-bitcoin/rust-bitcoin/issues/2175 which has a bit more discussion. This might stem from some bad documentation in rust-bitcoin.

apoelstra avatar Feb 02 '24 14:02 apoelstra

Yeah I think since it's already the user that provides the fields, it should be up to the user to decide whether to set the non_witness_utxo field. If the user is just going to let bdk's hot wallet sign it, there is no need. If he is using a HW that requires it, then he should be adding the field.

stevenroose avatar Feb 02 '24 14:02 stevenroose

But fwiw, I couldn't even find the code that was requiring it. There is this check in add_foreign_utxo about the prevout fields, but it doesn't get generated there, so it must be somewhere deeper in create_tx or so.

stevenroose avatar Feb 02 '24 14:02 stevenroose

I still think it's not ideal that bdk enforces this. In an application where the field is not required, it can be pretty annoying to get his value.. Currently I have to do this workaround

		psbt::Input {
			witness_utxo: Some(self.output.clone()),
			//TODO(stevenroose) BDK wants this here, but it shouldn't
			non_witness_utxo: Some(Transaction {
				version: 2,
				lock_time: bitcoin::absolute::LockTime::ZERO,
				input: vec![],
				output: iter::repeat(TxOut::default()).take(self.point.vout)
					.chain(Some(self.output.clone())).collect(),
			}),
			..Default::default()
		}

stevenroose avatar Feb 14 '24 15:02 stevenroose

@stevenroose did you see that there is only_witness_utxo option on the transaction builder. The docs for add_foreign_utxo actually mentions that this will happen unless you set it.

Sorry I had forgotten about this when I first replied.

LLFourn avatar Mar 21 '24 23:03 LLFourn

@stevenroose can I close this issue? Does this TxBuilder function do what you need? https://docs.rs/bdk/latest/bdk/wallet/tx_builder/struct.TxBuilder.html#method.only_witness_utxo

notmandatory avatar Jun 01 '24 23:06 notmandatory

Closing issue for now, will re-open if above suggestion didn't solve the problem.

notmandatory avatar Jun 19 '24 03:06 notmandatory