@@ -74,15 +74,21 @@ enum tx_msgs {
74
74
75
75
/*
76
76
* 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).
83
79
*/
84
80
#define MAX_TX_MSG_RCVD (1 << 12)
85
81
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
+
86
92
/* State for a 'new' funding transaction. There should be one
87
93
* for every new funding transaction attempt */
88
94
struct tx_state {
@@ -560,6 +566,29 @@ static char *check_balances(const tal_t *ctx,
560
566
& state -> our_funding_pubkey ,
561
567
& state -> their_funding_pubkey );
562
568
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
+
563
592
/* Find funding output, check balance */
564
593
if (find_txout (psbt ,
565
594
scriptpubkey_p2wsh (tmpctx , funding_wscript ),
0 commit comments