Skip to content

Commit 6f9db1e

Browse files
committed
Merge bitcoin#30357: Fix cases of calls to FillPSBT errantly returning complete=true
7e36dca test: add test for modififed walletprocesspsbt calls (willcl-ark) 39cea21 wallet: fix FillPSBT errantly showing as complete (willcl-ark) Pull request description: Fixes: bitcoin#30077 Fix cases of calls to `FillPSBT` returning `complete=true` when it's not the case. This can happen when some inputs have been signed but the transaction is subsequently modified, e.g. in the context of PayJoins. Also fixes a related bug where a finalized hex string is attempted to be added during `walletprocesspsbt` but a CHECK_NONFATAL causes an abort. ACKs for top commit: achow101: ACK 7e36dca ismaelsadeeq: Tested ACK 7e36dca pinheadmz: re-ACK 7e36dca Tree-SHA512: e35d19789899c543866d86d513506494d672e4bed9aa36a995dbec4e72f0a8ec5536b57c4a940a18002ae4a8efd0b007c77ba64e57cd52af98e4ac0e7bf650d6
2 parents 45750f6 + 7e36dca commit 6f9db1e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/wallet/wallet.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2225,8 +2225,8 @@ std::optional<PSBTError> CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bo
22252225

22262226
// Complete if every input is now signed
22272227
complete = true;
2228-
for (const auto& input : psbtx.inputs) {
2229-
complete &= PSBTInputSigned(input);
2228+
for (size_t i = 0; i < psbtx.inputs.size(); ++i) {
2229+
complete &= PSBTInputSignedAndVerified(psbtx, i, &txdata);
22302230
}
22312231

22322232
return {};

test/functional/rpc_psbt.py

+23
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ def set_test_params(self):
6868
def skip_test_if_missing_module(self):
6969
self.skip_if_no_wallet()
7070

71+
def test_psbt_incomplete_after_invalid_modification(self):
72+
self.log.info("Check that PSBT is correctly marked as incomplete after invalid modification")
73+
node = self.nodes[2]
74+
wallet = node.get_wallet_rpc(self.default_wallet_name)
75+
address = wallet.getnewaddress()
76+
wallet.sendtoaddress(address=address, amount=1.0)
77+
self.generate(node, nblocks=1, sync_fun=lambda: self.sync_all(self.nodes[:2]))
78+
79+
utxos = wallet.listunspent(addresses=[address])
80+
psbt = wallet.createpsbt([{"txid": utxos[0]["txid"], "vout": utxos[0]["vout"]}], [{wallet.getnewaddress(): 0.9999}])
81+
signed_psbt = wallet.walletprocesspsbt(psbt)["psbt"]
82+
83+
# Modify the raw transaction by changing the output address, so the signature is no longer valid
84+
signed_psbt_obj = PSBT.from_base64(signed_psbt)
85+
substitute_addr = wallet.getnewaddress()
86+
raw = wallet.createrawtransaction([{"txid": utxos[0]["txid"], "vout": utxos[0]["vout"]}], [{substitute_addr: 0.9999}])
87+
signed_psbt_obj.g.map[PSBT_GLOBAL_UNSIGNED_TX] = bytes.fromhex(raw)
88+
89+
# Check that the walletprocesspsbt call succeeds but also recognizes that the transaction is not complete
90+
signed_psbt_incomplete = wallet.walletprocesspsbt(signed_psbt_obj.to_base64(), finalize=False)
91+
assert signed_psbt_incomplete["complete"] is False
92+
7193
def test_utxo_conversion(self):
7294
self.log.info("Check that non-witness UTXOs are removed for segwit v1+ inputs")
7395
mining_node = self.nodes[2]
@@ -589,6 +611,7 @@ def run_test(self):
589611

590612
if self.options.descriptors:
591613
self.test_utxo_conversion()
614+
self.test_psbt_incomplete_after_invalid_modification()
592615

593616
self.test_input_confs_control()
594617

0 commit comments

Comments
 (0)