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

common: fix BOLT 12 payer_proof marker-jump via next_marker helper

Public commit record

What the developer wrote

Authored by Vincenzo Palazzo

96/100 · Strong
common: fix BOLT 12 payer_proof marker-jump via next_marker helper

In `lightning/bolts#1295` (head db3eff3a54, 12-offer-encoding.md), the
writer rule (lines 1041-1049) mandates that after a
`proof_omitted_tlvs` entry of `239` the next entry is `1000000000`
(jumping past the signature/payer-proof TLV range 240..999999999),
but the reader rule (lines 1065-1067) only accepts `prev + 1` or
`<included TLV> + 1`. A reader applying the spec literally rejects
a marker sequence the writer rule mandates. The contradiction was
raised on the spec PR:

https://github.com/lightning/bolts/pull/1295#discussion_r3286972971

CLN's reader at `common/bolt12_proof.c` line 379 was a literal
transcription of the bogus reader rule, and CLN's writer at line
115 used `++last_type` which would have emitted `240` (invalid)
after `239` if a real invoice ever reached the boundary.

Fix this by collapsing both writer and reader onto a single helper
`next_marker(prev)` that returns the smallest valid marker number
strictly greater than `prev`. Both sides now reference the same
symbol, so the writer/reader asymmetry that caused this bug is
structurally impossible.

The unit test `run-bolt12_proof_marker_jump` is rewritten as a real
end-to-end test: it builds an invoice with the standard required
fields plus 64 dummy unknown TLVs at odd extension-range types
(1000000001, 1000000003, ..., 1000000127), makes a payer_proof
including only the three required fields, and asserts that
`check_payer_proof` returns NULL. The marker sequence produced ends
with [..., 237, 238, 239, 1000000000], exercising the gap-jump
end-to-end. The test also sanity-checks that 239 appears in the
sequence and that 1000000000 follows it immediately, so the test
cannot go green for the wrong reason.

Existing `run-bolt12_proof` and `run-bolt12_proof_vectors` still
pass with no changes to their behaviour.

Parallel LDK reproduction:
https://github.com/lightningdevkit/rust-lightning/pull/4297
(test `spec_writer_reader_rules_contradict_on_gap_jump` in
lightning/src/offers/merkle.rs, commit 0034c79ae).

Changelog-Fixed: Reader of BOLT 12 payer_proof now accepts the writer-rule-mandated 239 -> 1000000000 marker jump.

Link: https://github.com/lightning/bolts/pull/1295#discussion_r3286972971
Link: https://github.com/lightningdevkit/rust-lightning/pull/4297
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
✓ 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 mismatch in Core Lightning's BOLT 12 invoice proof code. The BOLT 12 specification had contradictory writer and reader rules: writers were required to jump from marker 239 to marker 1000000000, but readers were written to only accept consecutive numbers. As a result, a valid invoice proof created by the rules could be rejected by the same implementation's checker. The fix introduces a single shared helper function so both sides agree on what number comes next, and updates the test to verify the jump is accepted end-to-end.

Recommended action

Review and merge the fix, then ensure the updated test passes. Consider backporting to maintained release branches because the bug can cause valid BOLT 12 invoices to be rejected. No immediate emergency response is indicated because exploitation requires a compliant but boundary-triggering invoice, and the fix is straightforward.

Security signals we found

01

Protocol implementation bug: writer and reader disagree on valid marker sequence

02

Potential denial of service: valid BOLT 12 payer proofs could be rejected by CLN

03

Spec contradiction fix: aligns CLN with the writer-mandated 239 -> 1000000000 jump

04

Single shared helper introduced to prevent future writer/reader divergence

05

End-to-end test added to lock in the boundary behavior

Risk score

Why this scored 60/100

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