Skip to content

openingd: fail channel gracefully when funding\_satoshis exceeds maximum Bitcoin supply - #9357

Open
zhuyh1606-oss wants to merge 1 commit into
ElementsProject:masterfrom
zhuyh1606-oss:fix-9225-openingd-funding-sat-bounds
Open

openingd: fail channel gracefully when funding\_satoshis exceeds maximum Bitcoin supply#9357
zhuyh1606-oss wants to merge 1 commit into
ElementsProject:masterfrom
zhuyh1606-oss:fix-9225-openingd-funding-sat-bounds

Conversation

@zhuyh1606-oss

Copy link
Copy Markdown

Fixes #9225

Problem

A peer can crash \openingd\ by sending \open_channel\ with \ unding_satoshis\ greater than \WALLY_SATOSHI_MAX\ (21M BTC). The invalid amount flows through to libwally which asserts and aborts the subdaemon.

Three crash variants were found during fuzzing:

  1. \ unding_satoshis > WALLY_SATOSHI_MAX\ alone → assert in \psbt_input_set_wit_utxo\
  2. \ unding_satoshis\ and \push_msat\ both exceeding the supply → assert in \�itcoin_tx_add_output\
  3. Individual outputs under the cap but total exceeding → assert in \wally_tx_add_output\

Fix

Add a bounds check in both the \initiator\ and \ undee\ paths. If \ unding_satoshis > chainparams->max_supply, fail the channel with a proper error message instead of crashing.

The single check on \ unding_satoshis\ covers all three variants since the commitment tx outputs are derived from \ unding_satoshis.

Changelog-Fixed: openingd no longer crashes when a peer sends open_channel with funding_satoshis above the maximum Bitcoin supply.

…um 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 ElementsProject#9225

Changelog-Fixed: openingd no longer crashes when a peer sends open_channel with funding_satoshis above the maximum Bitcoin supply.

@Andezion Andezion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about moving the max_supply bound into check_config_bounds() in openingd/common.c? This is the existing shared validation helper for funding amounts and is already called from every path that needs this protection (both funder/fundee in openingd.c, and all four call sites in dualopend.c). dualopend.c appears to have the same unbounded-total pattern with no max_supply check

Comment thread openingd/openingd.c
return false;
}

if (amount_sat_greater(state->funding_sats, chainparams->max_supply)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check whether dualopend.c has the same unbounded-total issue when building its commitment transaction?

Comment thread openingd/openingd.c
*...
* - `funding_satoshis` is greater than the maximum Bitcoin supply.
*/
if (amount_sat_greater(state->funding_sats, chainparams->max_supply)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you added the check at two separate call sites instead of inside check_config_bounds(), given that function already receives the funding amount at every relevant call site?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openingd crashes on assertion wally_err == WALLY_OK when peer sends open_channel with funding_satoshis > WALLY_SATOSHI_MAX

2 participants