@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,20 +1,28 @@
1
1
  // Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
2
2
  /**
3
- * verifyCarrier — the offline read path for a BitGraphed file (bitgraph-carrier/1
4
- * or /2), one result per claim, each saying what it rests on.
3
+ * verifyCarrier: the offline read path for a BitGraphed file (bitgraph-carrier/1,
4
+ * /2, /3 or /4), one result per claim, each saying what it rests on.
5
5
  *
6
6
  * Given the file and nothing else, it strips the block by structure and checks:
7
7
  *
8
- * the bytes SHA-256 of the committed bytes is the digest the proof names
8
+ * the bytes SHA-256 of the committed bytes is the digest the proof names; on v4
9
+ * (one member of a tree/1 BitGraph) it is the leaf's artifact digest, a
10
+ * placed leaf's bytes carry the commitment, the path reaches the root, and
11
+ * the root document carries that root and the position's commitment and
12
+ * hashes to the signed digest (verifyTreeMember), under a spec it knows
9
13
  * the proof Ed25519 signature, the position record and its bindings, the
10
- * fused commitment rebuilt (bitgraph-fuse/1 or /2), proofHash
14
+ * fused commitment rebuilt (bitgraph-fuse/1, /2 or /3), proofHash
11
15
  * the attestation ES384 signature, the certificate chain to the AWS Nitro root
12
16
  * (641A0321…), validity at the document's own instant, PCR0 against
13
17
  * the proof's measurement, user_data against the signed body; and,
14
18
  * on a v2 block, the openssl-checkable witness against the document
15
- * the floor the anchor proof named by the signed slotAnchor, verified over its
16
- * own message, matched by identity; its Ethereum header recomputed
17
- * the ceilings in position: the next anchor, same checks; in time (v2): the Base
19
+ * the floor v1, v2: the anchor proof named by the signed slotAnchor, verified over
20
+ * its own message, matched by identity; its Ethereum header recomputed.
21
+ * v3: the Base header, checked against the signed slotFloor (hash,
22
+ * number, time, Base mainnet's schedule). Either way the floor's time
23
+ * is a bound only when no later than the attestation document.
24
+ * the ceilings in position (v1, v2): the next anchor, same checks; v3 has none, its
25
+ * order is the chain of proof hashes; in time (v2, v3): the Base
18
26
  * sidecar's whole chain of custody (verifyCeiling); settled (v2): the
19
27
  * Ethereum block that committed the batch data (verifySettlementPointer)
20
28
  * the pins what the file declares it was made under, against the verifier's own
@@ -35,14 +43,16 @@
35
43
  */
36
44
  import { verify, verifyProofIntegrity, createVerificationContext } from "./verifier.js";
37
45
  import { verifyFuse } from "./fuse-verify.js";
38
- import { readFuseAttribution } from "./fuse.js";
46
+ import { readFuseAttribution, signedFloorOf, hexToBytes as treeHex } from "./fuse.js";
47
+ import { verifyTreeMember, TREE_MEMBER_CATEGORIES } from "./tree.js";
39
48
  import { computeProofHash, computeSignedBodyHash } from "./proof-hash.js";
40
49
  import { verifyNitroAttestation, witnessMatchesAttestation, awsNitroRootSha256 } from "./nitro.js";
41
- import { baseTimeIsBound, verifyCeiling, checkCeilingOnline } from "./ceiling.js";
50
+ import { baseTimeIsBound, checkFloorHeader, floorTimeIsBound, verifyCeiling, checkCeilingOnline } from "./ceiling.js";
51
+ import { hexToBytes as evmHex } from "./ceiling-evm.js";
42
52
  import { PUBLISHED_PCR0S, publishedMeasurement } from "./measurements.js";
43
53
  import { verifySettlementPointer, checkSettlementOnline, BASE_MAINNET_SETTLEMENT_PINS } from "./settlement.js";
44
54
  import { sha256 } from "@noble/hashes/sha256";
45
- import { parseCarrier, checkFloorBinding, checkCeilingBinding, anchorMessageBytes, verifyWitnessHeader, carrierBounds, innerDigestMatches, carrierVersionOf, } from "./carrier.js";
55
+ import { parseCarrier, checkFloorBinding, checkCeilingBinding, anchorMessageBytes, verifyWitnessHeader, carrierBounds, innerDigestMatches, carrierVersionOf, CARRIER_VERSION_4, } from "./carrier.js";
46
56
  /** BitGraph's published ceiling writer on Base mainnet: the default pin a verifier compares with. */
47
57
  export const BITGRAPH_CEILING_WRITER = "0xf3972408D853c975F86351C311f4310220bbF2a3";
48
58
  export const BASE_MAINNET_CHAIN_ID = 8453;
@@ -58,7 +68,7 @@ export async function verifyCarrier(bytes, opts = {}) {
58
68
  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 };
59
69
  }
60
70
  const result = await verifyCarrierPayload(parsed.payload, parsed.inner, opts);
61
- return { ...result, reading: `${result.reading} ${envelopeSentence(bytes, parsed.inner)}` };
71
+ return { ...result, reading: `${result.reading} ${envelopeSentence(bytes, parsed.inner, parsed.payload.carrier === CARRIER_VERSION_4)}` };
62
72
  }
63
73
  /**
64
74
  * THE ENVELOPE RULE, said out loud (outside review, 2026-10-02: "confirm the verify output
@@ -66,8 +76,10 @@ export async function verifyCarrier(bytes, opts = {}) {
66
76
  * that file travels without the README"). A reader who hashes the file they were handed
67
77
  * and compares it with the proof would otherwise conclude the proof is wrong.
68
78
  */
69
- function envelopeSentence(outer, inner) {
79
+ function envelopeSentence(outer, inner, member = false) {
70
80
  const hex = (b) => Array.from(sha256(b), (x) => x.toString(16).padStart(2, "0")).join("");
81
+ if (member)
82
+ 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.`;
71
83
  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.`;
72
84
  }
73
85
  /**
@@ -101,7 +113,7 @@ export async function verifyCarrierPayload(payload, inner, opts = {}) {
101
113
  version,
102
114
  reasons: claims.filter((c) => c.result === "FALSE").map((c) => `${c.name}: ${c.detail}`),
103
115
  bounds: null,
104
- ceiling: ceilingStatus === "present" || ceilingStatus === "unfetched" ? ceilingStatus : null,
116
+ ceiling: ceilingStatus === "present" || ceilingStatus === "unfetched" || ceilingStatus === "none" ? ceilingStatus : null,
105
117
  claims,
106
118
  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.`,
107
119
  payload,
@@ -116,8 +128,13 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
116
128
  const baseChainId = opts.pins?.baseChainId ?? BASE_MAINNET_CHAIN_ID;
117
129
  if (inner !== null)
118
130
  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`);
119
- // 1. The committed bytes are the ones the proof names.
120
- if (inner !== null) {
131
+ const isMember = version === 4;
132
+ // 1. The committed bytes are the ones the proof names. On v4 they are a
133
+ // tree member's, checked against its leaf in step 3.
134
+ if (isMember) {
135
+ // below, with the tree
136
+ }
137
+ else if (inner !== null) {
121
138
  const digestOk = innerDigestMatches(inner, payload);
122
139
  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");
123
140
  }
@@ -127,7 +144,9 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
127
144
  // 2. The proof itself, under the existing bitgraph/1 algorithm. A fresh
128
145
  // context: a carrier is judged alone, not against this process's history.
129
146
  // Without the bytes, the integrity half runs (verify() without bytes).
130
- const proofResult = inner !== null
147
+ // On v4 the signed digest names the root document, never the bytes, so
148
+ // the integrity half runs and the tree binds the bytes (step 3).
149
+ const proofResult = inner !== null && !isMember
131
150
  ? await verify({ proof, bytes: inner, context: createVerificationContext() })
132
151
  : await verifyProofIntegrity({ proof, context: createVerificationContext() });
133
152
  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"}`);
@@ -136,15 +155,22 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
136
155
  const ok = computeProofHash(proof) === ph;
137
156
  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");
138
157
  }
139
- // 3. Fused: the commitment inside the bytes, rebuilt from the signed record (fuse/2: and the signed floor block).
158
+ // 3. Fused: the commitment inside the bytes, rebuilt from the signed record (fuse/2 and fuse/3: and the signed floor block).
159
+ // v4: the tree. The spec the proof pins, the root document against the
160
+ // signed digest and the position's commitment, the path, the bytes
161
+ // against the leaf, and for a placed leaf the commitment in the bytes.
140
162
  const marker = readFuseAttribution(proof);
141
- if (marker !== null && inner === null) {
163
+ let tr = null;
164
+ if (isMember) {
165
+ tr = await memberClaims(payload, proof, inner, opts, add);
166
+ }
167
+ else if (marker !== null && inner === null) {
142
168
  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`);
143
169
  }
144
170
  else if (marker !== null && inner !== null) {
145
171
  const f = await verifyFuse({ proof, bytes: inner });
146
172
  const good = f.category === "FUSED_DIRECT" || f.category === "CARRIED_INLINE";
147
- add("proof.fused", "The bytes carry the position commitment", good ? "TRUE" : "FALSE", 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", 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}` : ""}`);
173
+ add("proof.fused", "The bytes carry the position commitment", good ? "TRUE" : "FALSE", (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", 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}` : ""}`);
148
174
  }
149
175
  else {
150
176
  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");
@@ -194,7 +220,7 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
194
220
  ? 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`
195
221
  : 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`);
196
222
  }
197
- if (version === 2 && payload.attestation) {
223
+ if (version >= 2 && payload.attestation) {
198
224
  const w = witnessMatchesAttestation(payload.attestation, att.reportB64);
199
225
  add("attestation.witness", "The openssl witness is what the document decodes to", w.ok ? "TRUE" : "FALSE", "recomputed from the attestation document", w.detail);
200
226
  }
@@ -202,21 +228,69 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
202
228
  else {
203
229
  add("attestation.signature", "AWS hardware signed the attestation", "NOT_CARRIED", "", "the proof carries no aws-nitro attestation");
204
230
  }
205
- // 5. The floor: the anchor proof verifies over its own signed message, and
206
- // it is the anchor the enclave fixed at allocation, matched by identity.
207
- const floorMsg = anchorMessageBytes(payload.floor.anchor);
208
- if (floorMsg.error !== null)
209
- add("floor.anchor", "The floor anchor is a genuine anchor proof", "FALSE", "", `floor anchor: ${floorMsg.error}`);
231
+ // 5. The floor. One floor per proof (signedFloorOf); a proof that signs two is ambiguous and floors nothing.
232
+ let signed = null;
233
+ let ambiguous = null;
234
+ try {
235
+ signed = signedFloorOf(proof);
236
+ }
237
+ catch (e) {
238
+ ambiguous = e.message;
239
+ }
240
+ let floorTs = null;
241
+ let floorChain = "ethereum";
242
+ if (payload.floor.basis === "base-header") {
243
+ // v3: the Base header itself, checked against the signed slotFloor. No anchor proof stands under it.
244
+ floorChain = "base";
245
+ const header = payload.floor.header;
246
+ let raw = null;
247
+ try {
248
+ raw = evmHex(header);
249
+ }
250
+ catch {
251
+ raw = null;
252
+ }
253
+ const fh = ambiguous !== null || signed === null || raw === null ? null : checkFloorHeader(signed, raw, "base");
254
+ 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 : "");
255
+ 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", fh?.ok ? "the header's block number, hash and time equal the signed slotFloor, on Base mainnet's schedule" : why);
256
+ if (fh?.ok) {
257
+ floorTs = fh.header.timestamp;
258
+ 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)}`);
259
+ }
260
+ else {
261
+ add("floor.header", "The floor block's header is the one with that hash", "FALSE", "", `floor header: ${why}`);
262
+ }
263
+ }
210
264
  else {
211
- const floorResult = await verify({ proof: payload.floor.anchor, bytes: floorMsg.bytes, context: createVerificationContext() });
212
- 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"}`);
213
- }
214
- const floorBind = checkFloorBinding(payload.proof, payload.floor);
215
- 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("; "));
216
- const floorWitness = verifyWitnessHeader(payload.floor.witness);
217
- 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}`);
218
- // 6. The ceiling in position, only when the carrier claims one.
219
- if (payload.ceiling.status === "present") {
265
+ // v1, v2: the anchor proof verifies over its own signed message, and it
266
+ // is the anchor the enclave fixed at allocation, matched by identity.
267
+ const floorMsg = anchorMessageBytes(payload.floor.anchor);
268
+ if (floorMsg.error !== null)
269
+ add("floor.anchor", "The floor anchor is a genuine anchor proof", "FALSE", "", `floor anchor: ${floorMsg.error}`);
270
+ else {
271
+ const floorResult = await verify({ proof: payload.floor.anchor, bytes: floorMsg.bytes, context: createVerificationContext() });
272
+ 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"}`);
273
+ }
274
+ const floorBind = ambiguous !== null ? [ambiguous]
275
+ : signed?.chain === "base" ? ["the proof signs a Base floor (commit.slotFloor), and this block carries an Ethereum anchor as its floor"]
276
+ : checkFloorBinding(payload.proof, payload.floor);
277
+ 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("; "));
278
+ const floorWitness = verifyWitnessHeader(payload.floor.witness);
279
+ floorTs = floorWitness.ok ? floorWitness.timestamp : null;
280
+ 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}`);
281
+ }
282
+ // The floor's time is a bound only when it is no later than the attestation document (review, 2026-10-06).
283
+ let floorTimeWithheld = null;
284
+ if (floorTs !== null) {
285
+ const bound = floorTimeIsBound(floorTs, attestedAtMs);
286
+ if (!bound.ok)
287
+ floorTimeWithheld = bound.reason;
288
+ }
289
+ // 6. The ceiling in position: v1 and v2 when the carrier claims one; v3 has none.
290
+ if (payload.ceiling.status === "none") {
291
+ 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");
292
+ }
293
+ else if (payload.ceiling.status === "present") {
220
294
  const ceilMsg = anchorMessageBytes(payload.ceiling.anchor);
221
295
  if (ceilMsg.error !== null)
222
296
  add("ceiling.position.anchor", "The closing anchor is a genuine anchor proof", "FALSE", "", `ceiling anchor: ${ceilMsg.error}`);
@@ -232,11 +306,11 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
232
306
  else {
233
307
  add("ceiling.position.binding", "The record was committed before the closing anchor", "NOT_CARRIED", "", "closing anchor not fetched: the floor stands on its own");
234
308
  }
235
- // 7. v2: the ceiling in time, the Base block the record existed by.
309
+ // 7. v2 and v3: the ceiling in time, the Base block the record existed by.
236
310
  let ceilingTime = null;
237
311
  let baseTimeWithheld = null;
238
312
  let sidecar = null;
239
- if (version === 2) {
313
+ if (version >= 2) {
240
314
  const ct = payload.ceilingInTime;
241
315
  if (ct && ct.status === "present") {
242
316
  sidecar = ct.sidecar;
@@ -247,11 +321,11 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
247
321
  add("ceiling.time.payload", "The transaction carries that root", r(byName("payload")), "the 84-byte BGC1 payload", byName("payload")?.detail ?? c.reason ?? "not reached");
248
322
  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");
249
323
  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");
250
- 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");
324
+ 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");
251
325
  const win = c.ok ? c.window?.ceiling : undefined;
252
326
  if (win) {
253
327
  // The inclusion holds either way; a stamp that cannot be a bound is withheld as a time.
254
- const stamp = baseTimeIsBound(win.blockTimestamp, { floorTimestampSec: floorWitness.timestamp ?? c.window?.floor.blockTimestamp ?? null, attestedAtMs });
328
+ const stamp = baseTimeIsBound(win.blockTimestamp, { floorTimestampSec: floorTs ?? c.window?.floor.blockTimestamp ?? null, attestedAtMs });
255
329
  if (stamp.ok)
256
330
  ceilingTime = { blockNumber: win.blockNumber, blockHash: win.blockHash, blockTimestamp: win.blockTimestamp, status: c.status ?? "included" };
257
331
  else
@@ -264,7 +338,7 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
264
338
  else {
265
339
  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");
266
340
  }
267
- // 8. v2: settlement on Ethereum, when carried.
341
+ // 8. v2 and v3: settlement on Ethereum, when carried.
268
342
  const st = payload.settlement;
269
343
  if (st && st.status === "present") {
270
344
  const pointer = st.pointer;
@@ -294,12 +368,22 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
294
368
  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("; "));
295
369
  }
296
370
  }
297
- // 10. Confirmed: the block hashes against nodes the caller named.
371
+ // 10. Confirmed: the block hashes against nodes the caller named. The floor
372
+ // is asked of its own chain, by height: the chain's block at N must be
373
+ // the one the header hashes to.
298
374
  const lk = opts.lookups;
375
+ const nb = carrierBounds(payload).notBefore;
376
+ const floorAsk = floorChain === "base" ? lk?.baseBlockHash : lk?.ethereumBlockHash;
377
+ const floorChainName = floorChain === "base" ? "Base" : "Ethereum";
378
+ if (floorAsk) {
379
+ const h = (await safe(() => floorAsk(nb.blockNumber)))?.toLowerCase();
380
+ const ok = h === nb.blockHash;
381
+ 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");
382
+ }
383
+ else {
384
+ 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");
385
+ }
299
386
  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
387
  const pc = payload.ceiling;
304
388
  if (pc.status === "present") {
305
389
  const h2 = (await safe(() => lk.ethereumBlockHash(pc.witness.blockNumber)))?.toLowerCase();
@@ -312,9 +396,6 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
312
396
  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
397
  }
314
398
  }
315
- else {
316
- 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");
317
- }
318
399
  if (sidecar) {
319
400
  if (lk?.baseBlockHash) {
320
401
  const r = await checkCeilingOnline(sidecar, lk.baseBlockHash);
@@ -330,24 +411,95 @@ async function verifyCarrierPayloadChecks(payload, inner, opts, claims, add) {
330
411
  const pins = claims.find((c) => c.id === "attestation.pins");
331
412
  if (reasons.length === 0 && pins?.result !== "TRUE")
332
413
  reasons.push(pins ? `${pins.name}: ${pins.detail}` : "The image is one the verifier accepts: the proof carries no attestation, so no image was established");
333
- const verdict = claims.some((c) => c.result === "FALSE") ? "FALSE" : pins?.result === "TRUE" ? "TRUE" : "UNDETERMINED";
414
+ // v4: a tree this verifier could not judge (a spec it does not know) is not judged, never TRUE.
415
+ const treeUnjudged = isMember ? claims.filter((c) => TREE_CLAIM_IDS.includes(c.id) && c.result === "UNDETERMINED") : [];
416
+ if (reasons.length === 0)
417
+ for (const c of treeUnjudged)
418
+ reasons.push(`${c.name}: ${c.detail}`);
419
+ const verdict = claims.some((c) => c.result === "FALSE") ? "FALSE" : pins?.result === "TRUE" && treeUnjudged.length === 0 ? "TRUE" : "UNDETERMINED";
334
420
  const bounds = carrierBounds(payload);
335
421
  // The ceiling in time reaches callers only as verified here, and only when its stamp is a bound.
336
422
  bounds.existedBy = ceilingTime ? { chain: "base", blockNumber: ceilingTime.blockNumber, blockHash: ceilingTime.blockHash, timestamp: ceilingTime.blockTimestamp } : null;
423
+ // So does the floor's time: from a verified header, and only when it is a bound.
424
+ bounds.notBefore.timestamp = floorTimeWithheld === null ? floorTs : null;
337
425
  return {
338
426
  verdict,
339
427
  baseTimeWithheld,
428
+ floorTimeWithheld,
340
429
  carrier: "ok",
341
430
  version,
342
431
  reasons,
343
432
  bounds,
344
433
  ceiling: payload.ceiling.status,
345
434
  claims,
346
- reading: writeReading(verdict, claims, bounds, proof, ceilingTime, floorWitness.timestamp, baseTimeWithheld),
435
+ member: tr?.member ?? null,
436
+ floorCovers: tr && TREE_MEMBER_CATEGORIES.includes(tr.category) ? tr.floorCovers : null,
437
+ reading: writeReading(verdict, claims, bounds, proof, ceilingTime, bounds.notBefore.timestamp, baseTimeWithheld, floorTimeWithheld, tr),
347
438
  payload,
348
439
  inner,
349
440
  };
350
441
  }
442
+ /** The claims a v4 block adds in place of the digest and fused lines; their verdict weight is checked by id. */
443
+ const TREE_CLAIM_IDS = ["spec.pin", "tree.root", "tree.member", "bytes.digest"];
444
+ /**
445
+ * v4: the bytes, as one member of the tree the proof commits. Five claims, in
446
+ * export/1's words: the spec pin, the root document, the member's path, the
447
+ * bytes against the leaf, and (as proof.fused, the content floor) the
448
+ * commitment inside a placed leaf's bytes. A leaf kept as is carries no
449
+ * commitment: recorded after the floor block, the bytes themselves are not
450
+ * dated. The bytes must be the leaf's COMMITTED bytes: an original that would
451
+ * rebuild them is not what a BitGraphed file carries, and is refused.
452
+ */
453
+ async function memberClaims(payload, proof, inner, opts, add) {
454
+ const t = payload.tree;
455
+ const rootDocument = treeHex(t.rootDocument) ?? new Uint8Array(0);
456
+ // The proof's own check is its own claim (step 2); the tree is judged on its own evidence.
457
+ const tr = await verifyTreeMember({
458
+ proof,
459
+ ...(inner !== null ? { bytes: inner } : {}),
460
+ member: t.member,
461
+ rootDocument,
462
+ ...(opts.extraSpecHashes ? { extraSpecHashes: opts.extraSpecHashes } : {}),
463
+ proofAlreadyVerified: true,
464
+ });
465
+ const unknownSpec = tr.category === "UNKNOWN_SPEC";
466
+ const notTree = tr.category === "NOT_TREE";
467
+ const specOk = !unknownSpec && !notTree && tr.category !== "INVALID_TREE_MARKER";
468
+ add("spec.pin", "The proof pins a spec this verifier knows", specOk ? "TRUE" : unknownSpec ? "UNDETERMINED" : "FALSE", "the signed attribution.message", 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);
469
+ const rootOk = tr.tree !== null;
470
+ add("tree.root", "The root document is the signed one and carries this position's commitment", rootOk ? "TRUE" : unknownSpec ? "UNDETERMINED" : "FALSE", "SHA-256 over the signed position record, its nonce and the signed floor block hash", 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);
471
+ const pathOk = tr.member !== null;
472
+ add("tree.member", "The member's leaf is in the committed tree", pathOk ? "TRUE" : rootOk ? "FALSE" : "UNDETERMINED", "SHA-256 (RFC 9162 path)", 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");
473
+ const where = tr.member ? `leaf ${tr.member.index} of ${tr.member.count}` : `leaf ${t.member.index} of ${t.member.count}`;
474
+ const asIs = tr.member?.placement === "as-is" || /^00/.test(t.member.leaf);
475
+ if (inner === null) {
476
+ 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)}`);
477
+ add("proof.fused", "The committed bytes carry the position commitment", "NOT_CARRIED", "", asIs
478
+ ? "the member was kept as is: the bytes carry no commitment, so the bytes themselves are not dated"
479
+ : "the file is not in hand; its bytes carry the position commitment to check");
480
+ return tr;
481
+ }
482
+ const isMember = TREE_MEMBER_CATEGORIES.includes(tr.category);
483
+ if (tr.category === "TREE_MEMBER_FROM_ORIGIN") {
484
+ add("bytes.digest", "The bytes are this member's committed bytes", "FALSE", "SHA-256", `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`);
485
+ }
486
+ else {
487
+ add("bytes.digest", "The bytes are this member's committed bytes", isMember ? "TRUE" : pathOk ? "FALSE" : "UNDETERMINED", "SHA-256", 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");
488
+ }
489
+ if (tr.category === "TREE_MEMBER_DIRECT") {
490
+ 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", `${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`);
491
+ }
492
+ else if (tr.category === "TREE_MEMBER_AS_IS" || asIs) {
493
+ 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)");
494
+ }
495
+ else if (tr.category === "INVALID_SLOT_COMMITMENT" || tr.category === "INVALID_ORIGIN") {
496
+ add("proof.fused", "The committed bytes carry the position commitment", "FALSE", "", `${tr.category}: ${tr.reason}`);
497
+ }
498
+ else {
499
+ 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");
500
+ }
501
+ return tr;
502
+ }
351
503
  async function safe(f) {
352
504
  try {
353
505
  return await f();
@@ -363,7 +515,7 @@ function iso(ts) {
363
515
  * The reading, from the results. It names what the file proves and what that
364
516
  * rests on, and says what removes each reliance. Never stored in the file.
365
517
  */
366
- function writeReading(verdict, claims, bounds, proof, ceilingTime, floorTs, baseTimeWithheld = null) {
518
+ function writeReading(verdict, claims, bounds, proof, ceilingTime, floorTs, baseTimeWithheld = null, floorTimeWithheld = null, tr = null) {
367
519
  const get = (id) => claims.find((c) => c.id === id);
368
520
  if (verdict === "FALSE") {
369
521
  const failed = claims.filter((c) => c.result === "FALSE").map((c) => c.name.toLowerCase());
@@ -372,24 +524,35 @@ function writeReading(verdict, claims, bounds, proof, ceilingTime, floorTs, base
372
524
  const position = proof.commit?.counter ?? "?";
373
525
  const epoch = (proof.commit?.epochId ?? "").replace(/=+$/, "").slice(0, 8);
374
526
  const fused = get("proof.fused");
375
- const after = floorTs !== null ? `Recorded after Ethereum block ${bounds.notBefore.blockNumber} (${iso(floorTs)})` : `Recorded after Ethereum block ${bounds.notBefore.blockNumber}`;
527
+ const floorChain = bounds.notBefore.chain === "base" ? "Base" : "Ethereum";
528
+ const after = floorTs !== null ? `Recorded after ${floorChain} block ${bounds.notBefore.blockNumber} (${iso(floorTs)})` : `Recorded after ${floorChain} block ${bounds.notBefore.blockNumber}`;
376
529
  const by = ceilingTime ? `, and existed by Base block ${ceilingTime.blockNumber} (${iso(ceilingTime.blockTimestamp)})` : "";
377
530
  const settled = bounds.settledBy ? `, whose batch data Ethereum committed in block ${bounds.settledBy.blockNumber} (${iso(bounds.settledBy.timestamp)})` : "";
378
- const before = bounds.notAfter ? `; committed before the anchoring of Ethereum block ${bounds.notAfter.blockNumber}, a bound in position` : "";
531
+ const before = bounds.notAfter
532
+ ? `; committed before the anchoring of Ethereum block ${bounds.notAfter.blockNumber}, a bound in position`
533
+ : get("ceiling.position") ? "; its order among BitGraphs is the chain of proof hashes" : "";
379
534
  const digest = get("bytes.digest");
380
535
  // Two floors (SPEC 8.6): every record has the record floor; only bytes that
381
536
  // carry the commitment have the content floor. Without it, the bytes
382
537
  // themselves are not dated.
383
- const subject = digest?.result !== "TRUE"
384
- ? "The bytes this proof names were committed under this position."
385
- : fused?.result === "TRUE"
386
- ? (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).")
387
- : "These exact bytes carry no commitment, so the bytes themselves are not dated (the record floor only).";
538
+ // v4: the same two floors, said of one member of the tree (SPEC 8.6, export/1's words).
539
+ const leafWords = tr?.member ? `leaf ${tr.member.index} of ${tr.member.count} in the committed tree` : null;
540
+ const subject = tr !== null
541
+ ? digest?.result !== "TRUE"
542
+ ? 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."
543
+ : fused?.result === "TRUE"
544
+ ? `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.`
545
+ : `These exact bytes are ${leafWords}, kept as is: they carry no commitment, so the bytes themselves are not dated (the record floor only).`
546
+ : digest?.result !== "TRUE"
547
+ ? "The bytes this proof names were committed under this position."
548
+ : fused?.result === "TRUE"
549
+ ? (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).")
550
+ : "These exact bytes carry no commitment, so the bytes themselves are not dated (the record floor only).";
388
551
  const att = get("attestation.root");
389
552
  const rests = ["SHA-256", "Ed25519"];
390
553
  if (att?.result === "TRUE")
391
554
  rests.push(`the AWS Nitro root (${awsNitroRootSha256().slice(0, 8)}…)`);
392
- rests.push(`Ethereum block ${bounds.notBefore.blockNumber}`);
555
+ rests.push(`${floorChain} block ${bounds.notBefore.blockNumber}`);
393
556
  if (ceilingTime)
394
557
  rests.push(`Base block ${ceilingTime.blockNumber}`);
395
558
  if (bounds.settledBy)
@@ -401,7 +564,8 @@ function writeReading(verdict, claims, bounds, proof, ceilingTime, floorTs, base
401
564
  : "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.";
402
565
  const pins = get("attestation.pins");
403
566
  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." : "";
404
- const withheld = baseTimeWithheld ? ` The record is in a Base block, but its time is not used as a bound: ${baseTimeWithheld}.` : "";
567
+ const withheld = (floorTimeWithheld ? ` The floor block's time is not used as a bound: ${floorTimeWithheld}.` : "")
568
+ + (baseTimeWithheld ? ` The record is in a Base block, but its time is not used as a bound: ${baseTimeWithheld}.` : "");
405
569
  const lead = verdict === "UNDETERMINED" ? "Not judged in full. " : "";
406
570
  return `${lead}${subject} ${after}${by}${settled}${before}. Position ${position} of epoch ${epoch}…. Rests on: ${rests.join(", ")}. ${tail}${withheld}${pinLine}`;
407
571
  }