From a4839b90cb45940cfd768115bdde2ec889a498dd Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Tue, 6 Feb 2024 11:13:47 -0500 Subject: [PATCH] fix(utxo-lib): correct logic for unsafe segwit unspent update In the case that we are updating a PSBT input where we are explicitly flagging that we want to substitute the nonWitnessUtxo for a witnessUtxo for a non-segwit input, we were not checking if the witnessUtxo already existed. This will throw an error for duplicate data TICKET: BTC-855 TICKET: BTC-855 --- modules/utxo-lib/src/bitgo/wallet/Unspent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/utxo-lib/src/bitgo/wallet/Unspent.ts b/modules/utxo-lib/src/bitgo/wallet/Unspent.ts index 7d675be66e..da057fe998 100644 --- a/modules/utxo-lib/src/bitgo/wallet/Unspent.ts +++ b/modules/utxo-lib/src/bitgo/wallet/Unspent.ts @@ -255,7 +255,7 @@ export function updateWalletUnspentForPsbt( // with the previous transaction. Therefore, we can treat Zcash non-segwit transactions as Bitcoin // segwit transactions const isZcashOrSegwit = isSegwit(u.chain) || getMainnet(psbt.network) === networks.zcash; - if ((isZcashOrSegwit && !input.witnessUtxo) || customParams?.skipNonWitnessUtxo) { + if ((isZcashOrSegwit || customParams?.skipNonWitnessUtxo) && !input.witnessUtxo) { const { script, value } = toPrevOutput(u, psbt.network); psbt.updateInput(inputIndex, { witnessUtxo: { script, value } }); } else if (!isZcashOrSegwit) {