@mikeargento/bitgraph-verify 1.15.2 → 1.17.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 (66) hide show
  1. package/README.md +24 -3
  2. package/dist/__tests__/carrier2.test.js +62 -3
  3. package/dist/__tests__/carrier2.test.js.map +1 -1
  4. package/dist/__tests__/ceiling.test.js +11 -4
  5. package/dist/__tests__/ceiling.test.js.map +1 -1
  6. package/dist/carrier-assemble.d.ts +12 -2
  7. package/dist/carrier-assemble.d.ts.map +1 -1
  8. package/dist/carrier-assemble.js +14 -3
  9. package/dist/carrier-assemble.js.map +1 -1
  10. package/dist/carrier-verify.d.ts +15 -4
  11. package/dist/carrier-verify.d.ts.map +1 -1
  12. package/dist/carrier-verify.js +201 -59
  13. package/dist/carrier-verify.js.map +1 -1
  14. package/dist/carrier.d.ts +48 -13
  15. package/dist/carrier.d.ts.map +1 -1
  16. package/dist/carrier.js +74 -16
  17. package/dist/carrier.js.map +1 -1
  18. package/dist/ceiling.d.ts +115 -6
  19. package/dist/ceiling.d.ts.map +1 -1
  20. package/dist/ceiling.js +189 -23
  21. package/dist/ceiling.js.map +1 -1
  22. package/dist/export.d.ts +122 -0
  23. package/dist/export.d.ts.map +1 -0
  24. package/dist/export.js +510 -0
  25. package/dist/export.js.map +1 -0
  26. package/dist/fuse.d.ts +45 -11
  27. package/dist/fuse.d.ts.map +1 -1
  28. package/dist/fuse.js +100 -18
  29. package/dist/fuse.js.map +1 -1
  30. package/dist/index.d.ts +20 -2
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +18 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/measurements.d.ts +30 -0
  35. package/dist/measurements.d.ts.map +1 -0
  36. package/dist/measurements.js +22 -0
  37. package/dist/measurements.js.map +1 -0
  38. package/dist/output-root.d.ts +88 -0
  39. package/dist/output-root.d.ts.map +1 -0
  40. package/dist/output-root.js +260 -0
  41. package/dist/output-root.js.map +1 -0
  42. package/dist/stream.d.ts +46 -0
  43. package/dist/stream.d.ts.map +1 -0
  44. package/dist/stream.js +290 -0
  45. package/dist/stream.js.map +1 -0
  46. package/dist/tree.d.ts +167 -0
  47. package/dist/tree.d.ts.map +1 -0
  48. package/dist/tree.js +485 -0
  49. package/dist/tree.js.map +1 -0
  50. package/dist/types.d.ts +21 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/src/__tests__/carrier2.test.ts +65 -3
  54. package/src/__tests__/ceiling.test.ts +12 -4
  55. package/src/carrier-assemble.ts +21 -3
  56. package/src/carrier-verify.ts +204 -61
  57. package/src/carrier.ts +95 -27
  58. package/src/ceiling.ts +217 -28
  59. package/src/export.ts +592 -0
  60. package/src/fuse.ts +126 -23
  61. package/src/index.ts +47 -1
  62. package/src/measurements.ts +49 -0
  63. package/src/output-root.ts +301 -0
  64. package/src/stream.ts +291 -0
  65. package/src/tree.ts +580 -0
  66. package/src/types.ts +22 -0
@@ -1,21 +1,25 @@
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 or /3), 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
9
  * the bytes SHA-256 of the committed bytes is the digest the proof names
10
10
  * the proof Ed25519 signature, the position record and its bindings, the
11
- * fused commitment rebuilt (bitgraph-fuse/1 or /2), proofHash
11
+ * fused commitment rebuilt (bitgraph-fuse/1, /2 or /3), proofHash
12
12
  * the attestation ES384 signature, the certificate chain to the AWS Nitro root
13
13
  * (641A0321…), validity at the document's own instant, PCR0 against
14
14
  * the proof's measurement, user_data against the signed body; and,
15
15
  * 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
16
+ * the floor v1, v2: the anchor proof named by the signed slotAnchor, verified over
17
+ * its own message, matched by identity; its Ethereum header recomputed.
18
+ * v3: the Base header, checked against the signed slotFloor (hash,
19
+ * number, time, Base mainnet's schedule). Either way the floor's time
20
+ * is a bound only when no later than the attestation document.
21
+ * the ceilings in position (v1, v2): the next anchor, same checks; v3 has none, its
22
+ * order is the chain of proof hashes; in time (v2, v3): the Base
19
23
  * sidecar's whole chain of custody (verifyCeiling); settled (v2): the
20
24
  * Ethereum block that committed the batch data (verifySettlementPointer)
21
25
  * the pins what the file declares it was made under, against the verifier's own
@@ -37,10 +41,12 @@
37
41
 
38
42
  import { verify, verifyProofIntegrity, createVerificationContext } from "./verifier.js";
39
43
  import { verifyFuse } from "./fuse-verify.js";
40
- import { readFuseAttribution } from "./fuse.js";
44
+ import { readFuseAttribution, signedFloorOf, type SignedFloor } from "./fuse.js";
41
45
  import { computeProofHash, computeSignedBodyHash } from "./proof-hash.js";
42
46
  import { verifyNitroAttestation, witnessMatchesAttestation, awsNitroRootSha256, type AttestationWitness } from "./nitro.js";
43
- import { verifyCeiling, checkCeilingOnline, type CeilingSidecar } from "./ceiling.js";
47
+ import { baseTimeIsBound, checkFloorHeader, floorTimeIsBound, verifyCeiling, checkCeilingOnline, type CeilingSidecar } from "./ceiling.js";
48
+ import { hexToBytes as evmHex } from "./ceiling-evm.js";
49
+ import { PUBLISHED_PCR0S, publishedMeasurement } from "./measurements.js";
44
50
  import { verifySettlementPointer, checkSettlementOnline, BASE_MAINNET_SETTLEMENT_PINS, type SettlementPointer, type SettlementPins } from "./settlement.js";
45
51
  import type { BitGraphProof } from "./types.js";
46
52
  import { sha256 } from "@noble/hashes/sha256";
@@ -80,24 +86,35 @@ export interface CarrierVerifyOptions {
80
86
  lookups?: CarrierLookups;
81
87
  /** The verifier's own pins. The file's declared pins are compared with these, never used as these. */
82
88
  pins?: {
83
- /** PCR0 values the verifier accepts. Without a list, the attestation's PCR0 is reported, not judged. */
84
- pcr0?: string[];
89
+ /**
90
+ * PCR0 values the verifier accepts. Default: BitGraph's published images
91
+ * (SPEC section 16). An empty list accepts nothing and leaves the claim,
92
+ * and so the verdict, undetermined.
93
+ */
94
+ pcr0?: readonly string[];
85
95
  ceilingWriter?: string;
86
96
  baseChainId?: number;
87
97
  settlement?: SettlementPins;
98
+ /** Another attestation trust root, DER, for a verifier that pins its own (tests use this). Default: the embedded AWS Nitro root. */
99
+ rootDer?: Uint8Array;
88
100
  };
89
101
  }
90
102
 
91
103
  export interface CarrierVerifyResult {
92
104
  verdict: "TRUE" | "FALSE" | "UNDETERMINED";
105
+ /** Why the Base block's time is not stated as a bound, when it is not (see baseTimeIsBound). */
106
+ baseTimeWithheld?: string | null;
107
+ /** 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). */
108
+ floorTimeWithheld?: string | null;
93
109
  /** "ok" | "none" | "corrupt" — whether the bytes carried a readable block at all. */
94
110
  carrier: "ok" | "none" | "corrupt";
95
- version: 1 | 2 | null;
111
+ version: 1 | 2 | 3 | null;
96
112
  /** Every failed or undetermined check, in the order met. Empty on a clean TRUE. */
97
113
  reasons: string[];
98
114
  /** Stated only when the block was readable. notAfter null = NOT FETCHED, in those words. */
99
115
  bounds: CarrierBounds | null;
100
- ceiling: "present" | "unfetched" | null;
116
+ /** The ceiling in position: "none" on v3, where none exists (order is the chain of proof hashes). */
117
+ ceiling: "present" | "unfetched" | "none" | null;
101
118
  claims: CarrierClaim[];
102
119
  /** Plain language, written from the claims. */
103
120
  reading: string;
@@ -140,10 +157,43 @@ function envelopeSentence(outer: Uint8Array, inner: Uint8Array): string {
140
157
  * as not carried, and everything else is judged exactly as for a file.
141
158
  */
142
159
  export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8Array | null, opts: CarrierVerifyOptions = {}): Promise<CarrierVerifyResult> {
143
- const version = carrierVersionOf(payload);
144
160
  const claims: CarrierClaim[] = [];
145
161
  const add = (id: string, name: string, result: ClaimResult, restsOn: string, detail: string, level: "offline" | "confirmed" = "offline") =>
146
162
  claims.push({ id, name, result, restsOn, detail, level });
163
+ // Every part is read defensively below; a malformed part that still throws
164
+ // is a FALSE claim, never an exception.
165
+ try {
166
+ return await verifyCarrierPayloadChecks(payload, inner, opts, claims, add);
167
+ } catch (e) {
168
+ const detail = `a part of this proof block is malformed: ${e instanceof Error ? e.message : String(e)}`;
169
+ add("wellformed", "Every part of the proof block is well formed", "FALSE", "", detail);
170
+ let version: 1 | 2 | 3 | null = null;
171
+ try { version = carrierVersionOf(payload); } catch { /* unreadable */ }
172
+ const ceilingStatus = (payload as { ceiling?: { status?: unknown } } | null)?.ceiling?.status;
173
+ return {
174
+ verdict: "FALSE",
175
+ baseTimeWithheld: null,
176
+ carrier: "ok",
177
+ version,
178
+ reasons: claims.filter((c) => c.result === "FALSE").map((c) => `${c.name}: ${c.detail}`),
179
+ bounds: null,
180
+ ceiling: ceilingStatus === "present" || ceilingStatus === "unfetched" || ceilingStatus === "none" ? ceilingStatus : null,
181
+ claims,
182
+ 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.`,
183
+ payload,
184
+ inner,
185
+ };
186
+ }
187
+ }
188
+
189
+ async function verifyCarrierPayloadChecks(
190
+ payload: CarrierPayload,
191
+ inner: Uint8Array | null,
192
+ opts: CarrierVerifyOptions,
193
+ claims: CarrierClaim[],
194
+ add: (id: string, name: string, result: ClaimResult, restsOn: string, detail: string, level?: "offline" | "confirmed") => number,
195
+ ): Promise<CarrierVerifyResult> {
196
+ const version = carrierVersionOf(payload);
147
197
  const proof = payload.proof as unknown as BitGraphProof;
148
198
  const pinnedWriter = opts.pins?.ceilingWriter ?? BITGRAPH_CEILING_WRITER;
149
199
  const baseChainId = opts.pins?.baseChainId ?? BASE_MAINNET_CHAIN_ID;
@@ -172,7 +222,7 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
172
222
  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");
173
223
  }
174
224
 
175
- // 3. Fused: the commitment inside the bytes, rebuilt from the signed record (fuse/2: and the signed floor block).
225
+ // 3. Fused: the commitment inside the bytes, rebuilt from the signed record (fuse/2 and fuse/3: and the signed floor block).
176
226
  const marker = readFuseAttribution(proof);
177
227
  if (marker !== null && inner === null) {
178
228
  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`);
@@ -180,33 +230,53 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
180
230
  const f = await verifyFuse({ proof, bytes: inner });
181
231
  const good = f.category === "FUSED_DIRECT" || f.category === "CARRIED_INLINE";
182
232
  add("proof.fused", "The bytes carry the position commitment", good ? "TRUE" : "FALSE",
183
- 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",
184
- 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}` : ""}`);
233
+ (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",
234
+ 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}` : ""}`);
185
235
  } else {
186
236
  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");
187
237
  }
188
238
 
189
239
  // 4. The attestation: the hardware's word on which image signed, bound to this proof.
190
- const att = proof.environment?.attestation;
240
+ const env = (proof as { environment?: { measurement?: unknown; attestation?: { format?: unknown; reportB64?: unknown } } }).environment;
241
+ const measurement = typeof env?.measurement === "string" && /^[0-9a-fA-F]+$/.test(env.measurement) ? env.measurement.toLowerCase() : null;
242
+ let attestedAtMs: number | null = null;
243
+ const att = env?.attestation;
191
244
  if (att && att.format === "aws-nitro" && typeof att.reportB64 === "string") {
192
- const n = verifyNitroAttestation(att.reportB64, { expectedPcr0: proof.environment.measurement, expectedUserDataB64: computeSignedBodyHash(proof) });
245
+ const n = verifyNitroAttestation(att.reportB64, { ...(measurement !== null ? { expectedPcr0: measurement } : {}), expectedUserDataB64: computeSignedBodyHash(proof), ...(opts.pins?.rootDer ? { rootDer: opts.pins.rootDer } : {}) });
193
246
  const byName = (prefix: string) => n.checks.find((c) => c.name.startsWith(prefix));
194
247
  const sig = byName("AWS signature"), chain = byName("Certificate chain"), root = byName("Chains to") ?? byName("Trust root"), validity = byName("Certificate validity"), pcr0 = byName("PCR0"), bound = byName("Bound to this proof");
195
248
  const r = (c: { pass: boolean } | undefined): ClaimResult => (c === undefined ? "UNDETERMINED" : c.pass ? "TRUE" : "FALSE");
196
- add("attestation.signature", "AWS hardware signed the attestation", r(sig), "ES384 (P-384)", sig?.detail ?? "not reached");
249
+ // Not a Nitro document at all: that contradicts the proof's own claim to carry one.
250
+ if (n.doc === null) add("attestation.signature", "AWS hardware signed the attestation", "FALSE", "", `the attestation does not decode as an AWS Nitro document (${n.checks[0]?.detail ?? "unreadable"})`);
251
+ else add("attestation.signature", "AWS hardware signed the attestation", r(sig), "ES384 (P-384)", sig?.detail ?? "not reached");
197
252
  add("attestation.chain", "The certificate chain holds together", r(chain), "ES384 (P-384)", chain?.detail ?? "not reached");
198
253
  add("attestation.root", "The chain reaches the AWS Nitro root", r(root), `the AWS Nitro Enclaves Root CA G1 (${n.rootSha256.slice(0, 8)}…)`, root?.detail ?? "not reached");
199
254
  add("attestation.validity", "Every certificate was valid at the document's own instant", r(validity), "the document's signed timestamp", validity?.detail ?? "not reached");
200
- add("attestation.pcr0", "The attested image is the one the proof names", r(pcr0), "PCR0 inside the signed document", pcr0?.detail ?? "not reached");
255
+ if (measurement === null) add("attestation.pcr0", "The attested image is the one the proof names", "FALSE", "", "the proof's environment.measurement is not a hex string, so it names no image");
256
+ else add("attestation.pcr0", "The attested image is the one the proof names", r(pcr0), "PCR0 inside the signed document", pcr0?.detail ?? "not reached");
201
257
  add("attestation.binding", "The attestation is bound to this proof", r(bound), "user_data inside the signed document", bound?.detail ?? "not reached");
202
- const measured = n.doc?.pcrs[0] ?? proof.environment.measurement;
203
- if (opts.pins?.pcr0 && opts.pins.pcr0.length > 0) {
204
- const ok = opts.pins.pcr0.map((x) => x.toLowerCase()).includes(measured.toLowerCase());
205
- add("attestation.pins", "The image is one the verifier accepts", ok ? "TRUE" : "FALSE", "the verifier's own allowlist", ok ? `PCR0 ${measured.slice(0, 16)}… is on the verifier's list` : `PCR0 ${measured.slice(0, 16)}… is not on the verifier's list`);
258
+ // The hardware's word, whole: signature, chain, root, validity, PCR0 and binding all verified.
259
+ const hardwareOk = n.doc !== null && measurement !== null && [sig, chain, root, validity, pcr0, bound].every((c) => c?.pass === true);
260
+ if (sig?.pass && chain?.pass && root?.pass && typeof n.doc?.timestampMs === "number") attestedAtMs = n.doc.timestampMs;
261
+ // The image judged is the one the DOCUMENT attests; the proof's declared measurement is a claim, not evidence.
262
+ const docPcr0 = (n.doc?.pcrs as Record<number, unknown> | undefined)?.[0];
263
+ const measured = typeof docPcr0 === "string" ? docPcr0.toLowerCase() : null;
264
+ const usingDefault = opts.pins?.pcr0 === undefined;
265
+ const policy = (opts.pins?.pcr0 ?? PUBLISHED_PCR0S).map((x) => String(x).toLowerCase());
266
+ if (!hardwareOk || measured === null) {
267
+ add("attestation.pins", "The image is one the verifier accepts", "UNDETERMINED", "", "not judged: the attestation did not verify in full, and a declared measurement is not hardware evidence");
268
+ } else if (policy.length === 0) {
269
+ add("attestation.pins", "The image is one the verifier accepts", "UNDETERMINED", "", `no accepted images were given: PCR0 is ${measured}; any AWS Nitro enclave can produce a valid attestation, and only a measurement policy says whose this is`);
206
270
  } else {
207
- add("attestation.pins", "The image is one the verifier accepts", "UNDETERMINED", "", `no allowlist given: PCR0 is ${measured}; compare it with the measurements BitGraph publishes and rebuild it from source to check`);
271
+ const ok = policy.includes(measured);
272
+ const pub = publishedMeasurement(measured);
273
+ add("attestation.pins", "The image is one the verifier accepts", ok ? "TRUE" : "FALSE",
274
+ usingDefault ? "BitGraph's published enclave images (SPEC section 16)" : "the verifier's own list",
275
+ ok
276
+ ? 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`
277
+ : 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`);
208
278
  }
209
- if (version === 2 && payload.attestation) {
279
+ if (version >= 2 && payload.attestation) {
210
280
  const w = witnessMatchesAttestation(payload.attestation as unknown as AttestationWitness, att.reportB64);
211
281
  add("attestation.witness", "The openssl witness is what the document decodes to", w.ok ? "TRUE" : "FALSE", "recomputed from the attestation document", w.detail);
212
282
  }
@@ -214,21 +284,60 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
214
284
  add("attestation.signature", "AWS hardware signed the attestation", "NOT_CARRIED", "", "the proof carries no aws-nitro attestation");
215
285
  }
216
286
 
217
- // 5. The floor: the anchor proof verifies over its own signed message, and
218
- // it is the anchor the enclave fixed at allocation, matched by identity.
219
- const floorMsg = anchorMessageBytes(payload.floor.anchor);
220
- if (floorMsg.error !== null) add("floor.anchor", "The floor anchor is a genuine anchor proof", "FALSE", "", `floor anchor: ${floorMsg.error}`);
221
- else {
222
- const floorResult = await verify({ proof: payload.floor.anchor as unknown as BitGraphProof, bytes: floorMsg.bytes, context: createVerificationContext() });
223
- 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"}`);
287
+ // 5. The floor. One floor per proof (signedFloorOf); a proof that signs two is ambiguous and floors nothing.
288
+ let signed: SignedFloor | null = null;
289
+ let ambiguous: string | null = null;
290
+ try {
291
+ signed = signedFloorOf(proof);
292
+ } catch (e) {
293
+ ambiguous = (e as Error).message;
294
+ }
295
+ let floorTs: number | null = null;
296
+ let floorChain: "ethereum" | "base" = "ethereum";
297
+ if (payload.floor.basis === "base-header") {
298
+ // v3: the Base header itself, checked against the signed slotFloor. No anchor proof stands under it.
299
+ floorChain = "base";
300
+ const header = payload.floor.header;
301
+ let raw: Uint8Array | null = null;
302
+ try { raw = evmHex(header); } catch { raw = null; }
303
+ const fh = ambiguous !== null || signed === null || raw === null ? null : checkFloorHeader(signed, raw, "base");
304
+ 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 : "");
305
+ 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",
306
+ fh?.ok ? "the header's block number, hash and time equal the signed slotFloor, on Base mainnet's schedule" : why);
307
+ if (fh?.ok) {
308
+ floorTs = fh.header.timestamp;
309
+ 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)}`);
310
+ } else {
311
+ add("floor.header", "The floor block's header is the one with that hash", "FALSE", "", `floor header: ${why}`);
312
+ }
313
+ } else {
314
+ // v1, v2: the anchor proof verifies over its own signed message, and it
315
+ // is the anchor the enclave fixed at allocation, matched by identity.
316
+ const floorMsg = anchorMessageBytes(payload.floor.anchor);
317
+ if (floorMsg.error !== null) add("floor.anchor", "The floor anchor is a genuine anchor proof", "FALSE", "", `floor anchor: ${floorMsg.error}`);
318
+ else {
319
+ const floorResult = await verify({ proof: payload.floor.anchor as unknown as BitGraphProof, bytes: floorMsg.bytes, context: createVerificationContext() });
320
+ 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"}`);
321
+ }
322
+ const floorBind = ambiguous !== null ? [ambiguous]
323
+ : signed?.chain === "base" ? ["the proof signs a Base floor (commit.slotFloor), and this block carries an Ethereum anchor as its floor"]
324
+ : checkFloorBinding(payload.proof, payload.floor);
325
+ 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("; "));
326
+ const floorWitness = verifyWitnessHeader(payload.floor.witness);
327
+ floorTs = floorWitness.ok ? floorWitness.timestamp : null;
328
+ 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}`);
329
+ }
330
+ // The floor's time is a bound only when it is no later than the attestation document (review, 2026-10-06).
331
+ let floorTimeWithheld: string | null = null;
332
+ if (floorTs !== null) {
333
+ const bound = floorTimeIsBound(floorTs, attestedAtMs);
334
+ if (!bound.ok) floorTimeWithheld = bound.reason;
224
335
  }
225
- const floorBind = checkFloorBinding(payload.proof, payload.floor);
226
- 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("; "));
227
- const floorWitness = verifyWitnessHeader(payload.floor.witness);
228
- 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}`);
229
336
 
230
- // 6. The ceiling in position, only when the carrier claims one.
231
- if (payload.ceiling.status === "present") {
337
+ // 6. The ceiling in position: v1 and v2 when the carrier claims one; v3 has none.
338
+ if (payload.ceiling.status === "none") {
339
+ 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");
340
+ } else if (payload.ceiling.status === "present") {
232
341
  const ceilMsg = anchorMessageBytes(payload.ceiling.anchor);
233
342
  if (ceilMsg.error !== null) add("ceiling.position.anchor", "The closing anchor is a genuine anchor proof", "FALSE", "", `ceiling anchor: ${ceilMsg.error}`);
234
343
  else {
@@ -243,10 +352,11 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
243
352
  add("ceiling.position.binding", "The record was committed before the closing anchor", "NOT_CARRIED", "", "closing anchor not fetched: the floor stands on its own");
244
353
  }
245
354
 
246
- // 7. v2: the ceiling in time, the Base block the record existed by.
355
+ // 7. v2 and v3: the ceiling in time, the Base block the record existed by.
247
356
  let ceilingTime: { blockNumber: number; blockHash: string; blockTimestamp: number; status: string } | null = null;
357
+ let baseTimeWithheld: string | null = null;
248
358
  let sidecar: CeilingSidecar | null = null;
249
- if (version === 2) {
359
+ if (version >= 2) {
250
360
  const ct = payload.ceilingInTime;
251
361
  if (ct && ct.status === "present") {
252
362
  sidecar = ct.sidecar as unknown as CeilingSidecar;
@@ -257,16 +367,21 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
257
367
  add("ceiling.time.payload", "The transaction carries that root", r(byName("payload")), "the 84-byte BGC1 payload", byName("payload")?.detail ?? c.reason ?? "not reached");
258
368
  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");
259
369
  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");
260
- 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");
370
+ 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");
261
371
  const win = c.ok ? c.window?.ceiling : undefined;
262
- if (win) ceilingTime = { blockNumber: win.blockNumber, blockHash: win.blockHash, blockTimestamp: win.blockTimestamp, status: c.status ?? "included" };
372
+ if (win) {
373
+ // The inclusion holds either way; a stamp that cannot be a bound is withheld as a time.
374
+ const stamp = baseTimeIsBound(win.blockTimestamp, { floorTimestampSec: floorTs ?? c.window?.floor.blockTimestamp ?? null, attestedAtMs });
375
+ if (stamp.ok) ceilingTime = { blockNumber: win.blockNumber, blockHash: win.blockHash, blockTimestamp: win.blockTimestamp, status: c.status ?? "included" };
376
+ else baseTimeWithheld = stamp.reason;
377
+ }
263
378
  if (!c.ok && c.reason) add("ceiling.time", "The ceiling in time holds together", "FALSE", "", c.reason);
264
379
  add("ceiling.time.status", "How far Base had settled the block", "UNDETERMINED", "", `the sidecar says "${sidecar.status}", as BitGraph's Base node reported when the file was written; not proven by the file. Settlement below is the proof, when carried.`);
265
380
  } else {
266
381
  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");
267
382
  }
268
383
 
269
- // 8. v2: settlement on Ethereum, when carried.
384
+ // 8. v2 and v3: settlement on Ethereum, when carried.
270
385
  const st = payload.settlement;
271
386
  if (st && st.status === "present") {
272
387
  const pointer = st.pointer as unknown as SettlementPointer;
@@ -287,19 +402,28 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
287
402
  // 9. The declared pins, compared with the verifier's.
288
403
  if (payload.pins) {
289
404
  const notes: string[] = [];
290
- if (payload.pins.pcr0 && payload.pins.pcr0.toLowerCase() !== proof.environment.measurement.toLowerCase()) notes.push("the declared PCR0 is not the proof's measurement");
405
+ if (payload.pins.pcr0 && String(payload.pins.pcr0).toLowerCase() !== String(proof.environment?.measurement).toLowerCase()) notes.push("the declared PCR0 is not the proof's measurement");
291
406
  if (payload.pins.ceilingWriter && payload.pins.ceilingWriter.toLowerCase() !== pinnedWriter.toLowerCase()) notes.push(`the declared ceiling writer ${payload.pins.ceilingWriter} is not the verifier's pin`);
292
407
  if (payload.pins.chains?.base !== undefined && payload.pins.chains.base !== baseChainId) notes.push(`the declared Base chain ${payload.pins.chains.base} is not the verifier's`);
293
408
  add("pins", "What the file says it was made under agrees with this verifier's pins", notes.length === 0 ? "TRUE" : "FALSE", "the verifier's own pins", notes.length === 0 ? "declared pins match; they were never used as authority" : notes.join("; "));
294
409
  }
295
410
  }
296
411
 
297
- // 10. Confirmed: the block hashes against nodes the caller named.
412
+ // 10. Confirmed: the block hashes against nodes the caller named. The floor
413
+ // is asked of its own chain, by height: the chain's block at N must be
414
+ // the one the header hashes to.
298
415
  const lk = opts.lookups;
416
+ const nb = carrierBounds(payload).notBefore;
417
+ const floorAsk = floorChain === "base" ? lk?.baseBlockHash : lk?.ethereumBlockHash;
418
+ const floorChainName = floorChain === "base" ? "Base" : "Ethereum";
419
+ if (floorAsk) {
420
+ const h = (await safe(() => floorAsk(nb.blockNumber)))?.toLowerCase();
421
+ const ok = h === nb.blockHash;
422
+ 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");
423
+ } else {
424
+ 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");
425
+ }
299
426
  if (lk?.ethereumBlockHash) {
300
- const h = (await safe(() => lk.ethereumBlockHash!(payload.floor.witness.blockNumber)))?.toLowerCase();
301
- const ok = h === payload.floor.witness.blockHash.toLowerCase();
302
- 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");
303
427
  const pc = payload.ceiling;
304
428
  if (pc.status === "present") {
305
429
  const h2 = (await safe(() => lk.ethereumBlockHash!(pc.witness.blockNumber)))?.toLowerCase();
@@ -311,8 +435,6 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
311
435
  const r = await checkSettlementOnline(st.pointer as unknown as SettlementPointer, lk.ethereumBlockHash);
312
436
  add("confirmed.settlement", "The settling Ethereum block is Ethereum's own", r.ok ? "TRUE" : "FALSE", "the Ethereum node the caller named", r.detail, "confirmed");
313
437
  }
314
- } else {
315
- 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");
316
438
  }
317
439
  if (sidecar) {
318
440
  if (lk?.baseBlockHash) {
@@ -324,17 +446,27 @@ export async function verifyCarrierPayload(payload: CarrierPayload, inner: Uint8
324
446
  }
325
447
 
326
448
  const reasons = claims.filter((c) => c.result === "FALSE").map((c) => `${c.name}: ${c.detail}`);
327
- const verdict: CarrierVerifyResult["verdict"] = reasons.length > 0 ? "FALSE" : "TRUE";
449
+ // TRUE needs the image to be one the verifier accepts: an attestation alone
450
+ // says only that some AWS Nitro enclave signed.
451
+ const pins = claims.find((c) => c.id === "attestation.pins");
452
+ 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");
453
+ const verdict: CarrierVerifyResult["verdict"] = claims.some((c) => c.result === "FALSE") ? "FALSE" : pins?.result === "TRUE" ? "TRUE" : "UNDETERMINED";
328
454
  const bounds = carrierBounds(payload);
455
+ // The ceiling in time reaches callers only as verified here, and only when its stamp is a bound.
456
+ bounds.existedBy = ceilingTime ? { chain: "base", blockNumber: ceilingTime.blockNumber, blockHash: ceilingTime.blockHash, timestamp: ceilingTime.blockTimestamp } : null;
457
+ // So does the floor's time: from a verified header, and only when it is a bound.
458
+ bounds.notBefore.timestamp = floorTimeWithheld === null ? floorTs : null;
329
459
  return {
330
460
  verdict,
461
+ baseTimeWithheld,
462
+ floorTimeWithheld,
331
463
  carrier: "ok",
332
464
  version,
333
465
  reasons,
334
466
  bounds,
335
467
  ceiling: payload.ceiling.status,
336
468
  claims,
337
- reading: writeReading(verdict, claims, bounds, proof, ceilingTime, floorWitness.timestamp),
469
+ reading: writeReading(verdict, claims, bounds, proof, ceilingTime, bounds.notBefore.timestamp, baseTimeWithheld, floorTimeWithheld),
338
470
  payload,
339
471
  inner,
340
472
  };
@@ -359,6 +491,8 @@ function writeReading(
359
491
  proof: BitGraphProof,
360
492
  ceilingTime: { blockNumber: number; blockHash: string; blockTimestamp: number } | null,
361
493
  floorTs: number | null,
494
+ baseTimeWithheld: string | null = null,
495
+ floorTimeWithheld: string | null = null,
362
496
  ): string {
363
497
  const get = (id: string) => claims.find((c) => c.id === id);
364
498
  if (verdict === "FALSE") {
@@ -368,20 +502,26 @@ function writeReading(
368
502
  const position = proof.commit?.counter ?? "?";
369
503
  const epoch = (proof.commit?.epochId ?? "").replace(/=+$/, "").slice(0, 8);
370
504
  const fused = get("proof.fused");
371
- const after = floorTs !== null ? `made after Ethereum block ${bounds.notBefore.blockNumber} (${iso(floorTs)})` : `made after Ethereum block ${bounds.notBefore.blockNumber}`;
505
+ const floorChain = bounds.notBefore.chain === "base" ? "Base" : "Ethereum";
506
+ const after = floorTs !== null ? `Recorded after ${floorChain} block ${bounds.notBefore.blockNumber} (${iso(floorTs)})` : `Recorded after ${floorChain} block ${bounds.notBefore.blockNumber}`;
372
507
  const by = ceilingTime ? `, and existed by Base block ${ceilingTime.blockNumber} (${iso(ceilingTime.blockTimestamp)})` : "";
373
508
  const settled = bounds.settledBy ? `, whose batch data Ethereum committed in block ${bounds.settledBy.blockNumber} (${iso(bounds.settledBy.timestamp)})` : "";
374
- const before = bounds.notAfter ? `; committed before the anchoring of Ethereum block ${bounds.notAfter.blockNumber}, a bound in position` : "";
509
+ const before = bounds.notAfter
510
+ ? `; committed before the anchoring of Ethereum block ${bounds.notAfter.blockNumber}, a bound in position`
511
+ : get("ceiling.position") ? "; its order among BitGraphs is the chain of proof hashes" : "";
375
512
  const digest = get("bytes.digest");
513
+ // Two floors (SPEC 8.6): every record has the record floor; only bytes that
514
+ // carry the commitment have the content floor. Without it, the bytes
515
+ // themselves are not dated.
376
516
  const subject = digest?.result !== "TRUE"
377
- ? "The bytes this proof names were committed"
517
+ ? "The bytes this proof names were committed under this position."
378
518
  : fused?.result === "TRUE"
379
- ? (fused.restsOn.includes("floor block") ? "These exact bytes were finished after the floor block existed" : "These exact bytes were finished after their position was opened")
380
- : "These exact bytes were committed";
519
+ ? (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).")
520
+ : "These exact bytes carry no commitment, so the bytes themselves are not dated (the record floor only).";
381
521
  const att = get("attestation.root");
382
522
  const rests: string[] = ["SHA-256", "Ed25519"];
383
523
  if (att?.result === "TRUE") rests.push(`the AWS Nitro root (${awsNitroRootSha256().slice(0, 8)}…)`);
384
- rests.push(`Ethereum block ${bounds.notBefore.blockNumber}`);
524
+ rests.push(`${floorChain} block ${bounds.notBefore.blockNumber}`);
385
525
  if (ceilingTime) rests.push(`Base block ${ceilingTime.blockNumber}`);
386
526
  if (bounds.settledBy) rests.push(`Ethereum block ${bounds.settledBy.blockNumber}`);
387
527
  const confirmed = claims.filter((c) => c.level === "confirmed");
@@ -390,6 +530,9 @@ function writeReading(
390
530
  ? "Every block was confirmed against a node, so nothing here rests on a header taken as given."
391
531
  : "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.";
392
532
  const pins = get("attestation.pins");
393
- const pinLine = pins?.result === "TRUE" ? " The enclave image is one this verifier accepts." : pins?.result === "UNDETERMINED" ? ` The enclave image's PCR0 is ${proof.environment.measurement.slice(0, 16)}…; compare it with BitGraph's published measurements.` : "";
394
- return `${subject}: ${after}${by}${settled}${before}. Position ${position} of epoch ${epoch}…. Rests on: ${rests.join(", ")}. ${tail}${pinLine}`;
533
+ 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." : "";
534
+ const withheld = (floorTimeWithheld ? ` The floor block's time is not used as a bound: ${floorTimeWithheld}.` : "")
535
+ + (baseTimeWithheld ? ` The record is in a Base block, but its time is not used as a bound: ${baseTimeWithheld}.` : "");
536
+ const lead = verdict === "UNDETERMINED" ? "Not judged in full. " : "";
537
+ return `${lead}${subject} ${after}${by}${settled}${before}. Position ${position} of epoch ${epoch}…. Rests on: ${rests.join(", ")}. ${tail}${withheld}${pinLine}`;
395
538
  }