Merge PR 'Use checked addition for anchor reserve UTXO input weight' (#5488)
What changed, and why it matters
This patch fixes a place where two numbers representing the size of a Bitcoin transaction input were added together using normal addition, which could silently overflow and wrap around to a tiny value in Rust. By switching to checked addition, the code now treats an overflow as a failure case and falls back to a maximum fee, preventing a malformed or extremely large UTXO from causing an underpriced fee estimate. The practical security impact is moderate: it could let an attacker-provided UTXO slip past a reserve check, but the surrounding code has other safeguards and the scenario requires a very large, crafted satisfaction_weight.
Apply the patch. Additionally, review other locations where UTXO satisfaction_weight or other externally influenced weight values are combined with constants using unchecked arithmetic, and consider input validation bounds on satisfaction_weight at deserialization or ingestion time.
Security signals we found
Integer overflow in weight calculation
Potential fee underestimation from wrapped weight
Reserve eligibility bypass via crafted UTXO satisfaction_weight
Use of checked arithmetic as hardening
Evidence from the diff
In anchor_channel_reserves.rs, get_supportable_anchor_channels computes the fee to spend a UTXO as upper_bound_fee_rate.fee_wu(Weight::from_wu(BASE_INPUT_WEIGHT + utxo.satisfaction_weight)). The addition of BASE_INPUT_WEIGHT and utxo.satisfaction_weight was an unchecked u64 addition. If utxo.satisfaction_weight is crafted to overflow u64, the sum wraps to a small value, fee_wu returns a small fee, and amount = utxo.output.value - spend_fee becomes larger than it should be, potentially allowing a UTXO to be counted as supporting an anchor channel reserve when it cannot actually cover the real spend cost. The patch uses checked_add and propagates None through and_then so that overflow causes unwrap_or(Amount::MAX), making spend_fee huge and amount minimal, which rejects the UTXO. This is a defensive fix for an integer-overflow-driven logic bypass.
Changed components
lightning/src/util/anchor_channel_reserves.rsget_supportable_anchor_channelsInspect captured patch +5 / −3
### lightning/src/util/anchor_channel_reserves.rs
@@ -240,9 +240,11 @@ pub fn get_supportable_anchor_channels(
let mut total_fractional_amount = Amount::from_sat(0);
let mut num_whole_utxos = 0;
for utxo in utxos {
- let spend_fee = context
- .upper_bound_fee_rate
- .fee_wu(Weight::from_wu(BASE_INPUT_WEIGHT + utxo.satisfaction_weight))
+ let spend_fee = BASE_INPUT_WEIGHT
+ .checked_add(utxo.satisfaction_weight)
+ .and_then(|input_weight| {
+ context.upper_bound_fee_rate.fee_wu(Weight::from_wu(input_weight))
+ })
.unwrap_or(Amount::MAX);
let amount = utxo.output.value.checked_sub(spend_fee).unwrap_or(Amount::MIN);
if amount >= reserve_per_channel {Why this scored 58/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.