Commit message · Vincenzo Palazzocommon: 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>
96/100 · StrongMessage clarity
✓ 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
Why it was queuedsigning boundary
AI analysis · Moderate 60/100This 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.