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

Reject serializing blinded paths with more than 255 hops

Public commit record

What the developer wrote

Authored by auto-pr-bot

100/100 · Strong
Reject serializing blinded paths with more than 255 hops

`BlindedPath::write` narrowed the hop count from `usize` to `u8` without
checking it was representable, so a path with 256 or more hops was
serialized as a wrapped `num_hops` byte followed by every hop body. In
BOLT12 fields that concatenate `...*blinded_path` values without
per-path framing, the trailing hop bodies remain inside the signed TLV
value and may be interpreted as additional paths or make the signed
offer/invoice unparsable.

We don't return an error here because it cannot propagate through TLV
encoding: `_encode_tlv!` computes each field's `serialized_length` up
front via an infallible writer, so a `BlindedPath` with too many hops
would panic there rather than surface the error. Instead we
debug-assert the invariant and, in release builds, cap the write at 255
hops so the trailing bodies are dropped rather than corrupting the
enclosing TLV value.

@val asked:

> @auto-pr-bot please open a PR that addresses this issue. No need for a
> test, just `try_into` when converting the blinded hops length to a u8
> on the write side.

and, on the erroring approach:

> @auto-pr-bot the review bot is right. Instead, we should
> `debug_assert` that we're not writing more than `u8::MAX` hops here,
> and only write up to 255 hops.

Fixes #5152

Requested-by: @val
Link: https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/issues/5152
Authored-By: ggml-org/GLM-5.3-Flash-GGUF:Q4_K <goose@users.noreply.local>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a serialization bug in the way secret routing paths (blinded paths) are written to data messages. Previously, if a path had 256 or more hops, the hop count was silently truncated to fit in a single byte, causing the remaining hop data to spill into the next part of the message. That could corrupt offers/invoices or make them unparseable. The fix caps the written hops at 255 and adds a debug-only assertion to catch the condition during development.

Recommended action

Review whether capping at 255 hops silently is acceptable for all callers, or whether construction of oversized blinded paths should be prevented earlier. Consider adding a release-mode check or returning a serialization error if the writer API is later made fallible. No immediate user action is required beyond updating to the patched version.

Security signals we found

01

Integer narrowing/truncation bug (usize -> u8) in serialization

02

Potential TLV payload corruption in BOLT12 offers/invoices

03

Signed message parsing failure or misinterpretation of trailing hop bytes

04

Fix caps output rather than returning an error due to infallible writer constraints

05

Debug assertion added to catch oversized paths in development builds

Risk score

Why this scored 58/100

Our methodology →
Potential impact 18/30
Exploitability 10/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.