Skip to content

BOLT 12: payer proofs - #1295

Closed
rustyrussell wants to merge 11 commits into
lightning:masterfrom
rustyrussell:guilt/payer-proofs
Closed

rustyrussell wants to merge 11 commits into
lightning:masterfrom
rustyrussell:guilt/payer-proofs

Conversation

@rustyrussell

@rustyrussell rustyrussell commented Nov 4, 2025 •

Copy link
Copy Markdown
Collaborator

Needs:

  • Implementation.
  • Test vectors
  • Review

@t-bast t-bast mentioned this pull request Nov 10, 2025
13 of 25 tasks

@jkczyz jkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments from a first pass. Should have more feedback once we attempt to implement this.

Comment thread 12-offer-encoding.md Resolved
Comment thread 12-offer-encoding.md Resolved
Comment thread 12-offer-encoding.md Resolved
Comment thread 12-offer-encoding.md Resolved
Comment thread 12-offer-encoding.md Resolved
Comment thread 12-offer-encoding.md Resolved
@t-bast t-bast mentioned this pull request Nov 19, 2025
8 of 24 tasks
@t-bast t-bast mentioned this pull request Jan 2, 2026
15 of 26 tasks
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jan 2, 2026
Implements the payer proof extension to BOLT 12 as specified in
lightning/bolts#1295. This allows proving
that a BOLT 12 invoice was paid by demonstrating possession of the
payment preimage, a valid invoice signature, and a payer signature.

Key additions:
- Extend merkle.rs with selective disclosure primitives for creating
  and reconstructing merkle trees with partial TLV disclosure
- Add payer_proof.rs with PayerProof, PayerProofBuilder, and
  UnsignedPayerProof types for building and verifying payer proofs
- Support bech32 encoding with "lnp" prefix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

@vincenzopalazzo vincenzopalazzo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this spec! I am finishing to implement it in ldk and have some feedback from implementation experience:

  1. The nonce hash notation needs clarification (see inline comment)
  2. Test vectors would be extremely valuable for cross-implementation compatibility. Wondering if you already had some draft implementation where we can compare the tests vectors?

Happy to provide my implementation's test vectors once the ambiguities are resolved.

Comment thread 12-offer-encoding.md Resolved
Comment thread 12-offer-encoding.md Resolved
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jan 4, 2026
Implements the payer proof extension to BOLT 12 as specified in
lightning/bolts#1295. This allows proving
that a BOLT 12 invoice was paid by demonstrating possession of the
payment preimage, a valid invoice signature, and a payer signature.

Key additions:
- Extend merkle.rs with selective disclosure primitives for creating
  and reconstructing merkle trees with partial TLV disclosure
- Add payer_proof.rs with PayerProof, PayerProofBuilder, and
  UnsignedPayerProof types for building and verifying payer proofs
- Support bech32 encoding with "lnp" prefix
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jan 4, 2026
Implements the payer proof extension to BOLT 12 as specified in
lightning/bolts#1295. This allows proving
that a BOLT 12 invoice was paid by demonstrating possession of the
payment preimage, a valid invoice signature, and a payer signature.

Key additions:
- Extend merkle.rs with selective disclosure primitives for creating
  and reconstructing merkle trees with partial TLV disclosure
- Add payer_proof.rs with PayerProof, PayerProofBuilder, and
  UnsignedPayerProof types for building and verifying payer proofs
- Support bech32 encoding with "lnp" prefix
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jan 4, 2026
Implements the payer proof extension to BOLT 12 as specified in
lightning/bolts#1295. This allows proving
that a BOLT 12 invoice was paid by demonstrating possession of the
payment preimage, a valid invoice signature, and a payer signature.

Key additions:
- Extend merkle.rs with selective disclosure primitives for creating
  and reconstructing merkle trees with partial TLV disclosure
- Add payer_proof.rs with PayerProof, PayerProofBuilder, and
  UnsignedPayerProof types for building and verifying payer proofs
- Support bech32 encoding with "lnp" prefix
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jan 5, 2026
Implements the payer proof extension to BOLT 12 as specified in
lightning/bolts#1295. This allows proving
that a BOLT 12 invoice was paid by demonstrating possession of the
payment preimage, a valid invoice signature, and a payer signature.

Key additions:
- Extend merkle.rs with selective disclosure primitives for creating
  and reconstructing merkle trees with partial TLV disclosure
- Add payer_proof.rs with PayerProof, PayerProofBuilder, and
  UnsignedPayerProof types for building and verifying payer proofs
- Support bech32 encoding with "lnp" prefix
Comment thread 12-offer-encoding.md Resolved
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jan 20, 2026
Implements the payer proof extension to BOLT 12 as specified in
lightning/bolts#1295. This allows proving
that a BOLT 12 invoice was paid by demonstrating possession of the
payment preimage, a valid invoice signature, and a payer signature.

Key additions:
- Extend merkle.rs with selective disclosure primitives for creating
  and reconstructing merkle trees with partial TLV disclosure
- Add payer_proof.rs with PayerProof, PayerProofBuilder, and
  UnsignedPayerProof types for building and verifying payer proofs
- Support bech32 encoding with "lnp" prefix
vincenzopalazzo added a commit to vincenzopalazzo/payer-proof-test-vectors that referenced this pull request Jan 20, 2026
Add a Rust CLI tool that generates and verifies test vectors for BOLT 12
payer proofs as specified in lightning/bolts#1295. The tool uses the
rust-lightning implementation from lightningdevkit/rust-lightning#4297.

Features:
- Generate deterministic test vectors with configurable seed
- Verify test vectors from JSON files
- Support for basic proofs, proofs with notes, and invalid test cases
- Uses refund flow for explicit payer key control

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@t-bast t-bast mentioned this pull request Jan 26, 2026
11 of 25 tasks
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Feb 22, 2026
Implements payer proofs for BOLT 12 invoices as specified in
lightning/bolts#1295.

A PayerProof cryptographically proves that a BOLT 12 invoice was paid
by demonstrating possession of the payment preimage, a valid invoice
signature over a merkle root (via selective disclosure), and a payer
signature proving who authorized the payment.

Key components:
- `PayerProofBuilder`: constructs proofs with selective disclosure,
  supporting both direct signing and derived key signing from
  `ExpandedKey` + `Nonce`
- `PayerProof`: verifiable proof with bech32 encoding (lnp HRP)
- Selective disclosure via merkle tree: omitted TLV fields are
  represented by minimized markers and missing hashes, allowing
  verification of the invoice signature without revealing all fields
- `compute_selective_disclosure` / `reconstruct_merkle_root`: build
  and verify merkle proofs using n-node in-place tree traversal
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Feb 22, 2026
Implements payer proofs for BOLT 12 invoices as specified in
lightning/bolts#1295. A payer proof
cryptographically demonstrates that a BOLT 12 invoice was paid
using selective disclosure of invoice fields, the payment preimage,
and signatures from both the invoice issuer and the payer.
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Feb 22, 2026
Implements payer proofs for BOLT 12 invoices as specified in
lightning/bolts#1295. A payer proof
cryptographically demonstrates that a BOLT 12 invoice was paid
using selective disclosure of invoice fields, the payment preimage,
and signatures from both the invoice issuer and the payer.
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Feb 24, 2026
Implement payer proofs for BOLT 12 invoices as specified in
lightning/bolts#1295. A payer proof
cryptographically demonstrates that a BOLT 12 invoice was paid
using selective disclosure of invoice fields, the payment preimage,
and signatures from both the invoice issuer and the payer.

The selective disclosure mechanism uses a merkle tree over the
invoice's TLV fields, allowing the payer to reveal only chosen
fields while proving the full invoice was signed by the issuer.
Privacy-preserving omitted markers hide the actual TLV type numbers
of undisclosed fields.

PayerProofBuilder provides two signing modes: an explicit signing
function for callers with direct key access, and automatic key
re-derivation from ExpandedKey + Nonce + PaymentId for the common
case where invoice requests used deriving_signing_pubkey.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Feb 24, 2026
Implement payer proofs for BOLT 12 invoices as specified in
lightning/bolts#1295. A payer proof
cryptographically demonstrates that a BOLT 12 invoice was paid
using selective disclosure of invoice fields, the payment preimage,
and signatures from both the invoice issuer and the payer.

The selective disclosure mechanism uses a merkle tree over the
invoice's TLV fields, allowing the payer to reveal only chosen
fields while proving the full invoice was signed by the issuer.
Privacy-preserving omitted markers hide the actual TLV type numbers
of undisclosed fields.

PayerProofBuilder provides two signing modes: an explicit signing
function for callers with direct key access, and automatic key
re-derivation from ExpandedKey + Nonce + PaymentId for the common
case where invoice requests used deriving_signing_pubkey.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Feb 24, 2026
Implement payer proofs for BOLT 12 invoices as specified in
lightning/bolts#1295. A payer proof
cryptographically demonstrates that a BOLT 12 invoice was paid
using selective disclosure of invoice fields, the payment preimage,
and signatures from both the invoice issuer and the payer.

The selective disclosure mechanism uses a merkle tree over the
invoice's TLV fields, allowing the payer to reveal only chosen
fields while proving the full invoice was signed by the issuer.
Privacy-preserving omitted markers hide the actual TLV type numbers
of undisclosed fields.

PayerProofBuilder provides two signing modes: an explicit signing
function for callers with direct key access, and automatic key
re-derivation from ExpandedKey + Nonce + PaymentId for the common
case where invoice requests used deriving_signing_pubkey.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@t-bast t-bast mentioned this pull request Feb 27, 2026
12 of 22 tasks
@vincenzopalazzo

vincenzopalazzo commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Mar 17, 2026
Implement payer proofs for BOLT 12 invoices as specified in
lightning/bolts#1295. A payer proof
cryptographically demonstrates that a BOLT 12 invoice was paid
using selective disclosure of invoice fields, the payment preimage,
and signatures from both the invoice issuer and the payer.

The selective disclosure mechanism uses a merkle tree over the
invoice's TLV fields, allowing the payer to reveal only chosen
fields while proving the full invoice was signed by the issuer.
Privacy-preserving omitted markers hide the actual TLV type numbers
of undisclosed fields.

PayerProofBuilder provides two signing modes: an explicit signing
function for callers with direct key access, and automatic key
re-derivation from ExpandedKey + Nonce + PaymentId for the common
case where invoice requests used deriving_signing_pubkey.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Mar 17, 2026
Implement payer proofs for BOLT 12 invoices as specified in
lightning/bolts#1295. A payer proof
cryptographically demonstrates that a BOLT 12 invoice was paid
using selective disclosure of invoice fields, the payment preimage,
and signatures from both the invoice issuer and the payer.

The selective disclosure mechanism uses a merkle tree over the
invoice's TLV fields, allowing the payer to reveal only chosen
fields while proving the full invoice was signed by the issuer.
Privacy-preserving omitted markers hide the actual TLV type numbers
of undisclosed fields.

PayerProofBuilder provides two signing modes: an explicit signing
function for callers with direct key access, and automatic key
re-derivation from ExpandedKey + Nonce + PaymentId for the common
case where invoice requests used deriving_signing_pubkey.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Mar 17, 2026
Implement payer proofs for BOLT 12 invoices as specified in
lightning/bolts#1295. A payer proof
cryptographically demonstrates that a BOLT 12 invoice was paid
using selective disclosure of invoice fields, the payment preimage,
and signatures from both the invoice issuer and the payer.

The selective disclosure mechanism uses a merkle tree over the
invoice's TLV fields, allowing the payer to reveal only chosen
fields while proving the full invoice was signed by the issuer.
Privacy-preserving omitted markers hide the actual TLV type numbers
of undisclosed fields.

PayerProofBuilder provides two signing modes: an explicit signing
function for callers with direct key access, and automatic key
re-derivation from ExpandedKey + Nonce + PaymentId for the common
case where invoice requests used deriving_signing_pubkey.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jun 18, 2026
Add the `payer_proof` module: `PayerProof`/`UnsignedPayerProof`, the
`PayerProofBuilder` (with selective disclosure and a derived-key path), bech32
`lnp` encoding, and parse-time verification, implementing the payer proof
extension to BOLT 12 (lightning/bolts#1295). Also
exposes the offer/invoice TLV-type constants and an invoice-bytes accessor used
to build proofs, and a `Sha256` `Writeable`/`Readable` impl for the proof hashes.

Co-Authored-By: Rusty Russell <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jun 18, 2026
Add the `payer_proof` module: `PayerProof`/`UnsignedPayerProof`, the
`PayerProofBuilder` (with selective disclosure and a derived-key path), bech32
`lnp` encoding, and parse-time verification, implementing the payer proof
extension to BOLT 12 (lightning/bolts#1295). Also
exposes the offer/invoice TLV-type constants and an invoice-bytes accessor used
to build proofs, and a `Sha256` `Writeable`/`Readable` impl for the proof hashes.

Co-Authored-By: Rusty Russell <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jun 18, 2026
Add the `payer_proof` module: `PayerProof`/`UnsignedPayerProof`, the
`PayerProofBuilder` (with selective disclosure and a derived-key path), bech32
`lnp` encoding, and parse-time verification, implementing the payer proof
extension to BOLT 12 (lightning/bolts#1295). Also
exposes the offer/invoice TLV-type constants and an invoice-bytes accessor used
to build proofs, and a `Sha256` `Writeable`/`Readable` impl for the proof hashes.

Co-Authored-By: Rusty Russell <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>
@vincenzopalazzo

Copy link
Copy Markdown
Contributor

I addressed the remaining reader-side proof_omitted_tlvs marker rule issue in this branch:

https://github.com/vincenzopalazzo/bolts/tree/codex/pr-1295

It adds the reader-side carve-out for the 239 -> 1000000000 marker jump, matching the existing writer rule.

vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jun 30, 2026
Add the `payer_proof` module: `PayerProof`/`UnsignedPayerProof`, the
`PayerProofBuilder` (with selective disclosure and a derived-key path), bech32
`lnp` encoding, and parse-time verification, implementing the payer proof
extension to BOLT 12 (lightning/bolts#1295). Also
exposes the offer/invoice TLV-type constants and an invoice-bytes accessor used
to build proofs, and a `Sha256` `Writeable`/`Readable` impl for the proof hashes.

Co-Authored-By: Rusty Russell <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jul 1, 2026
Add the `payer_proof` module: `PayerProof`/`UnsignedPayerProof`, the
`PayerProofBuilder` (with selective disclosure and a derived-key path), bech32
`lnp` encoding, and parse-time verification, implementing the payer proof
extension to BOLT 12 (lightning/bolts#1295). Also
exposes the offer/invoice TLV-type constants and an invoice-bytes accessor used
to build proofs, and a `Sha256` `Writeable`/`Readable` impl for the proof hashes.

Co-Authored-By: Rusty Russell <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jul 1, 2026
Add the `payer_proof` module: `PayerProof`/`UnsignedPayerProof`, the
`PayerProofBuilder` (with selective disclosure and a derived-key path), bech32
`lnp` encoding, and parse-time verification, implementing the payer proof
extension to BOLT 12 (lightning/bolts#1295). Also
exposes the offer/invoice TLV-type constants and an invoice-bytes accessor used
to build proofs, and a `Sha256` `Writeable`/`Readable` impl for the proof hashes.

Co-Authored-By: Rusty Russell <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>
@vincenzopalazzo

Copy link
Copy Markdown
Contributor

I opened a replacement PR to take this over from my fork, per Rusty’s handoff:

#1346

I’ll continue review/fixes there. Maintainers can close this PR when ready.

vincenzopalazzo added a commit to vincenzopalazzo/rust-lightning that referenced this pull request Jul 6, 2026
Add the `payer_proof` module: `PayerProof`/`UnsignedPayerProof`, the
`PayerProofBuilder` (with selective disclosure and a derived-key path), bech32
`lnp` encoding, and parse-time verification, implementing the payer proof
extension to BOLT 12 (lightning/bolts#1295). Also
exposes the offer/invoice TLV-type constants and an invoice-bytes accessor used
to build proofs, and a `Sha256` `Writeable`/`Readable` impl for the proof hashes.

Co-Authored-By: Rusty Russell <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>
@t-bast

t-bast commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Closing in favor of #1346. Thanks Rusty!

@t-bast t-bast closed this Jul 7, 2026
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Jul 10, 2026
Add the `payer_proof` module: `PayerProof`/`UnsignedPayerProof`, the
`PayerProofBuilder` (with selective disclosure and a derived-key path), bech32
`lnp` encoding, and parse-time verification, implementing the payer proof
extension to BOLT 12 (lightning/bolts#1295). Also
exposes the offer/invoice TLV-type constants and an invoice-bytes accessor used
to build proofs, and a `Sha256` `Writeable`/`Readable` impl for the proof hashes.

Co-Authored-By: Rusty Russell <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>

Backport of 5747866

Conflicts resolved in:
 * lightning/src/events/mod.rs
 * lightning/src/offers/payer_proof.rs
TheBlueMatt pushed a commit to TheBlueMatt/rust-lightning that referenced this pull request Jul 11, 2026
Add the `payer_proof` module: `PayerProof`/`UnsignedPayerProof`, the
`PayerProofBuilder` (with selective disclosure and a derived-key path), bech32
`lnp` encoding, and parse-time verification, implementing the payer proof
extension to BOLT 12 (lightning/bolts#1295). Also
exposes the offer/invoice TLV-type constants and an invoice-bytes accessor used
to build proofs, and a `Sha256` `Writeable`/`Readable` impl for the proof hashes.

Co-Authored-By: Rusty Russell <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>

Backport of 5747866

Conflicts resolved in:
 * lightning/src/offers/payer_proof.rs
t-bast added a commit to ACINQ/eclair that referenced this pull request Jul 29, 2026
vincenzopalazzo added a commit to vincenzopalazzo/lightning that referenced this pull request Aug 17, 2026
…ec contradiction

Add a failing C unit test that reproduces the BOLT 12 spec
contradiction raised on lightning/bolts#1295.

The writer rule in `12-offer-encoding.md` (lines 1041-1049, head
db3eff3a54) mandates that after a `proof_omitted_tlvs` entry of
`239` the next entry MUST be `1000000000`, because the writer skips
past the signature/payer-proof TLV range (240..999999999).

The reader rule (lines 1065-1067) only accepts an entry that is
`prev + 1` or `<included TLV> + 1`, with no carve-out for the
239 -> 1000000000 jump.

A reader applying the spec literally rejects a marker sequence the
writer rule mandates.

CLN's reader in common/bolt12_proof.c lines 339-388 is a literal
transcription of the bogus reader rule (specifically the
`omitted != prev_omitted + 1` branch at line 379).

Fed the writer-rule-mandated sequence [1, 2, ..., 239, 1000000000]
it returns an error on the 1000000000 entry.

The new test in common/test/run-bolt12_proof_marker_jump.c builds
the minimum tlv_payer_proof needed to reach the marker-validation
loop and asserts check_payer_proof returns NULL.

It is expected to fail on current master, the failure IS the
reproduction. The fix belongs in the spec PR first (amend reader
rule 1065) and only then mirrored into CLN.

The same contradiction is reproduced on the Rust-Lightning side in
lightningdevkit/rust-lightning#4297, test
spec_writer_reader_rules_contradict_on_gap_jump in
lightning/src/offers/merkle.rs (commit 0034c79ae).

Changelog-None

Link: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/lightning that referenced this pull request Aug 17, 2026
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:

  lightning/bolts#1295 (comment)

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:
  lightningdevkit/rust-lightning#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: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/lightning that referenced this pull request Aug 17, 2026
Add a new valid_vector `marker_jump_239_to_1000000000` to the JSON
output produced by `run-bolt12_proof_vectors`. The vector encodes a
real signed payer_proof whose `proof_omitted_tlvs` ends with
[..., 237, 238, 239, 1000000000], i.e. it actually contains the
spec gap-jump.

The point is cross-implementation coverage: with this vector in the
JSON corpus that CLN already emits, other BOLT 12 implementations
(LDK PR ElementsProject#4297, future eclair, ...) can consume the same bech32
string through their own decoder and verifier. A reader that still
has the old "must be prev + 1 or <included TLV> + 1" rule will
reject the proof with an error naming `1000000000` after `239`;
that surfaces the same latent bug across implementations rather
than having each project rediscover it independently.

The marker-jump invoice is built by `build_marker_jump_invoice`,
which is a minimal invoice (same keys A-F as the existing
vectors) plus 64 dummy unknown TLVs at odd extension-range types
(1000000001, 1000000003, ..., 1000000127). The new
`include_required_only` callback includes only the three required
fields (invreq_payer_id, invoice_payment_hash, invoice_node_id),
so the 64 trailing dummies and the optional invoice fields all
get omitted. The writer-side `next_marker` walks the marker
counter through 1..239 and then emits 1000000000 on the 64th
dummy, which is the case under test.

The existing 5 valid_vectors and 23 invalid_vectors are unchanged;
the new entry is appended at the end of `valid_vectors[]` so the
existing positions are preserved.

Link: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
t-bast added a commit to ACINQ/eclair that referenced this pull request Aug 27, 2026
vincenzopalazzo added a commit to vincenzopalazzo/lightning that referenced this pull request Sep 30, 2026
…ec contradiction

Add a failing C unit test that reproduces the BOLT 12 spec
contradiction raised on lightning/bolts#1295.

The writer rule in `12-offer-encoding.md` (lines 1041-1049, head
db3eff3a54) mandates that after a `proof_omitted_tlvs` entry of
`239` the next entry MUST be `1000000000`, because the writer skips
past the signature/payer-proof TLV range (240..999999999).

The reader rule (lines 1065-1067) only accepts an entry that is
`prev + 1` or `<included TLV> + 1`, with no carve-out for the
239 -> 1000000000 jump.

A reader applying the spec literally rejects a marker sequence the
writer rule mandates.

CLN's reader in common/bolt12_proof.c lines 339-388 is a literal
transcription of the bogus reader rule (specifically the
`omitted != prev_omitted + 1` branch at line 379).

Fed the writer-rule-mandated sequence [1, 2, ..., 239, 1000000000]
it returns an error on the 1000000000 entry.

The new test in common/test/run-bolt12_proof_marker_jump.c builds
the minimum tlv_payer_proof needed to reach the marker-validation
loop and asserts check_payer_proof returns NULL.

It is expected to fail on current master, the failure IS the
reproduction. The fix belongs in the spec PR first (amend reader
rule 1065) and only then mirrored into CLN.

The same contradiction is reproduced on the Rust-Lightning side in
lightningdevkit/rust-lightning#4297, test
spec_writer_reader_rules_contradict_on_gap_jump in
lightning/src/offers/merkle.rs (commit 0034c79ae).

Changelog-None

Link: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/lightning that referenced this pull request Sep 30, 2026
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:

  lightning/bolts#1295 (comment)

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:
  lightningdevkit/rust-lightning#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: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/lightning that referenced this pull request Sep 30, 2026
Add a new valid_vector `marker_jump_239_to_1000000000` to the JSON
output produced by `run-bolt12_proof_vectors`. The vector encodes a
real signed payer_proof whose `proof_omitted_tlvs` ends with
[..., 237, 238, 239, 1000000000], i.e. it actually contains the
spec gap-jump.

The point is cross-implementation coverage: with this vector in the
JSON corpus that CLN already emits, other BOLT 12 implementations
(LDK PR ElementsProject#4297, future eclair, ...) can consume the same bech32
string through their own decoder and verifier. A reader that still
has the old "must be prev + 1 or <included TLV> + 1" rule will
reject the proof with an error naming `1000000000` after `239`;
that surfaces the same latent bug across implementations rather
than having each project rediscover it independently.

The marker-jump invoice is built by `build_marker_jump_invoice`,
which is a minimal invoice (same keys A-F as the existing
vectors) plus 64 dummy unknown TLVs at odd extension-range types
(1000000001, 1000000003, ..., 1000000127). The new
`include_required_only` callback includes only the three required
fields (invreq_payer_id, invoice_payment_hash, invoice_node_id),
so the 64 trailing dummies and the optional invoice fields all
get omitted. The writer-side `next_marker` walks the marker
counter through 1..239 and then emits 1000000000 on the 64th
dummy, which is the case under test.

The existing 5 valid_vectors and 23 invalid_vectors are unchanged;
the new entry is appended at the end of `valid_vectors[]` so the
existing positions are preserved.

Link: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/lightning that referenced this pull request Sep 30, 2026
…ec contradiction

Add a failing C unit test that reproduces the BOLT 12 spec
contradiction raised on lightning/bolts#1295.

The writer rule in `12-offer-encoding.md` (lines 1041-1049, head
db3eff3a54) mandates that after a `proof_omitted_tlvs` entry of
`239` the next entry MUST be `1000000000`, because the writer skips
past the signature/payer-proof TLV range (240..999999999).

The reader rule (lines 1065-1067) only accepts an entry that is
`prev + 1` or `<included TLV> + 1`, with no carve-out for the
239 -> 1000000000 jump.

A reader applying the spec literally rejects a marker sequence the
writer rule mandates.

CLN's reader in common/bolt12_proof.c lines 339-388 is a literal
transcription of the bogus reader rule (specifically the
`omitted != prev_omitted + 1` branch at line 379).

Fed the writer-rule-mandated sequence [1, 2, ..., 239, 1000000000]
it returns an error on the 1000000000 entry.

The new test in common/test/run-bolt12_proof_marker_jump.c builds
the minimum tlv_payer_proof needed to reach the marker-validation
loop and asserts check_payer_proof returns NULL.

It is expected to fail on current master, the failure IS the
reproduction. The fix belongs in the spec PR first (amend reader
rule 1065) and only then mirrored into CLN.

The same contradiction is reproduced on the Rust-Lightning side in
lightningdevkit/rust-lightning#4297, test
spec_writer_reader_rules_contradict_on_gap_jump in
lightning/src/offers/merkle.rs (commit 0034c79ae).

Changelog-None

Link: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/lightning that referenced this pull request Sep 30, 2026
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:

  lightning/bolts#1295 (comment)

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:
  lightningdevkit/rust-lightning#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: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
vincenzopalazzo added a commit to vincenzopalazzo/lightning that referenced this pull request Sep 30, 2026
Add a new valid_vector `marker_jump_239_to_1000000000` to the JSON
output produced by `run-bolt12_proof_vectors`. The vector encodes a
real signed payer_proof whose `proof_omitted_tlvs` ends with
[..., 237, 238, 239, 1000000000], i.e. it actually contains the
spec gap-jump.

The point is cross-implementation coverage: with this vector in the
JSON corpus that CLN already emits, other BOLT 12 implementations
(LDK PR ElementsProject#4297, future eclair, ...) can consume the same bech32
string through their own decoder and verifier. A reader that still
has the old "must be prev + 1 or <included TLV> + 1" rule will
reject the proof with an error naming `1000000000` after `239`;
that surfaces the same latent bug across implementations rather
than having each project rediscover it independently.

The marker-jump invoice is built by `build_marker_jump_invoice`,
which is a minimal invoice (same keys A-F as the existing
vectors) plus 64 dummy unknown TLVs at odd extension-range types
(1000000001, 1000000003, ..., 1000000127). The new
`include_required_only` callback includes only the three required
fields (invreq_payer_id, invoice_payment_hash, invoice_node_id),
so the 64 trailing dummies and the optional invoice fields all
get omitted. The writer-side `next_marker` walks the marker
counter through 1..239 and then emits 1000000000 on the 64th
dummy, which is the case under test.

The existing 5 valid_vectors and 23 invalid_vectors are unchanged;
the new entry is appended at the end of `valid_vectors[]` so the
existing positions are preserved.

Link: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
daywalker90 pushed a commit to vincenzopalazzo/lightning that referenced this pull request Nov 3, 2026
…ec contradiction

Add a failing C unit test that reproduces the BOLT 12 spec
contradiction raised on lightning/bolts#1295.

The writer rule in `12-offer-encoding.md` (lines 1041-1049, head
db3eff3a54) mandates that after a `proof_omitted_tlvs` entry of
`239` the next entry MUST be `1000000000`, because the writer skips
past the signature/payer-proof TLV range (240..999999999).

The reader rule (lines 1065-1067) only accepts an entry that is
`prev + 1` or `<included TLV> + 1`, with no carve-out for the
239 -> 1000000000 jump.

A reader applying the spec literally rejects a marker sequence the
writer rule mandates.

CLN's reader in common/bolt12_proof.c lines 339-388 is a literal
transcription of the bogus reader rule (specifically the
`omitted != prev_omitted + 1` branch at line 379).

Fed the writer-rule-mandated sequence [1, 2, ..., 239, 1000000000]
it returns an error on the 1000000000 entry.

The new test in common/test/run-bolt12_proof_marker_jump.c builds
the minimum tlv_payer_proof needed to reach the marker-validation
loop and asserts check_payer_proof returns NULL.

It is expected to fail on current master, the failure IS the
reproduction. The fix belongs in the spec PR first (amend reader
rule 1065) and only then mirrored into CLN.

The same contradiction is reproduced on the Rust-Lightning side in
lightningdevkit/rust-lightning#4297, test
spec_writer_reader_rules_contradict_on_gap_jump in
lightning/src/offers/merkle.rs (commit 0034c79ae).

Changelog-None

Link: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
daywalker90 pushed a commit to vincenzopalazzo/lightning that referenced this pull request Nov 3, 2026
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:

  lightning/bolts#1295 (comment)

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:
  lightningdevkit/rust-lightning#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: lightning/bolts#1295 (comment)
Link: lightningdevkit/rust-lightning#4297
Signed-off-by: Vincenzo Palazzo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants