wallet: reject unmodifiable PSBTs in addpsbtoutput/addpsbtinput
What changed, and why it matters
This update fixes a crash in two wallet commands, addpsbtoutput and addpsbtinput. These commands let users add extra transaction outputs or inputs to a PSBT (a Bitcoin transaction planning file). If a user supplied a PSBT whose version 2 'modifiable' flags forbade such changes, the underlying library refused the operation and the lightning daemon crashed with an assertion failure. The patch now checks those flags beforehand and returns a clean error instead of crashing.
Apply the patch. It is a low-risk, targeted fix that prevents a local denial-of-service crash by validating PSBT modifiability before mutation. No additional mitigation is required beyond upgrading.
Security signals we found
Daemon crash (assertion failure) on crafted/strict PSBT input
Missing validation of PSBT v2 modifiable flags before mutation
User-controlled input directly passed to libwally without precondition check
Fix converts a crash into a controlled JSON-RPC error
Evidence from the diff
The JSON-RPC commands addpsbtoutput and addpsbtinput append outputs/inputs to a user-supplied PSBT using libwally. For PSBT v2, libwally honors tx_modifiable_flags; if the relevant flag (WALLY_PSBT_TXMOD_OUTPUTS or WALLY_PSBT_TXMOD_INPUTS) is not set, psbt_add_output/psbt_append_input fails and an assertion in bitcoin/psbt.c aborts lightningd. The patch introduces psbt_modifiable() in wallet/reservation.c, which treats PSBT v0 as always modifiable and for v2 requires the requested flag bits to be set. Both RPC handlers now call this check after validation and return FUNDING_PSBT_INVALID with a descriptive message before attempting mutation. The existing test_addpsbt_unmodifiable test is no longer marked as expected to fail.
Changed components
wallet/reservation.cJSON-RPC command addpsbtoutputJSON-RPC command addpsbtinputbitcoin/psbt.c (caller site of the failing assertions)Inspect captured patch +14 / −1
### tests/test_wallet.py
@@ -845,7 +845,6 @@ def read_compact(b, i):
@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)
### wallet/reservation.c
@@ -642,6 +642,12 @@ static const struct json_command fundpsbt_command = {
};
AUTODATA(json_command, &fundpsbt_command);
+static bool psbt_modifiable(const struct wally_psbt *psbt, u32 flags)
+{
+ return psbt->version == WALLY_PSBT_VERSION_0 ||
+ (psbt->tx_modifiable_flags & flags) == flags;
+}
+
static struct command_result *json_addpsbtoutput(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
@@ -686,6 +692,10 @@ static struct command_result *json_addpsbtoutput(struct command *cmd,
FUNDING_PSBT_INVALID,
"PSBT failed to validate.");
+ if (!psbt_modifiable(psbt, WALLY_PSBT_TXMOD_OUTPUTS))
+ return command_fail(cmd, FUNDING_PSBT_INVALID,
+ "PSBT does not allow adding outputs");
+
if (amount_sat_less(*amount, chainparams->dust_limit))
return command_fail(cmd, FUND_OUTPUT_IS_DUST,
"Receive amount is below dust limit (%s)",
@@ -797,6 +807,10 @@ static struct command_result *json_addpsbtinput(struct command *cmd,
FUNDING_PSBT_INVALID,
"PSBT failed to validate.");
+ if (!psbt_modifiable(psbt, WALLY_PSBT_TXMOD_INPUTS))
+ return command_fail(cmd, FUNDING_PSBT_INVALID,
+ "PSBT does not allow adding inputs");
+
if (!req_amount || amount_sat_is_zero(*req_amount))
return command_fail(cmd, FUND_INPUT_IS_ZERO, "Cannot add input"
" value of zero.");Why this scored 62/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.