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

Serialize experimental TLV records in unsigned invoices

Public commit record

What the developer wrote

Authored by auto-pr-bot

96/100 · Strong
Serialize experimental TLV records in unsigned invoices

The `Writeable` implementation for `UnsignedBolt12Invoice` emitted only
`bytes`, omitting `experimental_bytes`, even though construction and
parsing include that buffer in `tagged_hash` and `sign` appends it to
the signed invoice. Experimental records inherited from the payer's
signed invoice request, including unknown odd TLV records, were
therefore missing from the byte representation exposed before signing.

@jkczyz asked in issue #5192:

> @auto-pr-bot please open a PR to fix this issue

> `UnsignedBolt12Invoice` deliberately separates experimental records
> into `experimental_bytes`: construction and parsing include that
> buffer in `tagged_hash`, and `sign` appends it to the final signed
> invoice. However, its public `Writeable` implementation emits only
> `self.bytes`. Experimental records inherited from the payer's signed
> invoice request (including unknown odd TLVs) are therefore omitted
> from the byte representation exposed before signing even though they
> are authenticated by the signature and present in the resulting
> `Bolt12Invoice`.
>
> This breaks the documented policy-signing boundary:
> `NodeSigner::sign_bolt12_invoice` implementations are allowed to
> inspect the `UnsignedBolt12Invoice` and reject unexpected content
> before releasing the node key signature. A remote/HSM adapter or
> policy signer that serializes the public `Writeable` value to parse
> or reject extensions sees an incomplete object.
>
> The serialization should write `self.bytes` followed by
> `self.experimental_bytes`, without adding a length prefix, matching
> the exact unsigned TLV stream later signed.

[...]

The regression test inherits the repository's test-only experimental
invoice request field through `respond_with_no_std` and checks that
serialization exposes every TLV record committed by `tagged_hash` and
round-trips to the same hash.

Fixes #5192

Requested-by: @jkczyz
Link: https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/issues/5192
Authored-By: matt/GLM-5.3-Flash-GGUF:Q4_K_XL <goose@users.noreply.local>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes a bug in how an unsigned BOLT 12 invoice was serialized before being signed. The public serialization accidentally dropped experimental/custom data fields that were inherited from the payer's invoice request. Because those fields are still included in the cryptographic hash that gets signed, a signer that inspected only the public serialized bytes would see an incomplete picture and could not reliably enforce policies against unknown extensions. The fix makes the public serialization include both the standard bytes and the experimental bytes, matching what is actually signed.

Recommended action

Treat this as a security-relevant correctness fix and include it in the next maintenance release. Node operators and integrators using custom signers or HSM adapters for BOLT 12 invoices should upgrade so that policy checks operate on the complete authenticated invoice bytes. Review any signer code that serializes `UnsignedBolt12Invoice` to confirm it now receives the full TLV stream.

Security signals we found

01

Policy-signing boundary bypass risk: signer sees incomplete byte representation of authenticated data

02

Experimental/unknown odd TLV records silently omitted from public serialization

03

Mismatch between serialized view and tagged_hash/signature input

04

HSM or remote policy signer could fail to reject extensions it cannot see

05

Fix is narrowly scoped to one Writeable impl with regression test

Risk score

Why this scored 60/100

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