@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
@@ -1,21 +1,29 @@
1
1
  // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
 
3
3
  /**
4
- * verifyCarrier — the offline read path for a BitGraphed file (bitgraph-carrier/1
5
- * or /2), one result per claim, each saying what it rests on.
4
+ * verifyCarrier: the offline read path for a BitGraphed file (bitgraph-carrier/1,
5
+ * /2, /3 or /4), one result per claim, each saying what it rests on.
6
6
  *
7
7
  * Given the file and nothing else, it strips the block by structure and checks:
8
8
  *
9
- * the bytes SHA-256 of the committed bytes is the digest the proof names
9
+ * the bytes SHA-256 of the committed bytes is the digest the proof names; on v4
10
+ * (one member of a tree/1 BitGraph) it is the leaf's artifact digest, a
11
+ * placed leaf's bytes carry the commitment, the path reaches the root, and
12
+ * the root document carries that root and the position's commitment and
13
+ * hashes to the signed digest (verifyTreeMember), under a spec it knows
10
14
  * the proof Ed25519 signature, the position record and its bindings, the
11
- * fused commitment rebuilt (bitgraph-fuse/1 or /2), proofHash
15
+ * fused commitment rebuilt (bitgraph-fuse/1, /2 or /3), proofHash
12
16
  * the attestation ES384 signature, the certificate chain to the AWS Nitro root
13
17
  * (641A0321…), validity at the document's own instant, PCR0 against
14
18
  * the proof's measurement, user_data against the signed body; and,
15
19
  * on a v2 block, the openssl-checkable witness against the document
16
- * the floor the anchor proof named by the signed slotAnchor, verified over its
17
- * own message, matched by identity; its Ethereum header recomputed
18
- * the ceilings in position: the next anchor, same checks; in time (v2): the Base
20
+ * the floor v1, v2: the anchor proof named by the signed slotAnchor, verified over
21
+ * its own message, matched by identity; its Ethereum header recomputed.
22
+ * v3: the Base header, checked against the signed slotFloor (hash,
23
+ * number, time, Base mainnet's schedule). Either way the floor's time
24
+ * is a bound only when no later than the attestation document.
25
+ * the ceilings in position (v1, v2): the next anchor, same checks; v3 has none, its
26
+ * order is the chain of proof hashes; in time (v2, v3): the Base
19
27
  * sidecar's whole chain of custody (verifyCeiling); settled (v2): the
20
28
  * Ethereum block that committed the batch data (verifySettlementPointer)
21
29
  * the pins what the file declares it was made under, against the verifier's own
@@ -37,17 +45,19 @@
37
45
 
38
46
  import { verify, verifyProofIntegrity, createVerificationContext } from "./verifier.js";
39
47
  import { verifyFuse } from "./fuse-verify.js";
40
- import { readFuseAttribution } from "./fuse.js";
48
+ import { readFuseAttribution, signedFloorOf, hexToBytes as treeHex, type SignedFloor } from "./fuse.js";
49
+ import { verifyTreeMember, TREE_MEMBER_CATEGORIES, type TreeVerifyResult } from "./tree.js";
41
50
  import { computeProofHash, computeSignedBodyHash } from "./proof-hash.js";
42
51
  import { verifyNitroAttestation, witnessMatchesAttestation, awsNitroRootSha256, type AttestationWitness } from "./nitro.js";
43
- import { baseTimeIsBound, verifyCeiling, checkCeilingOnline, type CeilingSidecar } from "./ceiling.js";
52
+ import { baseTimeIsBound, checkFloorHeader, floorTimeIsBound, verifyCeiling, checkCeilingOnline, type CeilingSidecar } from "./ceiling.js";
53
+ import { hexToBytes as evmHex } from "./ceiling-evm.js";
44
54
  import { PUBLISHED_PCR0S, publishedMeasurement } from "./measurements.js";
45
55
  import { verifySettlementPointer, checkSettlementOnline, BASE_MAINNET_SETTLEMENT_PINS, type SettlementPointer, type SettlementPins } from "./settlement.js";
46
56
  import type { BitGraphProof } from "./types.js";
47
57
  import { sha256 } from "@noble/hashes/sha256";
48
58
  import {
49
59
  parseCarrier, checkFloorBinding, checkCeilingBinding, anchorMessageBytes,
50
- verifyWitnessHeader, carrierBounds, innerDigestMatches, carrierVersionOf,
60
+ verifyWitnessHeader, carrierBounds, innerDigestMatches, carrierVersionOf, CARRIER_VERSION_4,
51
61
  type CarrierBounds, type CarrierPayload,
52
62
  } from "./carrier.js";
53
63
 
@@ -80,6 +90,8 @@ export interface CarrierVerifyOptions {
80
90
  /** The one online question per chain, answered by nodes the caller names. Without them the confirmed level is UNDETERMINED. */
81
91
  lookups?: CarrierLookups;
82
92
  /** The verifier's own pins. The file's declared pins are compared with these, never used as these. */
93
+ /** v4: spec hashes (base64) to accept beside the ones this verifier knows (KNOWN_TREE_SPEC_HASHES). */
94
+ extraSpecHashes?: readonly string[];
83
95
  pins?: {
84
96
  /**
85
97
  * PCR0 values the verifier accepts. Default: BitGraph's published images
@@ -99,14 +111,21 @@ export interface CarrierVerifyResult {
99
111
  verdict: "TRUE" | "FALSE" | "UNDETERMINED";
100
112
  /** Why the Base block's time is not stated as a bound, when it is not (see baseTimeIsBound). */
101
113
  baseTimeWithheld?: string | null;
114
+ /** Why the floor block's time is not stated as a bound, when it is not: it is stamped after the attestation document (see floorTimeIsBound). */
115
+ floorTimeWithheld?: string | null;
102
116
  /** "ok" | "none" | "corrupt" — whether the bytes carried a readable block at all. */
103
117
  carrier: "ok" | "none" | "corrupt";
104
- version: 1 | 2 | null;
118
+ version: 1 | 2 | 3 | 4 | null;
119
+ /** v4: the leaf the committed bytes are, once its path reached the signed root; null otherwise (and on v1 to v3). */
120
+ member?: TreeVerifyResult["member"];
121
+ /** v4: "content" when the bytes carry the commitment (a placed leaf), "record" when kept as is; null when the bytes were not matched or not in hand. */
122
+ floorCovers?: TreeVerifyResult["floorCovers"];
105
123
  /** Every failed or undetermined check, in the order met. Empty on a clean TRUE. */
106
124
  reasons: string[];
107
125
  /** Stated only when the block was readable. notAfter null = NOT FETCHED, in those words. */
108
126
  bounds: CarrierBounds | null;
109
- ceiling: "present" | "unfetched" | null;
127
+ /** The ceiling in position: "none" on v3, where none exists (order is the chain of proof hashes). */
128
+ ceiling: "present" | "unfetched" | "none" | null;
110
129
  claims: CarrierClaim[];
111
130
  /** Plain language, written from the claims. */
112
131
  reading: string;
@@ -127,7 +146,7 @@ export async function verifyCarrier(bytes: Uint8Array, opts: CarrierVerifyOption
127
146
  return { verdict: "UNDETERMINED", carrier: "corrupt", version: null, reasons: [detail], bounds: null, ceiling: null, claims: [claim], reading: "The file ends in a proof block this reader cannot read. That is a damaged or newer block, not a verdict on the file.", payload: null, inner: null };
128
147
  }
129
148
  const result = await verifyCarrierPayload(parsed.payload, parsed.inner, opts);
130
- return { ...result, reading: `${result.reading} ${envelopeSentence(bytes, parsed.inner)}` };
149
+ return { ...result, reading: `${result.reading} ${envelopeSentence(bytes, parsed.inner, parsed.payload.carrier === CARRIER_VERSION_4)}` };
131
150
  }
132
151
 
133
152
  /**
@@ -136,8 +155,9 @@ export async function verifyCarrier(bytes: Uint8Array, opts: CarrierVerifyOption
136
155
  * that file travels without the README"). A reader who hashes the file they were handed
137
156
  * and compares it with the proof would otherwise conclude the proof is wrong.
138
157
  */
139
- function envelopeSentence(outer: Uint8Array, inner: Uint8Array): string {
158
+ function envelopeSentence(outer: Uint8Array, inner: Uint8Array, member = false): string {
140
159
  const hex = (b: Uint8Array) => Array.from(sha256(b), (x) => x.toString(16).padStart(2, "0")).join("");
160
+ if (member) return `This file's own SHA-256 (${hex(outer)}) is not the committed digest and is not meant to be: the proof block at its end is part of this file's bytes. The proof names the tree's root document; the bytes before that block (SHA-256 ${hex(inner)}) are the tree member the block names, and those are the bytes checked here.`;
141
161
  return `This file's own SHA-256 (${hex(outer)}) is not the committed digest and is not meant to be: the proof block at its end is part of this file's bytes. The proof names the bytes before that block (SHA-256 ${hex(inner)}), and those are the bytes checked here.`;
142
162
  }
143
163
 
@@ -159,7 +179,7 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
159
179
  } catch (e) {
160
180
  const detail = `a part of this proof block is malformed: ${e instanceof Error ? e.message : String(e)}`;
161
181
  add("wellformed", "Every part of the proof block is well formed", "FALSE", "", detail);
162
- let version: 1 | 2 | null = null;
182
+ let version: 1 | 2 | 3 | 4 | null = null;
163
183
  try { version = carrierVersionOf(payload); } catch { /* unreadable */ }
164
184
  const ceilingStatus = (payload as { ceiling?: { status?: unknown } } | null)?.ceiling?.status;
165
185
  return {
@@ -169,7 +189,7 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
169
189
  version,
170
190
  reasons: claims.filter((c) => c.result === "FALSE").map((c) => `${c.name}: ${c.detail}`),
171
191
  bounds: null,
172
- ceiling: ceilingStatus === "present" || ceilingStatus === "unfetched" ? ceilingStatus : null,
192
+ ceiling: ceilingStatus === "present" || ceilingStatus === "unfetched" || ceilingStatus === "none" ? ceilingStatus : null,
173
193
  claims,
174
194
  reading: `This file does not verify: ${detail}. Nothing here is a verdict on what the bytes say, only that the evidence does not hold together.`,
175
195
  payload,
@@ -191,9 +211,13 @@ async function verifyCarrierPayloadChecks(
191
211
  const baseChainId = opts.pins?.baseChainId ?? BASE_MAINNET_CHAIN_ID;
192
212
 
193
213
  if (inner !== null) add("block", "A proof block at the end of the file", "TRUE", "the block's own structure", `bitgraph-carrier/${version}, found from the end of the file and stripped exactly once`);
214
+ const isMember = version === 4;
194
215
 
195
- // 1. The committed bytes are the ones the proof names.
196
- if (inner !== null) {
216
+ // 1. The committed bytes are the ones the proof names. On v4 they are a
217
+ // tree member's, checked against its leaf in step 3.
218
+ if (isMember) {
219
+ // below, with the tree
220
+ } else if (inner !== null) {
197
221
  const digestOk = innerDigestMatches(inner, payload);
198
222
  add("bytes.digest", "The committed bytes are the ones the proof names", digestOk ? "TRUE" : "FALSE", "SHA-256", digestOk ? "SHA-256 of the bytes before the block equals the proof's artifact digest" : "the committed bytes do not hash to the carried proof's artifact digest");
199
223
  } else {
@@ -203,7 +227,9 @@ async function verifyCarrierPayloadChecks(
203
227
  // 2. The proof itself, under the existing bitgraph/1 algorithm. A fresh
204
228
  // context: a carrier is judged alone, not against this process's history.
205
229
  // Without the bytes, the integrity half runs (verify() without bytes).
206
- const proofResult = inner !== null
230
+ // On v4 the signed digest names the root document, never the bytes, so
231
+ // the integrity half runs and the tree binds the bytes (step 3).
232
+ const proofResult = inner !== null && !isMember
207
233
  ? await verify({ proof, bytes: inner, context: createVerificationContext() })
208
234
  : await verifyProofIntegrity({ proof, context: createVerificationContext() });
209
235
  add("proof.signature", "The proof is signed and its position record is bound to it", proofResult.valid ? "TRUE" : "FALSE", "Ed25519", proofResult.valid ? "the enclave's Ed25519 signature over the canonical signed body verifies; the position record's own signature, its hash in the commit, the nonce and the counter order all agree" : `the carried proof does not verify: ${proofResult.reason ?? "unspecified"}`);
@@ -214,16 +240,22 @@ async function verifyCarrierPayloadChecks(
214
240
  add("proof.hash", "The ledger's proofHash is this proof's", ok ? "TRUE" : "FALSE", "SHA-256", ok ? "recomputed over the signed-body subset and equal" : "the proofHash field is not the hash of this proof's signed-body subset");
215
241
  }
216
242
 
217
- // 3. Fused: the commitment inside the bytes, rebuilt from the signed record (fuse/2: and the signed floor block).
243
+ // 3. Fused: the commitment inside the bytes, rebuilt from the signed record (fuse/2 and fuse/3: and the signed floor block).
244
+ // v4: the tree. The spec the proof pins, the root document against the
245
+ // signed digest and the position's commitment, the path, the bytes
246
+ // against the leaf, and for a placed leaf the commitment in the bytes.
218
247
  const marker = readFuseAttribution(proof);
219
- if (marker !== null && inner === null) {
248
+ let tr: TreeVerifyResult | null = null;
249
+ if (isMember) {
250
+ tr = await memberClaims(payload, proof, inner, opts, add);
251
+ } else if (marker !== null && inner === null) {
220
252
  add("proof.fused", "The bytes carry the position commitment", "NOT_CARRIED", "", `the file is not in hand; its bytes carry a bitgraph-fuse/${marker.version ?? 1} commitment to check`);
221
253
  } else if (marker !== null && inner !== null) {
222
254
  const f = await verifyFuse({ proof, bytes: inner });
223
255
  const good = f.category === "FUSED_DIRECT" || f.category === "CARRIED_INLINE";
224
256
  add("proof.fused", "The bytes carry the position commitment", good ? "TRUE" : "FALSE",
225
- marker.version === 2 ? "SHA-256 over the signed position record, its nonce and the signed floor block hash" : "SHA-256 over the signed position record and its nonce",
226
- good ? `${f.category}: ${marker.version === 2 ? "the commitment binds the floor block, so the bytes could not have been finished before that block existed" : "the commitment was made from the position record before the bytes were finished"}` : `${f.category}${f.reason ? `: ${f.reason}` : ""}`);
257
+ (marker.version ?? 1) >= 2 ? "SHA-256 over the signed position record, its nonce and the signed floor block hash" : "SHA-256 over the signed position record and its nonce",
258
+ good ? `${f.category}: ${(marker.version ?? 1) >= 2 ? "the commitment binds the floor block, so the bytes could not have been finished before that block existed" : "the commitment was made from the position record before the bytes were finished"}` : `${f.category}${f.reason ? `: ${f.reason}` : ""}`);
227
259
  } else {
228
260
  add("proof.fused", "The bytes carry the position commitment", "NOT_CARRIED", "", "an ordinary recording: the position was taken after the bytes existed, and no commitment is inside them");
229
261
  }
@@ -268,7 +300,7 @@ async function verifyCarrierPayloadChecks(
268
300
  ? usingDefault && pub ? `PCR0 ${measured.slice(0, 16)}… is BitGraph's published ${pub.version} image (since ${pub.since})` : `PCR0 ${measured.slice(0, 16)}… is on the verifier's list`
269
301
  : usingDefault ? `PCR0 ${measured.slice(0, 16)}… is not an image BitGraph published, so this proof is not BitGraph's` : `PCR0 ${measured.slice(0, 16)}… is not on the verifier's list`);
270
302
  }
271
- if (version === 2 && payload.attestation) {
303
+ if (version >= 2 && payload.attestation) {
272
304
  const w = witnessMatchesAttestation(payload.attestation as unknown as AttestationWitness, att.reportB64);
273
305
  add("attestation.witness", "The openssl witness is what the document decodes to", w.ok ? "TRUE" : "FALSE", "recomputed from the attestation document", w.detail);
274
306
  }
@@ -276,21 +308,60 @@ async function verifyCarrierPayloadChecks(
276
308
  add("attestation.signature", "AWS hardware signed the attestation", "NOT_CARRIED", "", "the proof carries no aws-nitro attestation");
277
309
  }
278
310
 
279
- // 5. The floor: the anchor proof verifies over its own signed message, and
280
- // it is the anchor the enclave fixed at allocation, matched by identity.
281
- const floorMsg = anchorMessageBytes(payload.floor.anchor);
282
- if (floorMsg.error !== null) add("floor.anchor", "The floor anchor is a genuine anchor proof", "FALSE", "", `floor anchor: ${floorMsg.error}`);
283
- else {
284
- const floorResult = await verify({ proof: payload.floor.anchor as unknown as BitGraphProof, bytes: floorMsg.bytes, context: createVerificationContext() });
285
- add("floor.anchor", "The floor anchor is a genuine anchor proof", floorResult.valid ? "TRUE" : "FALSE", "Ed25519", floorResult.valid ? "the anchor proof verifies over its own signed block-hash message, under the same key" : `the floor anchor proof does not verify: ${floorResult.reason ?? "unspecified"}`);
311
+ // 5. The floor. One floor per proof (signedFloorOf); a proof that signs two is ambiguous and floors nothing.
312
+ let signed: SignedFloor | null = null;
313
+ let ambiguous: string | null = null;
314
+ try {
315
+ signed = signedFloorOf(proof);
316
+ } catch (e) {
317
+ ambiguous = (e as Error).message;
318
+ }
319
+ let floorTs: number | null = null;
320
+ let floorChain: "ethereum" | "base" = "ethereum";
321
+ if (payload.floor.basis === "base-header") {
322
+ // v3: the Base header itself, checked against the signed slotFloor. No anchor proof stands under it.
323
+ floorChain = "base";
324
+ const header = payload.floor.header;
325
+ let raw: Uint8Array | null = null;
326
+ try { raw = evmHex(header); } catch { raw = null; }
327
+ const fh = ambiguous !== null || signed === null || raw === null ? null : checkFloorHeader(signed, raw, "base");
328
+ const why = ambiguous ?? (signed === null ? "the proof signs no floor block (commit.slotFloor)" : raw === null ? "the floor header is not hex" : fh && !fh.ok ? fh.reason : "");
329
+ add("floor.binding", "The floor is the Base block the enclave fixed for this position", fh?.ok ? "TRUE" : "FALSE", "the proof's signed commit.slotFloor",
330
+ fh?.ok ? "the header's block number, hash and time equal the signed slotFloor, on Base mainnet's schedule" : why);
331
+ if (fh?.ok) {
332
+ floorTs = fh.header.timestamp;
333
+ add("floor.header", "The floor block's header is the one with that hash", "TRUE", `Base block ${fh.header.number}, header as given`, `keccak-256 of the header equals the signed block hash; its time is ${iso(fh.header.timestamp)}`);
334
+ } else {
335
+ add("floor.header", "The floor block's header is the one with that hash", "FALSE", "", `floor header: ${why}`);
336
+ }
337
+ } else {
338
+ // v1, v2: the anchor proof verifies over its own signed message, and it
339
+ // is the anchor the enclave fixed at allocation, matched by identity.
340
+ const floorMsg = anchorMessageBytes(payload.floor.anchor);
341
+ if (floorMsg.error !== null) add("floor.anchor", "The floor anchor is a genuine anchor proof", "FALSE", "", `floor anchor: ${floorMsg.error}`);
342
+ else {
343
+ const floorResult = await verify({ proof: payload.floor.anchor as unknown as BitGraphProof, bytes: floorMsg.bytes, context: createVerificationContext() });
344
+ add("floor.anchor", "The floor anchor is a genuine anchor proof", floorResult.valid ? "TRUE" : "FALSE", "Ed25519", floorResult.valid ? "the anchor proof verifies over its own signed block-hash message, under the same key" : `the floor anchor proof does not verify: ${floorResult.reason ?? "unspecified"}`);
345
+ }
346
+ const floorBind = ambiguous !== null ? [ambiguous]
347
+ : signed?.chain === "base" ? ["the proof signs a Base floor (commit.slotFloor), and this block carries an Ethereum anchor as its floor"]
348
+ : checkFloorBinding(payload.proof, payload.floor);
349
+ add("floor.binding", "The floor is the anchor the enclave fixed for this position", floorBind.length === 0 ? "TRUE" : "FALSE", "the proof's signed commit.slotAnchor", floorBind.length === 0 ? "the anchor's counter, block number and block hash equal the signed slotAnchor" : floorBind.join("; "));
350
+ const floorWitness = verifyWitnessHeader(payload.floor.witness);
351
+ floorTs = floorWitness.ok ? floorWitness.timestamp : null;
352
+ add("floor.header", "The floor block's header is the one with that hash", floorWitness.ok ? "TRUE" : "FALSE", `Ethereum block ${payload.floor.witness.blockNumber}, header as given`, floorWitness.ok ? `keccak-256 of the header equals the signed block hash; its time is ${iso(floorWitness.timestamp)}` : `floor witness: ${floorWitness.error}`);
353
+ }
354
+ // The floor's time is a bound only when it is no later than the attestation document (review, 2026-10-06).
355
+ let floorTimeWithheld: string | null = null;
356
+ if (floorTs !== null) {
357
+ const bound = floorTimeIsBound(floorTs, attestedAtMs);
358
+ if (!bound.ok) floorTimeWithheld = bound.reason;
286
359
  }
287
- const floorBind = checkFloorBinding(payload.proof, payload.floor);
288
- add("floor.binding", "The floor is the anchor the enclave fixed for this position", floorBind.length === 0 ? "TRUE" : "FALSE", "the proof's signed commit.slotAnchor", floorBind.length === 0 ? "the anchor's counter, block number and block hash equal the signed slotAnchor" : floorBind.join("; "));
289
- const floorWitness = verifyWitnessHeader(payload.floor.witness);
290
- add("floor.header", "The floor block's header is the one with that hash", floorWitness.ok ? "TRUE" : "FALSE", `Ethereum block ${payload.floor.witness.blockNumber}, header as given`, floorWitness.ok ? `keccak-256 of the header equals the signed block hash; its time is ${iso(floorWitness.timestamp)}` : `floor witness: ${floorWitness.error}`);
291
360
 
292
- // 6. The ceiling in position, only when the carrier claims one.
293
- if (payload.ceiling.status === "present") {
361
+ // 6. The ceiling in position: v1 and v2 when the carrier claims one; v3 has none.
362
+ if (payload.ceiling.status === "none") {
363
+ add("ceiling.position", "A closing anchor follows the record", "NOT_CARRIED", "", "none exists for a Base-floor BitGraph: anchors ended with the cutover, and its order among BitGraphs is the chain of proof hashes");
364
+ } else if (payload.ceiling.status === "present") {
294
365
  const ceilMsg = anchorMessageBytes(payload.ceiling.anchor);
295
366
  if (ceilMsg.error !== null) add("ceiling.position.anchor", "The closing anchor is a genuine anchor proof", "FALSE", "", `ceiling anchor: ${ceilMsg.error}`);
296
367
  else {
@@ -305,11 +376,11 @@ async function verifyCarrierPayloadChecks(
305
376
  add("ceiling.position.binding", "The record was committed before the closing anchor", "NOT_CARRIED", "", "closing anchor not fetched: the floor stands on its own");
306
377
  }
307
378
 
308
- // 7. v2: the ceiling in time, the Base block the record existed by.
379
+ // 7. v2 and v3: the ceiling in time, the Base block the record existed by.
309
380
  let ceilingTime: { blockNumber: number; blockHash: string; blockTimestamp: number; status: string } | null = null;
310
381
  let baseTimeWithheld: string | null = null;
311
382
  let sidecar: CeilingSidecar | null = null;
312
- if (version === 2) {
383
+ if (version >= 2) {
313
384
  const ct = payload.ceilingInTime;
314
385
  if (ct && ct.status === "present") {
315
386
  sidecar = ct.sidecar as unknown as CeilingSidecar;
@@ -320,11 +391,11 @@ async function verifyCarrierPayloadChecks(
320
391
  add("ceiling.time.payload", "The transaction carries that root", r(byName("payload")), "the 84-byte BGC1 payload", byName("payload")?.detail ?? c.reason ?? "not reached");
321
392
  add("ceiling.time.sender", "The transaction was signed by the ceiling writer", r(byName("sender")), `secp256k1; the writer pin ${pinnedWriter.slice(0, 8)}…`, byName("sender")?.detail ?? c.reason ?? "not reached");
322
393
  add("ceiling.time.inclusion", "The transaction is in the Base block", r(byName("inclusion")), `Merkle-Patricia proof; Base block ${sidecar.anchor?.blockNumber ?? "?"}, header as given`, byName("inclusion")?.detail ?? c.reason ?? "not reached");
323
- add("ceiling.time.floor", "The floor header the ceiling carries is the signed floor", r(byName("floor")), "the proof's signed commit.slotAnchor", byName("floor")?.detail ?? "the sidecar carries no floor header");
394
+ add("ceiling.time.floor", "The floor header the ceiling carries is the signed floor", r(byName("floor")), floorChain === "base" ? "the proof's signed commit.slotFloor" : "the proof's signed commit.slotAnchor", byName("floor")?.detail ?? "the sidecar carries no floor header");
324
395
  const win = c.ok ? c.window?.ceiling : undefined;
325
396
  if (win) {
326
397
  // The inclusion holds either way; a stamp that cannot be a bound is withheld as a time.
327
- const stamp = baseTimeIsBound(win.blockTimestamp, { floorTimestampSec: floorWitness.timestamp ?? c.window?.floor.blockTimestamp ?? null, attestedAtMs });
398
+ const stamp = baseTimeIsBound(win.blockTimestamp, { floorTimestampSec: floorTs ?? c.window?.floor.blockTimestamp ?? null, attestedAtMs });
328
399
  if (stamp.ok) ceilingTime = { blockNumber: win.blockNumber, blockHash: win.blockHash, blockTimestamp: win.blockTimestamp, status: c.status ?? "included" };
329
400
  else baseTimeWithheld = stamp.reason;
330
401
  }
@@ -334,7 +405,7 @@ async function verifyCarrierPayloadChecks(
334
405
  add("ceiling.time.record", "The record existed by a Base block", "NOT_CARRIED", "", ct?.status === "unfetched" ? "the ceiling in time was not fetched when this file was made" : "no ceiling in time is stated");
335
406
  }
336
407
 
337
- // 8. v2: settlement on Ethereum, when carried.
408
+ // 8. v2 and v3: settlement on Ethereum, when carried.
338
409
  const st = payload.settlement;
339
410
  if (st && st.status === "present") {
340
411
  const pointer = st.pointer as unknown as SettlementPointer;
@@ -362,12 +433,21 @@ async function verifyCarrierPayloadChecks(
362
433
  }
363
434
  }
364
435
 
365
- // 10. Confirmed: the block hashes against nodes the caller named.
436
+ // 10. Confirmed: the block hashes against nodes the caller named. The floor
437
+ // is asked of its own chain, by height: the chain's block at N must be
438
+ // the one the header hashes to.
366
439
  const lk = opts.lookups;
440
+ const nb = carrierBounds(payload).notBefore;
441
+ const floorAsk = floorChain === "base" ? lk?.baseBlockHash : lk?.ethereumBlockHash;
442
+ const floorChainName = floorChain === "base" ? "Base" : "Ethereum";
443
+ if (floorAsk) {
444
+ const h = (await safe(() => floorAsk(nb.blockNumber)))?.toLowerCase();
445
+ const ok = h === nb.blockHash;
446
+ add("confirmed.floor", `The floor block is ${floorChainName}'s own`, h ? (ok ? "TRUE" : "FALSE") : "UNDETERMINED", `the ${floorChainName} node the caller named`, h ? (ok ? `${floorChainName} block ${nb.blockNumber} matches the node` : `the node's block ${nb.blockNumber} is ${h}, not this header`) : "the node did not answer", "confirmed");
447
+ } else {
448
+ add("confirmed.floor", `The floor block is ${floorChainName}'s own`, "UNDETERMINED", "", `no ${floorChainName} node given: the header is taken as the one matching its hash; confirm block ${nb.blockNumber} against any node or explorer`, "confirmed");
449
+ }
367
450
  if (lk?.ethereumBlockHash) {
368
- const h = (await safe(() => lk.ethereumBlockHash!(payload.floor.witness.blockNumber)))?.toLowerCase();
369
- const ok = h === payload.floor.witness.blockHash.toLowerCase();
370
- add("confirmed.floor", "The floor block is Ethereum's own", h ? (ok ? "TRUE" : "FALSE") : "UNDETERMINED", "the Ethereum node the caller named", h ? (ok ? `Ethereum block ${payload.floor.witness.blockNumber} matches the node` : `the node's block ${payload.floor.witness.blockNumber} is ${h}, not this header`) : "the node did not answer", "confirmed");
371
451
  const pc = payload.ceiling;
372
452
  if (pc.status === "present") {
373
453
  const h2 = (await safe(() => lk.ethereumBlockHash!(pc.witness.blockNumber)))?.toLowerCase();
@@ -379,8 +459,6 @@ async function verifyCarrierPayloadChecks(
379
459
  const r = await checkSettlementOnline(st.pointer as unknown as SettlementPointer, lk.ethereumBlockHash);
380
460
  add("confirmed.settlement", "The settling Ethereum block is Ethereum's own", r.ok ? "TRUE" : "FALSE", "the Ethereum node the caller named", r.detail, "confirmed");
381
461
  }
382
- } else {
383
- add("confirmed.floor", "The floor block is Ethereum's own", "UNDETERMINED", "", "no Ethereum node given: the header is taken as the one matching its hash; confirm block " + payload.floor.witness.blockNumber + " against any node or explorer", "confirmed");
384
462
  }
385
463
  if (sidecar) {
386
464
  if (lk?.baseBlockHash) {
@@ -396,25 +474,105 @@ async function verifyCarrierPayloadChecks(
396
474
  // says only that some AWS Nitro enclave signed.
397
475
  const pins = claims.find((c) => c.id === "attestation.pins");
398
476
  if (reasons.length === 0 && pins?.result !== "TRUE") reasons.push(pins ? `${pins.name}: ${pins.detail}` : "The image is one the verifier accepts: the proof carries no attestation, so no image was established");
399
- const verdict: CarrierVerifyResult["verdict"] = claims.some((c) => c.result === "FALSE") ? "FALSE" : pins?.result === "TRUE" ? "TRUE" : "UNDETERMINED";
477
+ // v4: a tree this verifier could not judge (a spec it does not know) is not judged, never TRUE.
478
+ const treeUnjudged = isMember ? claims.filter((c) => TREE_CLAIM_IDS.includes(c.id) && c.result === "UNDETERMINED") : [];
479
+ if (reasons.length === 0) for (const c of treeUnjudged) reasons.push(`${c.name}: ${c.detail}`);
480
+ const verdict: CarrierVerifyResult["verdict"] = claims.some((c) => c.result === "FALSE") ? "FALSE" : pins?.result === "TRUE" && treeUnjudged.length === 0 ? "TRUE" : "UNDETERMINED";
400
481
  const bounds = carrierBounds(payload);
401
482
  // The ceiling in time reaches callers only as verified here, and only when its stamp is a bound.
402
483
  bounds.existedBy = ceilingTime ? { chain: "base", blockNumber: ceilingTime.blockNumber, blockHash: ceilingTime.blockHash, timestamp: ceilingTime.blockTimestamp } : null;
484
+ // So does the floor's time: from a verified header, and only when it is a bound.
485
+ bounds.notBefore.timestamp = floorTimeWithheld === null ? floorTs : null;
403
486
  return {
404
487
  verdict,
405
488
  baseTimeWithheld,
489
+ floorTimeWithheld,
406
490
  carrier: "ok",
407
491
  version,
408
492
  reasons,
409
493
  bounds,
410
494
  ceiling: payload.ceiling.status,
411
495
  claims,
412
- reading: writeReading(verdict, claims, bounds, proof, ceilingTime, floorWitness.timestamp, baseTimeWithheld),
496
+ member: tr?.member ?? null,
497
+ floorCovers: tr && (TREE_MEMBER_CATEGORIES as readonly string[]).includes(tr.category) ? tr.floorCovers : null,
498
+ reading: writeReading(verdict, claims, bounds, proof, ceilingTime, bounds.notBefore.timestamp, baseTimeWithheld, floorTimeWithheld, tr),
413
499
  payload,
414
500
  inner,
415
501
  };
416
502
  }
417
503
 
504
+ /** The claims a v4 block adds in place of the digest and fused lines; their verdict weight is checked by id. */
505
+ const TREE_CLAIM_IDS: readonly string[] = ["spec.pin", "tree.root", "tree.member", "bytes.digest"];
506
+
507
+ /**
508
+ * v4: the bytes, as one member of the tree the proof commits. Five claims, in
509
+ * export/1's words: the spec pin, the root document, the member's path, the
510
+ * bytes against the leaf, and (as proof.fused, the content floor) the
511
+ * commitment inside a placed leaf's bytes. A leaf kept as is carries no
512
+ * commitment: recorded after the floor block, the bytes themselves are not
513
+ * dated. The bytes must be the leaf's COMMITTED bytes: an original that would
514
+ * rebuild them is not what a BitGraphed file carries, and is refused.
515
+ */
516
+ async function memberClaims(
517
+ payload: CarrierPayload,
518
+ proof: BitGraphProof,
519
+ inner: Uint8Array | null,
520
+ opts: CarrierVerifyOptions,
521
+ add: (id: string, name: string, result: ClaimResult, restsOn: string, detail: string, level?: "offline" | "confirmed") => number,
522
+ ): Promise<TreeVerifyResult> {
523
+ const t = payload.tree!;
524
+ const rootDocument = treeHex(t.rootDocument) ?? new Uint8Array(0);
525
+ // The proof's own check is its own claim (step 2); the tree is judged on its own evidence.
526
+ const tr = await verifyTreeMember({
527
+ proof,
528
+ ...(inner !== null ? { bytes: inner } : {}),
529
+ member: t.member,
530
+ rootDocument,
531
+ ...(opts.extraSpecHashes ? { extraSpecHashes: opts.extraSpecHashes } : {}),
532
+ proofAlreadyVerified: true,
533
+ });
534
+ const unknownSpec = tr.category === "UNKNOWN_SPEC";
535
+ const notTree = tr.category === "NOT_TREE";
536
+ const specOk = !unknownSpec && !notTree && tr.category !== "INVALID_TREE_MARKER";
537
+ add("spec.pin", "The proof pins a spec this verifier knows", specOk ? "TRUE" : unknownSpec ? "UNDETERMINED" : "FALSE", "the signed attribution.message",
538
+ specOk ? `SPEC.md SHA-256 ${tr.specHashB64}` : notTree ? `the carried proof is not a tree/1 proof (${tr.reason}); a ${CARRIER_VERSION_4} block carries one member of a tree` : unknownSpec ? `${tr.reason}; a verifier that knows that spec can judge the tree` : tr.reason);
539
+ const rootOk = tr.tree !== null;
540
+ add("tree.root", "The root document is the signed one and carries this position's commitment", rootOk ? "TRUE" : unknownSpec ? "UNDETERMINED" : "FALSE",
541
+ "SHA-256 over the signed position record, its nonce and the signed floor block hash",
542
+ rootOk ? `a tree of ${tr.tree!.count} leaves, root ${tr.tree!.rootHex.slice(0, 16)}…; SHA-256 of the root document is the proof's artifact digest` : unknownSpec ? "not judged: the proof follows a spec this verifier does not know" : tr.reason);
543
+ const pathOk = tr.member !== null;
544
+ add("tree.member", "The member's leaf is in the committed tree", pathOk ? "TRUE" : rootOk ? "FALSE" : "UNDETERMINED", "SHA-256 (RFC 9162 path)",
545
+ pathOk ? `leaf ${tr.member!.index} of ${tr.member!.count} (${tr.member!.placement === "as-is" ? "kept as is" : tr.member!.placement}); a path proves this leaf only, not the order of the others` : rootOk ? tr.reason : "not judged: the root it would reach is not established");
546
+ const where = tr.member ? `leaf ${tr.member.index} of ${tr.member.count}` : `leaf ${t.member.index} of ${t.member.count}`;
547
+ const asIs = tr.member?.placement === "as-is" || /^00/.test(t.member.leaf);
548
+ if (inner === null) {
549
+ add("bytes.digest", "The bytes are this member's committed bytes", "NOT_CARRIED", "", `the file is not in hand; the block names ${where}, SHA-256 ${t.member.leaf.slice(2, 66)}`);
550
+ add("proof.fused", "The committed bytes carry the position commitment", "NOT_CARRIED", "", asIs
551
+ ? "the member was kept as is: the bytes carry no commitment, so the bytes themselves are not dated"
552
+ : "the file is not in hand; its bytes carry the position commitment to check");
553
+ return tr;
554
+ }
555
+ const isMember = (TREE_MEMBER_CATEGORIES as readonly string[]).includes(tr.category);
556
+ if (tr.category === "TREE_MEMBER_FROM_ORIGIN") {
557
+ add("bytes.digest", "The bytes are this member's committed bytes", "FALSE", "SHA-256",
558
+ `the bytes before the block are ${where}'s original, not its committed bytes: a BitGraphed file carries the bytes the leaf names, with the commitment placed in them`);
559
+ } else {
560
+ add("bytes.digest", "The bytes are this member's committed bytes", isMember ? "TRUE" : pathOk ? "FALSE" : "UNDETERMINED", "SHA-256",
561
+ isMember ? `SHA-256 of the bytes before the block is the artifact digest of ${where}` : pathOk ? `${tr.category}: ${tr.reason}` : "not judged: the member's place in the tree did not verify");
562
+ }
563
+ if (tr.category === "TREE_MEMBER_DIRECT") {
564
+ add("proof.fused", "The committed bytes carry the position commitment", "TRUE", "SHA-256 over the signed position record, its nonce and the signed floor block hash",
565
+ `${tr.member!.placement}: the commitment binds the floor block, so these bytes could not have been finished before that block existed; the original inside them is not dated by it`);
566
+ } else if (tr.category === "TREE_MEMBER_AS_IS" || asIs) {
567
+ add("proof.fused", "The committed bytes carry the position commitment", "NOT_CARRIED", "", "the member was kept as is: the bytes carry no commitment, so the bytes themselves are not dated (the record floor only)");
568
+ } else if (tr.category === "INVALID_SLOT_COMMITMENT" || tr.category === "INVALID_ORIGIN") {
569
+ add("proof.fused", "The committed bytes carry the position commitment", "FALSE", "", `${tr.category}: ${tr.reason}`);
570
+ } else {
571
+ add("proof.fused", "The committed bytes carry the position commitment", "NOT_CARRIED", "", "not reached: the bytes before the block are not this leaf's committed bytes");
572
+ }
573
+ return tr;
574
+ }
575
+
418
576
  async function safe<T>(f: () => Promise<T>): Promise<T | null> {
419
577
  try { return await f(); } catch { return null; }
420
578
  }
@@ -435,6 +593,8 @@ function writeReading(
435
593
  ceilingTime: { blockNumber: number; blockHash: string; blockTimestamp: number } | null,
436
594
  floorTs: number | null,
437
595
  baseTimeWithheld: string | null = null,
596
+ floorTimeWithheld: string | null = null,
597
+ tr: TreeVerifyResult | null = null,
438
598
  ): string {
439
599
  const get = (id: string) => claims.find((c) => c.id === id);
440
600
  if (verdict === "FALSE") {
@@ -444,15 +604,26 @@ function writeReading(
444
604
  const position = proof.commit?.counter ?? "?";
445
605
  const epoch = (proof.commit?.epochId ?? "").replace(/=+$/, "").slice(0, 8);
446
606
  const fused = get("proof.fused");
447
- const after = floorTs !== null ? `Recorded after Ethereum block ${bounds.notBefore.blockNumber} (${iso(floorTs)})` : `Recorded after Ethereum block ${bounds.notBefore.blockNumber}`;
607
+ const floorChain = bounds.notBefore.chain === "base" ? "Base" : "Ethereum";
608
+ const after = floorTs !== null ? `Recorded after ${floorChain} block ${bounds.notBefore.blockNumber} (${iso(floorTs)})` : `Recorded after ${floorChain} block ${bounds.notBefore.blockNumber}`;
448
609
  const by = ceilingTime ? `, and existed by Base block ${ceilingTime.blockNumber} (${iso(ceilingTime.blockTimestamp)})` : "";
449
610
  const settled = bounds.settledBy ? `, whose batch data Ethereum committed in block ${bounds.settledBy.blockNumber} (${iso(bounds.settledBy.timestamp)})` : "";
450
- const before = bounds.notAfter ? `; committed before the anchoring of Ethereum block ${bounds.notAfter.blockNumber}, a bound in position` : "";
611
+ const before = bounds.notAfter
612
+ ? `; committed before the anchoring of Ethereum block ${bounds.notAfter.blockNumber}, a bound in position`
613
+ : get("ceiling.position") ? "; its order among BitGraphs is the chain of proof hashes" : "";
451
614
  const digest = get("bytes.digest");
452
615
  // Two floors (SPEC 8.6): every record has the record floor; only bytes that
453
616
  // carry the commitment have the content floor. Without it, the bytes
454
617
  // themselves are not dated.
455
- const subject = digest?.result !== "TRUE"
618
+ // v4: the same two floors, said of one member of the tree (SPEC 8.6, export/1's words).
619
+ const leafWords = tr?.member ? `leaf ${tr.member.index} of ${tr.member.count} in the committed tree` : null;
620
+ const subject = tr !== null
621
+ ? digest?.result !== "TRUE"
622
+ ? leafWords ? `The tree this proof names was committed under this position, and ${leafWords.replace(/ in the committed tree$/, "")} is in it.` : "The tree this proof names was committed under this position."
623
+ : fused?.result === "TRUE"
624
+ ? `These exact bytes are ${leafWords} and carry the commitment, so they were finished after the floor block (the content floor); an original inside them is not dated by it.`
625
+ : `These exact bytes are ${leafWords}, kept as is: they carry no commitment, so the bytes themselves are not dated (the record floor only).`
626
+ : digest?.result !== "TRUE"
456
627
  ? "The bytes this proof names were committed under this position."
457
628
  : fused?.result === "TRUE"
458
629
  ? (fused.restsOn.includes("floor block") ? "These exact bytes carry the commitment, so they were finished after the floor block (the content floor)." : "These exact bytes carry the commitment, so they were finished after their position was opened (the content floor).")
@@ -460,7 +631,7 @@ function writeReading(
460
631
  const att = get("attestation.root");
461
632
  const rests: string[] = ["SHA-256", "Ed25519"];
462
633
  if (att?.result === "TRUE") rests.push(`the AWS Nitro root (${awsNitroRootSha256().slice(0, 8)}…)`);
463
- rests.push(`Ethereum block ${bounds.notBefore.blockNumber}`);
634
+ rests.push(`${floorChain} block ${bounds.notBefore.blockNumber}`);
464
635
  if (ceilingTime) rests.push(`Base block ${ceilingTime.blockNumber}`);
465
636
  if (bounds.settledBy) rests.push(`Ethereum block ${bounds.settledBy.blockNumber}`);
466
637
  const confirmed = claims.filter((c) => c.level === "confirmed");
@@ -470,7 +641,8 @@ function writeReading(
470
641
  : "Offline, the blocks are taken from their headers, each of which hashes to the hash the evidence names; confirm them against any node or explorer to remove that reliance.";
471
642
  const pins = get("attestation.pins");
472
643
  const pinLine = pins?.result === "TRUE" ? ` ${pins.detail.replace(/^PCR0 [0-9a-f]+… is /, "The enclave image is ")}.` : pins?.result === "UNDETERMINED" ? ` ${pins.detail}.` : !pins ? " The proof carries no attestation, so which enclave image signed it is not established." : "";
473
- const withheld = baseTimeWithheld ? ` The record is in a Base block, but its time is not used as a bound: ${baseTimeWithheld}.` : "";
644
+ const withheld = (floorTimeWithheld ? ` The floor block's time is not used as a bound: ${floorTimeWithheld}.` : "")
645
+ + (baseTimeWithheld ? ` The record is in a Base block, but its time is not used as a bound: ${baseTimeWithheld}.` : "");
474
646
  const lead = verdict === "UNDETERMINED" ? "Not judged in full. " : "";
475
647
  return `${lead}${subject} ${after}${by}${settled}${before}. Position ${position} of epoch ${epoch}…. Rests on: ${rests.join(", ")}. ${tail}${withheld}${pinLine}`;
476
648
  }