tests: show addpsbtoutput/addpsbtinput crash on an unmodifiable v2 PSBT
What changed, and why it matters
This commit only adds a new test case that demonstrates two Core Lightning commands, addpsbtoutput and addpsbtinput, crash with an internal assertion when given a v2 PSBT that does not allow adding inputs or outputs. The test is marked as expected to fail for now, so the underlying crash is not fixed in this commit. A remote or local user who can call these RPC commands with a crafted PSBT could cause the lightning daemon to abort.
Treat this as a reported bug requiring a defensive fix: validate PSBT_GLOBAL_TX_MODIFIABLE before invoking libwally add-input/output operations, and return a clean RPC error instead of asserting. The test should be promoted from xfail to passing once the fix lands. Monitor for a follow-up commit that removes the xfail marker.
Security signals we found
Daemon abort due to failed assertion in PSBT helper functions
RPC commands addpsbtoutput and addpsbtinput lack validation of PSBT modifiability flags before calling libwally
Potential denial-of-service vector: any caller able to submit a crafted v2 PSBT can crash lightningd
Test is marked xfail, confirming the crash behavior is known and unfixed in this commit
Evidence from the diff
The commit adds test_wallet.py tests showing that feeding a BIP-370-style v2 PSBT without PSBT_GLOBAL_TX_MODIFIABLE (or with only inputs/outputs modifiable) to addpsbtoutput/addpsbtinput triggers assertion failures in bitcoin/psbt.c (psbt_add_output at line 269 and psbt_append_input at line 233) because libwally rejects adding inputs/outputs. The test expects RPC errors (‘PSBT does not allow adding outputs/inputs’) instead of crashes, and is decorated with @pytest.mark.xfail(strict=True), indicating the bug is reproduced but not yet fixed.
Changed components
wallet/reservation.c (json_addpsbtoutput, psbt_using_utxos, json_addpsbtinput)bitcoin/psbt.c (psbt_add_output, psbt_append_input)tests/test_wallet.pyInspect captured patch +60 / −0
### tests/test_wallet.py
@@ -9,6 +9,7 @@
check_utxos_channel, check_feerate, did_short_sig, first_scid,
)
+import base64
import os
import pytest
import subprocess
@@ -811,6 +812,65 @@ def test_addpsbtoutput(node_factory, bitcoind, chainparams):
assert psbt_info['tx']['vout'][n]['scriptPubKey']['address'] == dest
+def psbt_set_tx_modifiable(psbt_b64, flags):
+ """Set PSBT_GLOBAL_TX_MODIFIABLE, omitting it (like libwally) if flags is 0"""
+
+ def read_compact(b, i):
+ n = b[i]
+ if n < 0xFD:
+ return n, i + 1
+ size = {0xFD: 2, 0xFE: 4, 0xFF: 8}[n]
+ start = i + 1
+ end = start + size
+ return int.from_bytes(b[start:end], "little"), end
+
+ b = base64.b64decode(psbt_b64)
+ assert b[:5] == b"psbt\xff"
+ out = b[:5]
+ i = 5
+ while b[i] != 0:
+ start = i
+ klen, i = read_compact(b, i)
+ end = i + klen
+ key = b[i:end]
+ vlen, i = read_compact(b, end)
+ i += vlen
+ if key != b"\x06":
+ out += b[start:i]
+ if flags:
+ out += bytes([1, 6, 1, flags])
+ return base64.b64encode(out + b[i:]).decode()
+
+
+@unittest.skipIf(
+ TEST_NETWORK != "regtest", "elementsd doesnt yet support PSBT features we need"
+)
+@pytest.mark.xfail(strict=True)
+def test_addpsbt_unmodifiable(node_factory):
+ l1 = node_factory.get_node()
+ l1.fundwallet(10**7)
+
+ psbt = l1.rpc.addpsbtoutput(1000000)["psbt"]
+ psbt = l1.rpc.setpsbtversion(psbt, 2)["psbt"]
+ unmodifiable = psbt_set_tx_modifiable(psbt, 0)
+ inputs_only = psbt_set_tx_modifiable(psbt, 1)
+ outputs_only = psbt_set_tx_modifiable(psbt, 2)
+
+ with pytest.raises(RpcError, match="PSBT does not allow adding outputs"):
+ l1.rpc.addpsbtoutput(1000000, unmodifiable)
+ with pytest.raises(RpcError, match="PSBT does not allow adding inputs"):
+ l1.rpc.addpsbtinput(1000000, unmodifiable)
+ with pytest.raises(RpcError, match="PSBT does not allow adding outputs"):
+ l1.rpc.addpsbtoutput(1000000, inputs_only)
+ with pytest.raises(RpcError, match="PSBT does not allow adding inputs"):
+ l1.rpc.addpsbtinput(1000000, outputs_only)
+
+ assert not any(o["reserved"] for o in l1.rpc.listfunds()["outputs"])
+
+ assert l1.rpc.addpsbtoutput(1000000, outputs_only)["outnum"] == 1
+ assert l1.rpc.addpsbtinput(1000000, inputs_only)["appended_inputs"] == 1
+
+
def test_utxopsbt(node_factory, bitcoind, chainparams):
amount = 1000000
l1 = node_factory.get_node()Why this scored 59/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.