AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 62 Bitcoin

common: saturate marginal_feerate() instead of overflowing

Public commit record

What the developer wrote

Authored by Matt Morehouse

85/100 · Strong
common: saturate marginal_feerate() instead of overflowing

marginal_feerate() computed current_feerate * 1.1 as a double and
converted the result back to u32. Since current_feerate is chosen by
the peer in open_channel or update_fee, they could choose an absurdly
high value that overflows u32 after the computation. UBSan reports:

common/fee_states.c:179:10: runtime error: 4.72446e+09 is outside the range of representable values of type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior common/fee_states.c:179:10

Do the arithmetic with u64 and saturate at UINT32_MAX to avoid the
undefined behavior.

Found by fuzzing with smite.

Changelog-Fixed: JSON-RPC: `listpeerchannels` no longer derives `receivable_msat` from an overflowed fee estimate when the peer sets an absurd `feerate_per_kw`.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit fixes a numeric overflow bug in Core Lightning's fee calculation. A peer could supply an extremely high transaction fee rate that, when increased by 10%, produced a value too large for the program's internal storage. That triggered undefined behavior (a C programming error) and could cause incorrect values, such as a distorted 'receivable_msat' shown by listpeerchannels. The fix performs the math in a larger integer type and caps the result at the maximum allowed value.

Recommended action

Apply the patch and ensure builds with UBSan/ASan continue to pass. Review other fee-rate arithmetic for similar double-to-integer conversions or missing saturation. The issue was found by fuzzing; consider extending fuzzing coverage for peer-controlled numeric inputs.

Security signals we found

01

UndefinedBehaviorSanitizer-reported double-to-u32 overflow

02

Peer-controlled input (feerate_per_kw) used in arithmetic without bounds checking

03

Downstream RPC value (listpeerchannels receivable_msat) derived from overflowed fee estimate

04

Fix uses widened u64 arithmetic and explicit saturation

Risk score

Why this scored 62/100

Our methodology →
Potential impact 18/30
Exploitability 14/25
Stealth signal 8/15
Affected reach 10/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.