@mikeargento/bitgraph-verify 1.16.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +24 -3
  2. package/dist/__tests__/carrier2.test.js +1 -1
  3. package/dist/__tests__/carrier2.test.js.map +1 -1
  4. package/dist/carrier-assemble.d.ts +30 -2
  5. package/dist/carrier-assemble.d.ts.map +1 -1
  6. package/dist/carrier-assemble.js +27 -3
  7. package/dist/carrier-assemble.js.map +1 -1
  8. package/dist/carrier-verify.d.ts +12 -2
  9. package/dist/carrier-verify.d.ts.map +1 -1
  10. package/dist/carrier-verify.js +222 -58
  11. package/dist/carrier-verify.js.map +1 -1
  12. package/dist/carrier.d.ts +77 -12
  13. package/dist/carrier.d.ts.map +1 -1
  14. package/dist/carrier.js +146 -17
  15. package/dist/carrier.js.map +1 -1
  16. package/dist/ceiling.d.ts +82 -3
  17. package/dist/ceiling.d.ts.map +1 -1
  18. package/dist/ceiling.js +137 -20
  19. package/dist/ceiling.js.map +1 -1
  20. package/dist/export.d.ts +10 -0
  21. package/dist/export.d.ts.map +1 -1
  22. package/dist/export.js +89 -30
  23. package/dist/export.js.map +1 -1
  24. package/dist/fuse.d.ts +43 -11
  25. package/dist/fuse.d.ts.map +1 -1
  26. package/dist/fuse.js +85 -18
  27. package/dist/fuse.js.map +1 -1
  28. package/dist/index.d.ts +13 -3
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +10 -2
  31. package/dist/index.js.map +1 -1
  32. package/dist/measurements.d.ts.map +1 -1
  33. package/dist/measurements.js +1 -0
  34. package/dist/measurements.js.map +1 -1
  35. package/dist/tree.d.ts +15 -3
  36. package/dist/tree.d.ts.map +1 -1
  37. package/dist/tree.js +41 -12
  38. package/dist/tree.js.map +1 -1
  39. package/dist/types.d.ts +21 -0
  40. package/dist/types.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/__tests__/carrier2.test.ts +1 -1
  43. package/src/carrier-assemble.ts +47 -3
  44. package/src/carrier-verify.ts +227 -55
  45. package/src/carrier.ts +171 -26
  46. package/src/ceiling.ts +150 -24
  47. package/src/export.ts +94 -31
  48. package/src/fuse.ts +114 -23
  49. package/src/index.ts +24 -2
  50. package/src/measurements.ts +1 -0
  51. package/src/tree.ts +42 -10
  52. package/src/types.ts +22 -0
package/src/carrier.ts CHANGED
@@ -41,6 +41,37 @@
41
41
  * never reads as authority. A reader that knows only v1 reports an unknown
42
42
  * version (UNDETERMINED), never a verdict.
43
43
  *
44
+ * bitgraph-carrier/3 (2026-10-06, enclave v10) is /2 for a proof whose floor
45
+ * is a Base block (`commit.slotFloor`). The floor is that block's header
46
+ * itself, `{ status: "present", basis: "base-header", header }`, checked
47
+ * against the signed floor (hash, number and time, on Base mainnet's
48
+ * schedule); there is no anchor proof under it. There is no ceiling in
49
+ * POSITION either: anchors ended with the cutover, and the order among
50
+ * BitGraphs is the chain of proof hashes, so the block states
51
+ * `{ status: "none", basis: "hash-chain" }`, a fact, not a pending part.
52
+ * Everything else (ceiling in time, settlement, pins, attestation witness) is
53
+ * /2's. Ethereum-floor proofs keep travelling as /1 and /2.
54
+ *
55
+ * bitgraph-carrier/4 (2026-10-11) is the BitGraphed file of ONE MEMBER of a
56
+ * tree/1 BitGraph. In a tree the signed digest is the SHA-256 of the tree's
57
+ * 84-byte root document, not of any file, so the committed bytes before the
58
+ * block are a LEAF's committed bytes (the bytes whose SHA-256 is the leaf's
59
+ * artifact digest: the file itself for a leaf kept as is, the file with the
60
+ * commitment placed in it otherwise), and the block carries what reaches the
61
+ * signed digest from them, exactly the tree part a one-file export/1 carries:
62
+ * `tree: { rootDocument, member: { index, count, leaf, path } }`. A reader
63
+ * hashes the bytes before the block, requires that digest to be the leaf's
64
+ * artifact (and, for a placed leaf, the commitment to be inside the bytes),
65
+ * walks the path to the root, and requires the root document to hold that
66
+ * root and the position's commitment and to hash to the signed digest. The
67
+ * floor is the one the proof signs, in its own shape: an Ethereum anchor and
68
+ * header (as /2, with the ceiling in position unfetched or present) or a Base
69
+ * header (as /3, with no ceiling in position). Ceiling in time, settlement,
70
+ * pins and attestation witness are /2's. A new version and not a field added
71
+ * to /2 or /3, on purpose: a reader that knows only /1 to /3 would hash the
72
+ * bytes against the root document's digest and call a good file FALSE, so it
73
+ * must see a version it does not know and say UNDETERMINED instead.
74
+ *
44
75
  * ⚠️ TWO BYTE-IDENTICAL COPIES OF THIS FILE EXIST, on purpose:
45
76
  * packages/verify/src/carrier.ts (canonical, published with the package)
46
77
  * website/src/lib/carrier.ts (the site cannot import unpublished code)
@@ -63,7 +94,9 @@ export const MAX_CARRIER_PAYLOAD = 8 * 1024 * 1024;
63
94
 
64
95
  export const CARRIER_VERSION = "bitgraph-carrier/1";
65
96
  export const CARRIER_VERSION_2 = "bitgraph-carrier/2";
66
- export type CarrierVersion = typeof CARRIER_VERSION | typeof CARRIER_VERSION_2;
97
+ export const CARRIER_VERSION_3 = "bitgraph-carrier/3";
98
+ export const CARRIER_VERSION_4 = "bitgraph-carrier/4";
99
+ export type CarrierVersion = typeof CARRIER_VERSION | typeof CARRIER_VERSION_2 | typeof CARRIER_VERSION_3 | typeof CARRIER_VERSION_4;
67
100
  /** The sidecar and pointer formats a v2 block carries; their shapes are checked by their own modules. */
68
101
  export const CEILING_SIDECAR_VERSION = "bitgraph-ceiling/1";
69
102
  export const SETTLEMENT_POINTER_VERSION = "bitgraph-settlement/1";
@@ -83,12 +116,24 @@ export type CarrierProof = Record<string, unknown>;
83
116
 
84
117
  export interface CarrierFloor {
85
118
  status: "present";
119
+ basis?: never;
86
120
  /** The anchor proof named by the carried proof's signed `commit.slotAnchor`. */
87
121
  anchor: CarrierProof;
88
122
  witness: CarrierWitness;
89
123
  }
90
124
 
125
+ /** v3: the Base block the carried proof signs as `commit.slotFloor`, as its raw header (0x hex RLP). No anchor proof stands under it. */
126
+ export interface CarrierBaseFloor {
127
+ status: "present";
128
+ basis: "base-header";
129
+ header: string;
130
+ anchor?: never;
131
+ witness?: never;
132
+ }
133
+
91
134
  export type CarrierCeiling =
135
+ /** v3: no ceiling in position exists; order among BitGraphs is the chain of proof hashes. */
136
+ | { status: "none"; basis: "hash-chain" }
92
137
  | {
93
138
  status: "unfetched";
94
139
  /** Set when a completion looked and nothing had landed yet, so "never looked" and "not yet" read apart. */
@@ -112,6 +157,19 @@ export type CarrierSettlement =
112
157
  | { status: "unfetched" }
113
158
  | { status: "present"; pointer: Record<string, unknown> };
114
159
 
160
+ /**
161
+ * v4: the tree member the committed bytes are, in export/1's words: the
162
+ * tree's root document and the member's evidence, both lowercase hex. Bound
163
+ * to nothing until a verifier walks it: the leaf must be the bytes, the path
164
+ * must reach the root, the root document must hash to the signed digest.
165
+ */
166
+ export interface CarrierTree {
167
+ /** The 84-byte root document (168 hex characters); its SHA-256 is the proof's artifact digest. */
168
+ rootDocument: string;
169
+ /** The member's evidence, exactly export/1's `tree.member`: the 65-byte leaf, its index, the tree's size and the sibling path from the leaf up. */
170
+ member: { index: number; count: number; leaf: string; path: string[] };
171
+ }
172
+
115
173
  /** v2: what the file was made under. Declared only; a verifier compares with its own pins. */
116
174
  export interface CarrierPins {
117
175
  pcr0?: string;
@@ -124,16 +182,19 @@ export interface CarrierPayload {
124
182
  carrier: CarrierVersion;
125
183
  /** The bitgraph/1 proof exactly as the commit returned it. */
126
184
  proof: CarrierProof;
127
- floor: CarrierFloor;
128
- /** The ceiling in position: the next anchor in the chain. Every proof ever made has one. */
185
+ /** v4, required there: the tree member the committed bytes are. */
186
+ tree?: CarrierTree;
187
+ /** v1 and v2: the Ethereum anchor proof and its header. v3: the Base header. v4: whichever the proof signs. */
188
+ floor: CarrierFloor | CarrierBaseFloor;
189
+ /** The ceiling in position: the next anchor in the chain (v1, v2, v4 on an Ethereum floor), or on a Base floor the statement that there is none. */
129
190
  ceiling: CarrierCeiling;
130
- /** v2 only. Required on a v2 block, so absence reads as a corrupt block, never as "no ceiling". */
191
+ /** v2, v3 and v4. Required there, so absence reads as a corrupt block, never as "no ceiling". */
131
192
  ceilingInTime?: CarrierCeilingInTime;
132
- /** v2 only, optional. */
193
+ /** v2, v3 and v4, optional. */
133
194
  settlement?: CarrierSettlement;
134
- /** v2 only, optional. */
195
+ /** v2, v3 and v4, optional. */
135
196
  pins?: CarrierPins;
136
- /** v2 only, optional: the proof's attestation as aws-nitro-witness/1 evidence. */
197
+ /** v2, v3 and v4, optional: the proof's attestation as aws-nitro-witness/1 evidence. */
137
198
  attestation?: Record<string, unknown>;
138
199
  }
139
200
 
@@ -227,23 +288,55 @@ export function buildCarrier(inner: Uint8Array, payload: CarrierPayload): Uint8A
227
288
  return out;
228
289
  }
229
290
 
291
+ /** v4: the tree part's shape (export/1's one-file tree), lowercase hex throughout. Whether it holds is verifyCarrier's question. */
292
+ function treeShapeError(t: unknown): string | null {
293
+ const o = record(t);
294
+ if (o === null) return `a ${CARRIER_VERSION_4} block carries its tree member: "tree" is missing`;
295
+ if (Object.keys(o).sort().join(",") !== "member,rootDocument") return "tree must hold exactly rootDocument and member";
296
+ if (typeof o["rootDocument"] !== "string" || !/^[0-9a-f]{168}$/.test(o["rootDocument"])) return "tree.rootDocument is not 84 bytes of lowercase hex";
297
+ const m = record(o["member"]);
298
+ if (m === null || Object.keys(m).sort().join(",") !== "count,index,leaf,path") return "tree.member must hold exactly index, count, leaf and path";
299
+ const { index, count } = m;
300
+ if (typeof count !== "number" || !Number.isInteger(count) || count < 1) return "tree.member.count is not a whole number of leaves";
301
+ if (typeof index !== "number" || !Number.isInteger(index) || index < 0 || index >= count) return "tree.member.index is not a leaf of the tree";
302
+ if (typeof m["leaf"] !== "string" || !/^[0-9a-f]{130}$/.test(m["leaf"])) return "tree.member.leaf is not 65 bytes of lowercase hex";
303
+ if (!Array.isArray(m["path"]) || !(m["path"] as unknown[]).every((n) => typeof n === "string" && /^[0-9a-f]{64}$/.test(n))) return "tree.member.path is not a list of 32-byte lowercase-hex nodes";
304
+ return null;
305
+ }
306
+
230
307
  /** Structural payload check: is this object a readable bitgraph-carrier/1 payload? */
231
308
  function payloadShapeError(p: unknown): string | null {
232
309
  const o = record(p);
233
310
  if (o === null) return "payload is not an object";
234
- const v2 = o["carrier"] === CARRIER_VERSION_2;
311
+ const v4 = o["carrier"] === CARRIER_VERSION_4;
312
+ const v3 = o["carrier"] === CARRIER_VERSION_3;
313
+ const v2 = o["carrier"] === CARRIER_VERSION_2 || v3 || v4;
235
314
  if (o["carrier"] !== CARRIER_VERSION && !v2) return `unknown carrier version ${JSON.stringify(o["carrier"])}`;
236
315
  if (record(o["proof"]) === null) return "payload carries no proof object";
316
+ if (v4) {
317
+ const te = treeShapeError(o["tree"]);
318
+ if (te !== null) return te;
319
+ }
237
320
  const floor = record(o["floor"]);
238
321
  if (floor === null || floor["status"] !== "present") return "floor must be present: a floorless carrier is not a not-before";
239
- if (record(floor["anchor"]) === null) return "floor carries no anchor proof";
240
- const fw = record(floor["witness"]);
241
- if (fw === null || typeof fw["headerRlpHex"] !== "string" || typeof fw["blockNumber"] !== "number" || typeof fw["blockHash"] !== "string") {
242
- return "floor carries no readable block-header witness";
243
- }
244
322
  const ceil = record(o["ceiling"]);
245
323
  if (ceil === null) return "ceiling is missing: absence must be a stated fact, not a missing key";
246
- if (ceil["status"] !== "unfetched") {
324
+ // v3, and v4 over a Base floor: the floor is a Base header, and no ceiling in position exists.
325
+ const baseFloor = v3 || (v4 && floor["basis"] === "base-header");
326
+ if (baseFloor) {
327
+ if (floor["basis"] !== "base-header") return `a ${CARRIER_VERSION_3} floor must be a Base header (basis "base-header"), got ${JSON.stringify(floor["basis"])}`;
328
+ if (typeof floor["header"] !== "string" || baseHeaderFields(floor["header"]) === null) return "floor carries no readable Base block header";
329
+ if (floor["anchor"] !== undefined || floor["witness"] !== undefined) return `a ${String(o["carrier"])} ${v4 ? "Base " : ""}floor carries no anchor proof`;
330
+ if (ceil["status"] !== "none" || ceil["basis"] !== "hash-chain") return `a ${String(o["carrier"])} block ${v4 ? "over a Base floor " : ""}states no ceiling in position ({ status: "none", basis: "hash-chain" })`;
331
+ } else {
332
+ if (floor["basis"] !== undefined) return `unknown floor basis ${JSON.stringify(floor["basis"])} on ${String(o["carrier"])}`;
333
+ if (record(floor["anchor"]) === null) return "floor carries no anchor proof";
334
+ const fw = record(floor["witness"]);
335
+ if (fw === null || typeof fw["headerRlpHex"] !== "string" || typeof fw["blockNumber"] !== "number" || typeof fw["blockHash"] !== "string") {
336
+ return "floor carries no readable block-header witness";
337
+ }
338
+ }
339
+ if (!baseFloor && ceil["status"] !== "unfetched") {
247
340
  if (ceil["status"] !== "present") return `ceiling status must be "unfetched" or "present", got ${JSON.stringify(ceil["status"])}`;
248
341
  if (ceil["basis"] !== "counter-order") return `unknown ceiling basis ${JSON.stringify(ceil["basis"])}`;
249
342
  if (record(ceil["anchor"]) === null) return "ceiling carries no anchor proof";
@@ -253,7 +346,7 @@ function payloadShapeError(p: unknown): string | null {
253
346
  }
254
347
  }
255
348
  if (!v2) return null;
256
- // v2: the ceiling in time is stated either way; settlement, pins and the attestation witness are optional.
349
+ // v2, v3 and v4: the ceiling in time is stated either way; settlement, pins and the attestation witness are optional.
257
350
  const ct = record(o["ceilingInTime"]);
258
351
  if (ct === null) return "ceilingInTime is missing: a v2 block states the ceiling in time or that it was not fetched";
259
352
  if (ct["status"] === "present") {
@@ -276,9 +369,9 @@ function payloadShapeError(p: unknown): string | null {
276
369
  return null;
277
370
  }
278
371
 
279
- /** 1 or 2, from a parsed payload. */
280
- export function carrierVersionOf(payload: CarrierPayload): 1 | 2 {
281
- return payload.carrier === CARRIER_VERSION_2 ? 2 : 1;
372
+ /** 1, 2, 3 or 4, from a parsed payload. */
373
+ export function carrierVersionOf(payload: CarrierPayload): 1 | 2 | 3 | 4 {
374
+ return payload.carrier === CARRIER_VERSION_4 ? 4 : payload.carrier === CARRIER_VERSION_3 ? 3 : payload.carrier === CARRIER_VERSION_2 ? 2 : 1;
282
375
  }
283
376
 
284
377
  export function parseCarrier(bytes: Uint8Array): CarrierParse {
@@ -315,6 +408,7 @@ export function completeCarrier(
315
408
  const p = parseCarrier(bytes);
316
409
  if (p.kind !== "carrier") return { changed: false, bytes, error: p.kind === "none" ? "not a carrier" : `corrupt block: ${p.reason}` };
317
410
  const cur = p.payload.ceiling;
411
+ if (cur.status === "none") return { changed: false, bytes, error: `${p.payload.carrier === CARRIER_VERSION_3 ? `a ${CARRIER_VERSION_3} block` : "a block over a Base floor"} has no ceiling in position: its order is the chain of proof hashes` };
318
412
  if (cur.status === "present") {
319
413
  if (ceiling === null) return { changed: false, bytes };
320
414
  const a = record(record(cur.anchor)?.["commit"]);
@@ -346,7 +440,7 @@ export function completeCarrierInTime(
346
440
  ): { changed: boolean; bytes: Uint8Array; error?: string } {
347
441
  const p = parseCarrier(bytes);
348
442
  if (p.kind !== "carrier") return { changed: false, bytes, error: p.kind === "none" ? "not a carrier" : `corrupt block: ${p.reason}` };
349
- if (carrierVersionOf(p.payload) !== 2) return { changed: false, bytes, error: "a bitgraph-carrier/1 block has no ceiling in time; rebuild the file as carrier/2" };
443
+ if (carrierVersionOf(p.payload) === 1) return { changed: false, bytes, error: "a bitgraph-carrier/1 block has no ceiling in time; rebuild the file as carrier/2" };
350
444
  const cur = p.payload.ceilingInTime;
351
445
  if (cur && cur.status === "present") {
352
446
  if (sidecar === null) return { changed: false, bytes };
@@ -380,7 +474,7 @@ export function completeCarrierSettlement(
380
474
  ): { changed: boolean; bytes: Uint8Array; error?: string } {
381
475
  const p = parseCarrier(bytes);
382
476
  if (p.kind !== "carrier") return { changed: false, bytes, error: p.kind === "none" ? "not a carrier" : `corrupt block: ${p.reason}` };
383
- if (carrierVersionOf(p.payload) !== 2) return { changed: false, bytes, error: "a bitgraph-carrier/1 block has no settlement; rebuild the file as carrier/2" };
477
+ if (carrierVersionOf(p.payload) === 1) return { changed: false, bytes, error: "a bitgraph-carrier/1 block has no settlement; rebuild the file as carrier/2" };
384
478
  const cur = p.payload.settlement;
385
479
  if (cur && cur.status === "present") {
386
480
  const a = record(cur.pointer["l1"]), b = record(pointer["l1"]);
@@ -583,11 +677,33 @@ export function verifyWitnessHeader(w: CarrierWitness): WitnessCheck {
583
677
  return { ok: true, error: null, timestamp: rlpNumber(items[11]!) };
584
678
  }
585
679
 
680
+ /**
681
+ * v3: the block a Base header names, read from its bytes: keccak-256 is its
682
+ * hash, items 8 and 11 its number and time. Null when it is not a readable
683
+ * header. Says nothing about whether it is the signed floor: verifyCarrier
684
+ * checks that against the proof.
685
+ */
686
+ export function baseHeaderFields(headerHex: string): { blockNumber: number; blockHash: string; timestamp: number } | null {
687
+ const raw = typeof headerHex === "string" ? hexToBytes(headerHex) : null;
688
+ if (raw === null || raw.length === 0) return null;
689
+ const items = decodeRlpTop(raw);
690
+ if (items === null || items.length < 12) return null;
691
+ const blockNumber = rlpNumber(items[8]!), timestamp = rlpNumber(items[11]!);
692
+ if (blockNumber === null || timestamp === null) return null;
693
+ const blockHash = "0x" + Array.from(keccak_256(raw), (b) => b.toString(16).padStart(2, "0")).join("");
694
+ return { blockNumber, blockHash, timestamp };
695
+ }
696
+
586
697
  /* ── The window a reader states ─────────────────────────────────────────── */
587
698
 
588
699
  export interface CarrierBounds {
589
- notBefore: { blockNumber: number; blockHash: string; timestamp: number | null };
590
- /** The ceiling in POSITION: the next anchor. null means NOT FETCHED — say so in those words — never "none exists". */
700
+ /** The floor, on its chain: Ethereum (v1, v2) or Base (v3). */
701
+ notBefore: { chain: "ethereum" | "base"; blockNumber: number; blockHash: string; timestamp: number | null };
702
+ /**
703
+ * The ceiling in POSITION: the next anchor. On v1 and v2, null means NOT
704
+ * FETCHED (say so in those words), never "none exists". On v3 it is always
705
+ * null because none exists: order is the chain of proof hashes.
706
+ */
591
707
  notAfter: { blockNumber: number; blockHash: string; timestamp: number | null } | null;
592
708
  /**
593
709
  * v2: the ceiling in TIME. From carrierBounds, as the sidecar states it;
@@ -601,9 +717,17 @@ export interface CarrierBounds {
601
717
  }
602
718
 
603
719
  export function carrierBounds(payload: CarrierPayload): CarrierBounds {
604
- const f = payload.floor.witness;
605
- const floorTs = verifyWitnessHeader(f);
606
- const notBefore = { blockNumber: f.blockNumber, blockHash: f.blockHash.toLowerCase(), timestamp: floorTs.ok ? floorTs.timestamp : null };
720
+ let notBefore: CarrierBounds["notBefore"];
721
+ if (payload.floor.basis === "base-header") {
722
+ const h = baseHeaderFields(payload.floor.header);
723
+ notBefore = h === null
724
+ ? { chain: "base", blockNumber: 0, blockHash: "", timestamp: null }
725
+ : { chain: "base", blockNumber: h.blockNumber, blockHash: h.blockHash, timestamp: h.timestamp };
726
+ } else {
727
+ const f = payload.floor.witness;
728
+ const floorTs = verifyWitnessHeader(f);
729
+ notBefore = { chain: "ethereum", blockNumber: f.blockNumber, blockHash: f.blockHash.toLowerCase(), timestamp: floorTs.ok ? floorTs.timestamp : null };
730
+ }
607
731
  let notAfter: CarrierBounds["notAfter"] = null;
608
732
  if (payload.ceiling.status === "present") {
609
733
  const c = payload.ceiling.witness;
@@ -629,8 +753,29 @@ export function carrierBounds(payload: CarrierPayload): CarrierBounds {
629
753
  return { notBefore, notAfter, existedBy, settledBy };
630
754
  }
631
755
 
632
- /** SHA-256 of the committed bytes, compared to the carried proof's artifact digest. */
756
+ /**
757
+ * v4: the leaf's artifact digest, the SHA-256 the committed bytes must have,
758
+ * read from the carried leaf (bytes 1 to 33 of its 65). Null when the block
759
+ * carries no readable leaf. That the leaf is in the signed tree is
760
+ * verifyCarrier's check, not this one.
761
+ */
762
+ export function memberArtifactDigest(payload: CarrierPayload): Uint8Array | null {
763
+ const leaf = payload.tree?.member?.leaf;
764
+ const raw = typeof leaf === "string" && /^[0-9a-f]{130}$/.test(leaf) ? hexToBytes(leaf) : null;
765
+ return raw === null ? null : raw.slice(1, 33);
766
+ }
767
+
768
+ /**
769
+ * SHA-256 of the committed bytes, compared to the carried proof's artifact
770
+ * digest; on v4, to the carried leaf's artifact digest (a tree's signed digest
771
+ * names its root document, which no file is). A digest match only: the
772
+ * verifier does the rest.
773
+ */
633
774
  export function innerDigestMatches(inner: Uint8Array, payload: CarrierPayload): boolean {
775
+ if (payload.carrier === CARRIER_VERSION_4) {
776
+ const want = memberArtifactDigest(payload);
777
+ return want !== null && sameDigest(bytesToB64(sha256(inner)), bytesToB64(want));
778
+ }
634
779
  const artifact = record(payload.proof["artifact"]);
635
780
  return sameDigest(bytesToB64(sha256(inner)), artifact?.["digestB64"] as string);
636
781
  }
package/src/ceiling.ts CHANGED
@@ -3,9 +3,13 @@
3
3
  /**
4
4
  * A ceiling in TIME for a BitGraph, carried beside the proof, never inside it.
5
5
  *
6
- * Every BitGraph already has a floor in time (the Ethereum block the enclave
7
- * fixes at slot allocation and signs at commit, `commit.slotAnchor`) and a ceiling in POSITION (the
8
- * anchors that follow it in the chain). This adds the one thing a record
6
+ * Every BitGraph already has a floor in time: the block the enclave fixes at
7
+ * slot allocation and signs at commit, an Ethereum anchor (`commit.slotAnchor`,
8
+ * enclave v7 to v9) or a Base block (`commit.slotFloor`, enclave v10; read both
9
+ * through signedFloorOf). An Ethereum-floor BitGraph also has a ceiling in
10
+ * POSITION (the anchors that follow it in the chain); after the cutover to Base
11
+ * floors there are no anchors, and order among BitGraphs is the chain of proof
12
+ * hashes. This adds the one thing a record
9
13
  * cannot supply for itself: something outside the operator's control that
10
14
  * depends on the record. After a commit, a writer puts a Merkle root over
11
15
  * record hashes into a Base transaction. The block that includes it proves
@@ -30,9 +34,10 @@ import { sha256 } from "@noble/hashes/sha256";
30
34
  import { verifyProofIntegrity, createVerificationContext } from "./verifier.js";
31
35
  import { computeProofHash } from "./proof-hash.js";
32
36
  import { merkleLeafHash, merkleRootFromPath } from "./fuse-merkle.js";
33
- import { base64ToBytes } from "./fuse.js";
37
+ import { base64ToBytes, signedFloorOf, type SignedFloor } from "./fuse.js";
34
38
  import {
35
- bytesEqual, bytesToHex, decodeEip1559, decodeHeader, hexToBytes, keccak256, mptVerify, txTrieKey,
39
+ bytesEqual, bytesToHex, decodeEip1559, decodeHeader, hexToBytes, keccak256, mptVerify, rlpEncode, txTrieKey,
40
+ type DecodedHeader,
36
41
  } from "./ceiling-evm.js";
37
42
  import type { BitGraphProof, VerificationPolicy } from "./types.js";
38
43
 
@@ -70,9 +75,12 @@ export interface CeilingSidecar {
70
75
  statusObserved: { included: string | null; safe: string | null; finalized: string | null };
71
76
  /**
72
77
  * The floor block's header, so the window reads offline. Optional and
73
- * unsigned: checked by keccak256 against the proof's SIGNED slotAnchor hash.
78
+ * unsigned: checked by keccak256 against the floor the proof SIGNS
79
+ * (signedFloorOf). `chain` names the floor's chain: absent is Ethereum (every
80
+ * sidecar before enclave v10), "base" a Base floor, whose header's time must
81
+ * also equal the signed blockTimestamp.
74
82
  */
75
- floor?: { blockNumber: number; blockHash: string; blockTimestamp: number; blockHeader: string } | null;
83
+ floor?: { blockNumber: number; blockHash: string; blockTimestamp: number; blockHeader: string; chain?: "ethereum" | "base" } | null;
76
84
  /** Reserved for v2: the Ethereum batch that settles this Base block. */
77
85
  settlement: null;
78
86
  }
@@ -138,8 +146,8 @@ export interface CeilingVerifyResult {
138
146
  checks: CeilingCheck[];
139
147
  status?: CeilingStatus;
140
148
  window?: {
141
- /** Floor: the proof's signed slotAnchor block. Time only if a checked header was carried. */
142
- floor: { blockNumber: number; blockHash: string; blockTimestamp: number | null };
149
+ /** Floor: the block the proof signs (signedFloorOf), on its chain. Time only if a checked header was carried. */
150
+ floor: { chain: "ethereum" | "base" | null; blockNumber: number; blockHash: string; blockTimestamp: number | null };
143
151
  /** Ceiling: the Base block, time read from its header. */
144
152
  ceiling: { chainId: number; blockNumber: number; blockHash: string; blockTimestamp: number };
145
153
  widthSeconds: number | null;
@@ -298,29 +306,38 @@ async function verifyCeilingChecks(
298
306
  if (!inBlock || !bytesEqual(inBlock, rawTx)) return fail("inclusion", "the transaction is not in this block");
299
307
  pass("inclusion", `transaction ${a.txIndex} of block ${header.number}`);
300
308
 
301
- // 5. The window. The floor is the proof's own signed slotAnchor.
302
- const slotAnchor = proof.commit.slotAnchor;
303
- let floor: { blockNumber: number; blockHash: string; blockTimestamp: number | null } | null = null;
304
- if (slotAnchor) {
305
- floor = { blockNumber: slotAnchor.blockNumber, blockHash: slotAnchor.blockHash, blockTimestamp: null };
309
+ // 5. The window. The floor is the block the proof itself signs, on its own chain.
310
+ let signed: SignedFloor | null;
311
+ try {
312
+ signed = signedFloorOf(proof);
313
+ } catch (e) {
314
+ return fail("floor", (e as Error).message);
315
+ }
316
+ let floor: { chain: "ethereum" | "base"; blockNumber: number; blockHash: string; blockTimestamp: number | null } | null = null;
317
+ if (signed) {
318
+ floor = { chain: signed.chain, blockNumber: signed.blockNumber, blockHash: signed.blockHash, blockTimestamp: null };
306
319
  const w = sidecar.floor;
307
320
  if (w !== null && w !== undefined) {
308
321
  if (typeof w !== "object" || typeof w.blockHeader !== "string" || w.blockHeader.length === 0) {
309
322
  return fail("floor", "the sidecar carries a floor without a header (absence is null; a present floor carries its header)");
310
323
  }
324
+ let raw: Uint8Array;
311
325
  try {
312
- const fh = decodeHeader(hexToBytes(w.blockHeader));
313
- if (fh.hash === slotAnchor.blockHash.toLowerCase() && fh.number === slotAnchor.blockNumber) {
314
- floor.blockTimestamp = fh.timestamp;
315
- pass("floor", `Ethereum block ${fh.number}, header checked against the signed hash`);
316
- } else {
317
- // Every part a sidecar carries must hold: a copy of the floor that
318
- // is not the signed floor block fails the sidecar, it is not skipped.
319
- return fail("floor", "the carried floor header does not match the proof's signed slotAnchor");
320
- }
326
+ raw = hexToBytes(w.blockHeader);
321
327
  } catch {
322
328
  return fail("floor", "the carried floor header does not decode");
323
329
  }
330
+ // Every part a sidecar carries must hold: a copy of the floor that is
331
+ // not the signed floor block fails the sidecar, it is not skipped.
332
+ const fh = checkFloorHeader(signed, raw, w.chain);
333
+ if (!fh.ok) {
334
+ if (fh.reason.startsWith("the header does not decode")) return fail("floor", "the carried floor header does not decode");
335
+ const field = signed.chain === "base" ? "slotFloor" : "slotAnchor";
336
+ const said = signed.chain === "ethereum" && w.chain === undefined ? "" : `: ${fh.reason}`;
337
+ return fail("floor", `the carried floor header does not match the proof's signed ${field}${said}`);
338
+ }
339
+ floor.blockTimestamp = fh.header.timestamp;
340
+ pass("floor", `${chainName(signed.chain)} block ${fh.header.number}, header checked against the signed hash`);
324
341
  }
325
342
  }
326
343
  const width = floor?.blockTimestamp != null ? header.timestamp - floor.blockTimestamp : null;
@@ -330,7 +347,7 @@ async function verifyCeilingChecks(
330
347
  checks,
331
348
  status,
332
349
  window: {
333
- floor: floor ?? { blockNumber: 0, blockHash: "", blockTimestamp: null },
350
+ floor: floor ?? { chain: null, blockNumber: 0, blockHash: "", blockTimestamp: null },
334
351
  ceiling: { chainId: a.chainId, blockNumber: header.number, blockHash: header.hash, blockTimestamp: header.timestamp },
335
352
  widthSeconds: width,
336
353
  },
@@ -364,6 +381,115 @@ export async function checkCeilingOnline(
364
381
 
365
382
  export { keccak256 as ceilingKeccak256 };
366
383
 
384
+ // ── The floor block's header ───────────────────────────────────────────────
385
+
386
+ /**
387
+ * Base mainnet stamps every block by its height: block n is
388
+ * BASE_MAINNET_GENESIS_TIME + BASE_BLOCK_TIME_SECONDS * n (OP Stack, checked
389
+ * against the live chain 2026-10-06). The enclave (v10) refuses a floor header
390
+ * off this schedule; a verifier refuses one too, since such a header is not a
391
+ * Base mainnet block (another chain, a testnet, or made up).
392
+ */
393
+ export const BASE_MAINNET_GENESIS_TIME = 1686789347;
394
+ export const BASE_BLOCK_TIME_SECONDS = 2;
395
+
396
+ /** True when a block's stamp is Base mainnet's schedule for its number. */
397
+ export function onBaseSchedule(blockNumber: number, timestampSec: number): boolean {
398
+ return timestampSec === BASE_MAINNET_GENESIS_TIME + BASE_BLOCK_TIME_SECONDS * blockNumber;
399
+ }
400
+
401
+ const chainName = (c: "ethereum" | "base") => (c === "base" ? "Base" : "Ethereum");
402
+
403
+ /**
404
+ * Check a floor header against the floor the proof signs (signedFloorOf). The
405
+ * header must decode, hash (keccak-256) to the signed block hash and carry the
406
+ * signed number. For a Base floor its time must also equal the signed
407
+ * blockTimestamp and be Base mainnet's schedule for its number. When the
408
+ * carrier of the header names a chain (`declaredChain`, absent = Ethereum), it
409
+ * must be the signed floor's chain: a Base floor read as an Ethereum header,
410
+ * or the reverse, fails here even before any hash is compared.
411
+ */
412
+ export function checkFloorHeader(
413
+ signed: SignedFloor,
414
+ headerRlp: Uint8Array,
415
+ declaredChain?: unknown,
416
+ ): { ok: true; header: DecodedHeader } | { ok: false; reason: string } {
417
+ const declared = declaredChain === undefined || declaredChain === null ? "ethereum" : declaredChain;
418
+ if (declared !== "ethereum" && declared !== "base") return { ok: false, reason: `the header names an unknown chain (${JSON.stringify(declaredChain)})` };
419
+ const aBlock = (c: "ethereum" | "base") => (c === "base" ? "a Base block" : "an Ethereum block");
420
+ if (declared !== signed.chain) return { ok: false, reason: `the header is given as ${aBlock(declared)}, and the proof signs ${aBlock(signed.chain)}` };
421
+ let h: DecodedHeader;
422
+ try {
423
+ h = decodeHeader(headerRlp);
424
+ } catch (e) {
425
+ return { ok: false, reason: `the header does not decode (${(e as Error).message})` };
426
+ }
427
+ if (h.hash !== signed.blockHash.toLowerCase()) return { ok: false, reason: `the header does not hash to the signed ${chainName(signed.chain)} block hash` };
428
+ if (h.number !== signed.blockNumber) return { ok: false, reason: `the header is block ${h.number}, the proof signs block ${signed.blockNumber}` };
429
+ if (signed.chain === "base") {
430
+ if (h.timestamp !== signed.blockTimestamp) return { ok: false, reason: `the header's time is ${h.timestamp}, the proof signs ${signed.blockTimestamp}` };
431
+ if (!onBaseSchedule(h.number, h.timestamp)) return { ok: false, reason: `Base block ${h.number} is stamped ${h.timestamp}, off Base mainnet's schedule (${BASE_MAINNET_GENESIS_TIME + BASE_BLOCK_TIME_SECONDS * h.number})` };
432
+ }
433
+ return { ok: true, header: h };
434
+ }
435
+
436
+ /**
437
+ * Whether the floor block's time may be stated as a bound (review, 2026-10-06):
438
+ * the floor block must be no later than the commit's attestation document,
439
+ * the time AWS's hardware signed. A floor stamped after it cannot be a "not
440
+ * before" for a record that already existed; the block hash still floors the
441
+ * record (it did not exist before its block), but its time is withheld.
442
+ * Holds for either chain.
443
+ */
444
+ export function floorTimeIsBound(floorTimestampSec: number, attestedAtMs: number | null | undefined): { ok: true } | { ok: false; reason: string } {
445
+ if (attestedAtMs != null && floorTimestampSec * 1000 > attestedAtMs) {
446
+ return { ok: false, reason: `the floor block is stamped ${isoSec(floorTimestampSec)}, after the attestation document was made (${isoMs(attestedAtMs)})` };
447
+ }
448
+ return { ok: true };
449
+ }
450
+
451
+ /** A block as an EVM node's JSON-RPC returns it (eth_getBlockByNumber), the header fields only. */
452
+ export interface RpcBlockHeader {
453
+ hash: string; parentHash: string; sha3Uncles: string; miner: string; stateRoot: string;
454
+ transactionsRoot: string; receiptsRoot: string; logsBloom: string;
455
+ difficulty: string; number: string; gasLimit: string; gasUsed: string;
456
+ timestamp: string; extraData: string; mixHash: string; nonce: string;
457
+ baseFeePerGas?: string; withdrawalsRoot?: string; blobGasUsed?: string;
458
+ excessBlobGas?: string; parentBeaconBlockRoot?: string; requestsHash?: string;
459
+ }
460
+
461
+ /**
462
+ * The header's RLP, rebuilt from a node's JSON in canonical field order
463
+ * (through Prague; Base headers have the same shape), or null when it does not
464
+ * reproduce `expectedHash`. Null is the honest answer for a field this encoder
465
+ * does not know: nothing unchecked is ever returned.
466
+ */
467
+ export function headerRlpFromRpc(b: RpcBlockHeader | null | undefined, expectedHash: string): Uint8Array | null {
468
+ if (!b || typeof b !== "object") return null;
469
+ try {
470
+ const q = (x: string | undefined) => {
471
+ const h = String(x ?? "0x").replace(/^0x/i, "").replace(/^0+/, "");
472
+ return h === "" ? new Uint8Array(0) : hexToBytes(h.length % 2 ? `0${h}` : h);
473
+ };
474
+ const d = (x: string | undefined) => hexToBytes(String(x ?? "0x"));
475
+ const fields: Uint8Array[] = [
476
+ d(b.parentHash), d(b.sha3Uncles), d(b.miner), d(b.stateRoot), d(b.transactionsRoot),
477
+ d(b.receiptsRoot), d(b.logsBloom), q(b.difficulty), q(b.number), q(b.gasLimit),
478
+ q(b.gasUsed), q(b.timestamp), d(b.extraData), d(b.mixHash), d(b.nonce),
479
+ ];
480
+ if (b.baseFeePerGas != null) fields.push(q(b.baseFeePerGas));
481
+ if (b.withdrawalsRoot != null) fields.push(d(b.withdrawalsRoot));
482
+ if (b.blobGasUsed != null) fields.push(q(b.blobGasUsed));
483
+ if (b.excessBlobGas != null) fields.push(q(b.excessBlobGas));
484
+ if (b.parentBeaconBlockRoot != null) fields.push(d(b.parentBeaconBlockRoot));
485
+ if (b.requestsHash != null) fields.push(d(b.requestsHash));
486
+ const rlp = rlpEncode(fields);
487
+ return bytesToHex(keccak256(rlp)) === expectedHash.toLowerCase() ? rlp : null;
488
+ } catch {
489
+ return null;
490
+ }
491
+ }
492
+
367
493
  // ── The Base stamp as a time bound ─────────────────────────────────────────
368
494
 
369
495
  const isoSec = (unix: number) => new Date(unix * 1000).toISOString().replace(".000Z", "Z");