Remove PSBT output if KeyPath added to both inputs and outputs
MODIFY
WalletWasabi/Blockchain/Transactions/TransactionFactory.cs
WalletWasabi/Blockchain/Transactions/TransactionFactory.cs
@@ -357,8 +357,19 @@ namespace WalletWasabi.Blockchain.Transactions
foreach (var coin in spentCoins)
{
var rootKeyPath = new RootedKeyPath(fp, coin.HdPubKey.FullKeyPath);
- psbt.AddKeyPath(coin.HdPubKey.PubKey, rootKeyPath, coin.ScriptPubKey);
+ var coinPubkey = coin.HdPubKey.PubKey;
+ psbt.AddKeyPath(coinPubkey, rootKeyPath, coin.ScriptPubKey);
+
+ // In case of multisig address the keyPath is added to both inputs and outputs which is a bug. The following code removes the output in that case. https://github.com/zkSNACKs/WalletWasabi/pull/4600
+ if (psbt.Outputs.SelectMany(output => output.HDKeyPaths.Keys).Contains(coinPubkey) && psbt.Inputs.SelectMany(input => input.HDKeyPaths.Keys).Contains(coinPubkey))
+ {
+ foreach (var output in psbt.Outputs)
+ {
+ output.HDKeyPaths.Remove(coinPubkey);
}
+ }
+ }
+
if (changeHdPubKey is { })
{
var rootKeyPath = new RootedKeyPath(fp, changeHdPubKey.FullKeyPath);

Remove PSBT output if KeyPath added to both inputs and outputs