common/test: reproduce BOLT 12 PR #1295 marker-jump spec contradiction
What changed, and why it matters
This commit adds a new test file that deliberately fails to prove there is a contradiction in the BOLT 12 specification. The spec's writer rules say a certain list of omitted fields must jump from 239 to 1,000,000,000, but the reader rules reject that exact jump. Core Lightning's code follows the reader rule literally, so it would reject a message that another implementation following the writer rule would produce. The commit itself does not fix the bug; it only reproduces it and is expected to fail until the specification is updated.
Treat this as a specification/implementation mismatch rather than an immediate exploitable vulnerability. Monitor lightning/bolts#1295 for the spec fix, then update common/bolt12_proof.c's check_payer_proof() to mirror the amended reader rule allowing the 239 -> 1000000000 jump. Re-run the new test to confirm it passes. Do not merge this commit alone if CI enforces passing tests, because the commit is intentionally a failing reproduction.
Security signals we found
Protocol-level spec contradiction between writer and reader rules
Implementation follows a reader rule that rejects spec-compliant encodings
Potential interoperability failure with other BOLT12 implementations
Failing regression test added to document the contradiction
Evidence from the diff
The commit introduces common/test/run-bolt12_proof_marker_jump.c, a C unit test that exercises check_payer_proof() in common/bolt12_proof.c. It builds a tlv_payer_proof whose proof_omitted_tlvs array is [1,2,…,239,1000000000]. Under the BOLT 12 offer-encoding writer rule (lines 1041-1049), the 240th omitted marker must jump to 1000000000 because TLV types 240..999999999 are the signature/payer-proof range and are skipped. However, the reader rule (lines 1065-1067) only accepts omitted entries that are prev+1 or
Changed components
common/bolt12_proof.ccommon/test/run-bolt12_proof_marker_jump.ccommon/test/MakefileBOLT 12 offer-encoding specification (12-offer-encoding.md)Inspect captured patch +132 / −1
### common/test/Makefile
@@ -124,7 +124,7 @@ common/test/run-bolt12_merkle-json: \
common/base32.o \
common/wireaddr.o
-common/test/run-bolt12_proof common/test/run-bolt12_proof_vectors: \
+common/test/run-bolt12_proof common/test/run-bolt12_proof_vectors common/test/run-bolt12_proof_marker_jump: \
common/bolt12.o \
common/bigsize.o \
common/amount.o \
### common/test/run-bolt12_proof_marker_jump.c
@@ -0,0 +1,131 @@
+/* Reproduce BOLT 12 spec contradiction PR #1295 in CLN's reader.
+ *
+ * Spec discussion:
+ * https://github.com/lightning/bolts/pull/1295#discussion_r3286972971
+ *
+ * In `lightning/bolts#1295` (head db3eff3a54, file 12-offer-encoding.md):
+ *
+ * - Writer rule (lines 1041-1049) mandates that the marker number after a
+ * `proof_omitted_tlvs` entry of 239 is 1000000000 — i.e. the writer skips
+ * past the signature/payer-proof range (TLV types 240..999999999).
+ * - Reader rule (lines 1065-1067) only accepts the next entry if it is
+ * `prev + 1` or `<included TLV> + 1`. 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 is a literal transcription of the bogus reader rule; see
+ * `check_payer_proof` in common/bolt12_proof.c lines 339-388 (specifically the
+ * `omitted != prev_omitted + 1` branch at line 379). Feeding it the
+ * writer-rule-mandated sequence `[1, 2, …, 239, 1000000000]` produces an error
+ * naming `1000000000` as "not one greater than the previous 239 nor an
+ * included tlv entry" — that's the contradiction.
+ *
+ * This test deliberately FAILS until reader rule 1065 is amended to allow the
+ * 239 → 1000000000 jump. The failure IS the reproduction.
+ *
+ * Parallel LDK reproduction lives in lightningdevkit/rust-lightning#4297, test
+ * `spec_writer_reader_rules_contradict_on_gap_jump` in
+ * lightning/src/offers/merkle.rs (commit 0034c79ae).
+ */
+#include "config.h"
+#include <stdio.h>
+#include "../bolt12_proof.c"
+#include "../bolt12_merkle.c"
+#include "../bech32_util.c"
+#include "../bech32.c"
+#include "../json_parse.c"
+#include "../json_parse_simple.c"
+#include <ccan/ptrint/ptrint.h>
+#include <common/features.h>
+#include <common/setup.h>
+#include <secp256k1_schnorrsig.h>
+
+/* AUTOGENERATED MOCKS START */
+/* Generated stub for features_unsupported */
+int features_unsupported(const struct feature_set *our_features UNNEEDED,
+ const u8 *their_features UNNEEDED,
+ enum feature_place p UNNEEDED)
+{ fprintf(stderr, "features_unsupported called!\n"); abort(); }
+/* Generated stub for mvt_tag_parse */
+bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED)
+{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); }
+/* Generated stub for node_id_from_hexstr */
+bool node_id_from_hexstr(const char *str UNNEEDED, size_t slen UNNEEDED, struct node_id *id UNNEEDED)
+{ fprintf(stderr, "node_id_from_hexstr called!\n"); abort(); }
+/* Generated stub for pubkey_from_node_id */
+bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
+{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
+/* Generated stub for siphash_seed */
+const struct siphash_seed *siphash_seed(void)
+{ fprintf(stderr, "siphash_seed called!\n"); abort(); }
+/* AUTOGENERATED MOCKS END */
+
+/* AAAA... BBBB... etc */
+static struct pubkey *pubkey_for_letter(const tal_t *ctx, char letter)
+{
+ struct secret secret;
+ struct pubkey *pk;
+
+ pk = tal(ctx, struct pubkey);
+ memset(&secret, letter, sizeof(secret));
+ assert(pubkey_from_secret(&secret, pk));
+ return pk;
+}
+
+int main(int argc, char *argv[])
+{
+ struct tlv_payer_proof *pptlv;
+ struct preimage preimage;
+ bigsize_t *omitted;
+ const char *err;
+
+ common_setup(argv[0]);
+
+ /* Construct just enough of a payer_proof for `check_payer_proof` to
+ * reach the proof_omitted_tlvs validation loop (lines 339-388 of
+ * common/bolt12_proof.c). All eight required-field pointers must be
+ * non-NULL, and sha256(proof_preimage) must equal invoice_payment_hash.
+ * We deliberately leave pptlv->fields as the empty array from
+ * tlv_payer_proof_new, so `find_tlv_num` always returns false and we
+ * isolate the gap-jump bug from the "is included field" check.
+ */
+ pptlv = tlv_payer_proof_new(tmpctx);
+
+ pptlv->invreq_payer_id = pubkey_for_letter(pptlv, 'A');
+ pptlv->invoice_node_id = pubkey_for_letter(pptlv, 'B');
+
+ memset(&preimage, 0x1, sizeof(preimage));
+ pptlv->proof_preimage = tal_dup(pptlv, struct preimage, &preimage);
+ pptlv->invoice_payment_hash = tal(pptlv, struct sha256);
+ sha256(pptlv->invoice_payment_hash, &preimage, sizeof(preimage));
+
+ /* Stub signatures: bytes are irrelevant since the marker-loop check
+ * runs before any signature verification. */
+ pptlv->signature = talz(pptlv, struct bip340sig);
+ pptlv->proof_signature = talz(pptlv, struct bip340sig);
+ pptlv->proof_missing_hashes = tal_arr(pptlv, struct sha256, 0);
+ pptlv->proof_leaf_hashes = tal_arr(pptlv, struct sha256, 0);
+
+ /* The marker sequence the spec writer rule mandates for 240 consecutive
+ * omitted non-signature TLVs:
+ * [1, 2, 3, …, 239, 1000000000]
+ * The 240th marker jumps to 1000000000 because TLV types 240..999999999
+ * are the signature/payer-proof range. */
+ omitted = tal_arr(pptlv, bigsize_t, 240);
+ for (size_t i = 0; i < 239; i++)
+ omitted[i] = i + 1;
+ omitted[239] = 1000000000;
+ pptlv->proof_omitted_tlvs = omitted;
+
+ err = check_payer_proof(tmpctx, pptlv);
+ if (err)
+ fprintf(stderr,
+ "check_payer_proof rejected the writer-rule-mandated"
+ " 239 → 1000000000 jump: %s\n", err);
+ assert(err == NULL);
+
+ common_shutdown();
+ return 0;
+}Why this scored 37/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.