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

Make FundingContribution::net_value() infallible

Public commit record

What the developer wrote

Authored by Jeffrey Czyz

58/100 · Thin
Make FundingContribution::net_value() infallible

Split FundingContribution::net_value() (which returned
Result<SignedAmount, String>) into a separate validate() method and an
infallible net_value() that returns SignedAmount directly. The validate()
method checks prevtx sizes and input sufficiency, while net_value()
computes the net contribution amount.

To make net_value() safe to call without error handling, add MAX_MONEY
bounds checks in the build_funding_contribution! macro before coin
selection. This ensures FundingContribution is valid by construction:
value_added and the sum of outputs are each bounded by MAX_MONEY
(~2.1e15 sat), so the worst-case net_value() computation (-2 * MAX_MONEY
~= -4.2e15) is well within i64 range (~-9.2e18).

Update callers in channel.rs to use the new separate methods, simplifying
error handling at call sites where net_value() previously required
unwrapping a Result.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✓ Descriptive subject✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit refactors how a Bitcoin Lightning channel funding calculation reports its results. Previously, a single method could either return a number or fail with an error. Now validation and the actual number calculation are split apart, and the code adds upfront checks to ensure the numbers involved can never be large enough to cause an arithmetic overflow. It is a defensive hardening change rather than a fix for a known active exploit.

Recommended action

Review as normal defensive refactoring. No urgent action required; ensure tests pass and that downstream callers always invoke validate() before relying on net_value().

Security signals we found

01

Adds MAX_MONEY bounds checks before coin selection to prevent signed-amount overflow in net_value() arithmetic

02

Replaces fallible net_value() with infallible net_value() plus separate validate()

03

Replaces unwrap/match error handling on net_value() with direct use after validation

04

Adds unit tests verifying rejection of value_added and output sums exceeding MAX_MONEY

Risk score

Why this scored 34/100

Our methodology →
Potential impact 8/30
Exploitability 5/25
Stealth signal 4/15
Affected reach 6/15
Confidence 7/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.