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

fn: fix Result[T].FlatMap

Public commit record

What the developer wrote

Authored by Gijs van Dam

86/100 · Strong
fn: fix Result[T].FlatMap

For a Result[T], FlatMap should apply f when the result is Ok, and
propagate the error unchanged when it's Err. The original code returns r
on Ok and tries to use r.left when Err, which is wrong. This commit
fixes that.

Secondly, the group of FlatMap/AndThen and OrElse functions and methods
are now properly tested with new unit tests.

fixes #10401
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a logic bug in a small helper function called FlatMap used inside the LND codebase. FlatMap is supposed to transform a successful value and pass through failures unchanged. The old code did the opposite: it left successes alone and tried to transform failures, which could cause errors to be silently mishandled or successful values to be lost. The commit also adds unit tests to prevent the bug from returning.

Recommended action

Review all call sites of FlatMap, AndThen, and FlatMapResult in the LND codebase to determine whether the inverted behavior caused incorrect state transitions, skipped validations, or mishandled errors. Run the new unit tests and consider backporting the fix to active release branches.

Security signals we found

01

Logic inversion in error-handling primitive

02

Potential for error values to be passed where success values are expected

03

Potential for successful results to bypass intended validation/transformation

04

Fix is accompanied by new unit tests

Risk score

Why this scored 36/100

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