Merge PR 'Avoid overflow in closing fee limit calculation' (#5284)
What changed, and why it matters
This patch fixes an integer overflow in the code that calculates the maximum acceptable fee when negotiating a Lightning channel closing transaction. A malicious or buggy peer could potentially supply values that cause the arithmetic to overflow, leading to an incorrect fee limit. The fix uses Rust's saturating addition so the result cannot wrap around. This is a defensive hardening change in a single calculation.
Apply the patch. Consider auditing other fee/weight arithmetic in channel closing and commitment transaction flows for similar overflow risks, and add regression tests with boundary inputs if not already present.
Security signals we found
Integer overflow in fee-limit arithmetic
Peer-influenced inputs in calculation
Use of saturating_add as overflow mitigation
Channel closing / fee negotiation code path
Evidence from the diff
In lightning/src/ln/channel.rs, the closing fee limit calculation added normal_feerate as u64 * tx_weight / 1000 to force_close_avoidance_max_fee_satoshis using normal +. The patch replaces this with saturating_add(), preventing a u64 overflow. The overflow could occur if a peer-provided or derived feerate/weight combination produced a large base value such that adding the configured max fee wrapped. The patch is narrow and only addresses the arithmetic, not the broader input validation.
Changed components
lightning/src/ln/channel.rsChannel closing fee negotiationforce_close_avoidance_max_fee_satoshis option handlingInspect captured patch +3 / −2
### lightning/src/ln/channel.rs
@@ -11435,8 +11435,9 @@ where
// feerate-calculated fee, but allow the max to be overridden if we're using a
// target feerate-calculated fee.
cmp::max(
- normal_feerate as u64 * tx_weight / 1000
- + self.context.config.options.force_close_avoidance_max_fee_satoshis,
+ (normal_feerate as u64 * tx_weight / 1000).saturating_add(
+ self.context.config.options.force_close_avoidance_max_fee_satoshis,
+ ),
proposed_max_feerate as u64 * tx_weight / 1000,
)
} else {Why this scored 59/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.