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

Fix `Borrow`/`Hash` inconsistency on `Payment*` types

Public commit record

What the developer wrote

Authored by Matt Corallo

85/100 · Strong
Fix `Borrow`/`Hash` inconsistency on `Payment*` types

`Borrow`'d values are required to `Hash` identically to the
original object so that a `Borrow`ed key can be used in place of an
owned one in a `HashMap` lookup.

We'd violated this on our `Payment*` types, which we fix here. Note
that changing the `Hash` implementation is generally not considered
an API-breaking change and this seems like a useful fix.

Reported by Project Loupe.
✓ 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 Rust programming contract violation in several Lightning payment identifier types. In Rust, if a type can be 'borrowed' as a byte slice and used as a HashMap key, the borrowed form and the owned form must produce the same hash value. The old code used the type's automatic derived hash (which hashed the whole struct, including wrapper metadata) while borrowing only the inner byte array, so a borrowed key and an owned key could hash differently. That breaks HashMap lookups: you might store a value under one key and then be unable to find it with a borrowed version of the same key. The patch replaces the derived Hash implementation with one that hashes only the borrowed byte slice, restoring consistency. The commit message notes the issue was reported by Project Loupe.

Recommended action

Review all HashMap/HashSet uses keyed by PaymentHash, PaymentPreimage, PaymentSecret, PaymentId, InterceptId, or ChannelId to confirm the fix resolves observed lookup issues. No immediate exploit mitigation is required, but verify that no persisted hash-based state (e.g., serialized maps) relied on the old hash values, since hashes now change. Consider adding regression tests that insert with an owned key and look up with a borrowed key.

Security signals we found

01

Borrow/Hash contract violation in Rust standard collection key types

02

Potential HashMap lookup failure for payment/channel identifiers

03

Manual Hash implementation now delegates to borrowed byte slice

04

Reported by external party (Project Loupe)

Risk score

Why this scored 63/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 10/15
Affected reach 12/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.