Skip to content

Commit bfa5db7

Browse files
niftyneirustyrussell
authored andcommitted
df-spec: limit allowable inputs/outputs to 252
The maximum inputs and outputs are capped at 252. This effectively fixes the byte size of the input and output counts on the transaction to one (1).
1 parent 26e4bae commit bfa5db7

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

openingd/dualopend.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,21 @@ enum tx_msgs {
7474

7575
/*
7676
* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
77-
* The receiving node:
78-
* ...
79-
* - MUST fail the negotiation if: ...
80-
* - if has received 4096 `tx_add_input` messages during this negotiation
81-
* ...
82-
* - it has received 4096 `tx_add_output` messages during this negotiation
77+
* The maximum inputs and outputs are capped at 252. This effectively fixes
78+
* the byte size of the input and output counts on the transaction to one (1).
8379
*/
8480
#define MAX_TX_MSG_RCVD (1 << 12)
8581

82+
/*
83+
* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
84+
* The receiving node: ...
85+
* - MUST fail the negotiation if: ...
86+
* - there are more than 252 inputs
87+
* - there are more than 252 outputs
88+
*/
89+
#define MAX_FUNDING_INPUTS 252
90+
#define MAX_FUNDING_OUTPUTS 252
91+
8692
/* State for a 'new' funding transaction. There should be one
8793
* for every new funding transaction attempt */
8894
struct tx_state {
@@ -560,6 +566,29 @@ static char *check_balances(const tal_t *ctx,
560566
&state->our_funding_pubkey,
561567
&state->their_funding_pubkey);
562568

569+
/*
570+
* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
571+
* The receiving node: ...
572+
* - MUST fail the negotiation if: ...
573+
* - there are more than 252 inputs
574+
*/
575+
if (tx_state->psbt->num_inputs > MAX_FUNDING_INPUTS)
576+
negotiation_failed(state, "Too many inputs. Have %zu,"
577+
" Max allowed %zu",
578+
tx_state->psbt->num_inputs,
579+
MAX_FUNDING_INPUTS);
580+
/*
581+
* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
582+
* The receiving node: ...
583+
* - MUST fail the negotiation if: ...
584+
* - there are more than 252 outputs
585+
*/
586+
if (tx_state->psbt->num_outputs > MAX_FUNDING_OUTPUTS)
587+
negotiation_failed(state, "Too many inputs. Have %zu,"
588+
" Max allowed %zu",
589+
tx_state->psbt->num_outputs,
590+
MAX_FUNDING_OUTPUTS);
591+
563592
/* Find funding output, check balance */
564593
if (find_txout(psbt,
565594
scriptpubkey_p2wsh(tmpctx, funding_wscript),

0 commit comments

Comments
 (0)