From 38f4f8604a30189481ee9b5d816a65bc30775f60 Mon Sep 17 00:00:00 2001 From: zhuyh1606-oss Date: Mon, 27 Jul 2026 16:23:49 +0800 Subject: [PATCH] openingd: fail channel gracefully when funding_satoshis exceeds maximum Bitcoin supply A peer can crash openingd by sending open_channel with funding_satoshis greater than WALLY_SATOSHI_MAX (21M BTC). The invalid amount flows through to libwally which asserts and aborts the subdaemon. Fix: add a bounds check in both the initiator and fundee paths. If funding_satoshis > chainparams->max_supply, fail the channel with a proper error message instead of crashing. Fixes #9225 Changelog-Fixed: openingd no longer crashes when a peer sends open_channel with funding_satoshis above the maximum Bitcoin supply. --- openingd/openingd.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/openingd/openingd.c b/openingd/openingd.c index 52e50572e2e0..580fe1e4fa10 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -248,6 +248,13 @@ static bool setup_channel_funder(struct state *state) return false; } + if (amount_sat_greater(state->funding_sats, chainparams->max_supply)) { + status_failed(STATUS_FAIL_MASTER_IO, + "funding_satoshis %s exceeds maximum Bitcoin supply", + fmt_amount_sat(tmpctx, state->funding_sats)); + return false; + } + return true; } @@ -939,6 +946,19 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) return NULL; } + /* BOLT #2: + * + * The receiving node MUST fail the channel if: + *... + * - `funding_satoshis` is greater than the maximum Bitcoin supply. + */ + if (amount_sat_greater(state->funding_sats, chainparams->max_supply)) { + peer_failed_err(state->pps, &state->channel_id, + "funding_satoshis %s exceeds maximum Bitcoin supply", + fmt_amount_sat(tmpctx, state->funding_sats)); + return NULL; + } + /* BOLT #2: * * The receiving node MUST fail the channel if: