@mikeargento/bitgraph-verify 1.16.0 → 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.
- package/README.md +24 -3
- package/dist/__tests__/carrier2.test.js +1 -1
- package/dist/__tests__/carrier2.test.js.map +1 -1
- package/dist/carrier-assemble.d.ts +12 -2
- package/dist/carrier-assemble.d.ts.map +1 -1
- package/dist/carrier-assemble.js +14 -3
- package/dist/carrier-assemble.js.map +1 -1
- package/dist/carrier-verify.d.ts +5 -2
- package/dist/carrier-verify.d.ts.map +1 -1
- package/dist/carrier-verify.js +110 -43
- package/dist/carrier-verify.js.map +1 -1
- package/dist/carrier.d.ts +44 -11
- package/dist/carrier.d.ts.map +1 -1
- package/dist/carrier.js +74 -16
- package/dist/carrier.js.map +1 -1
- package/dist/ceiling.d.ts +82 -3
- package/dist/ceiling.d.ts.map +1 -1
- package/dist/ceiling.js +137 -20
- package/dist/ceiling.js.map +1 -1
- package/dist/export.d.ts +10 -0
- package/dist/export.d.ts.map +1 -1
- package/dist/export.js +89 -30
- package/dist/export.js.map +1 -1
- package/dist/fuse.d.ts +43 -11
- package/dist/fuse.d.ts.map +1 -1
- package/dist/fuse.js +85 -18
- package/dist/fuse.js.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/measurements.d.ts.map +1 -1
- package/dist/measurements.js +1 -0
- package/dist/measurements.js.map +1 -1
- package/dist/tree.d.ts +15 -3
- package/dist/tree.d.ts.map +1 -1
- package/dist/tree.js +41 -12
- package/dist/tree.js.map +1 -1
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/carrier2.test.ts +1 -1
- package/src/carrier-assemble.ts +21 -3
- package/src/carrier-verify.ts +107 -45
- package/src/carrier.ts +91 -25
- package/src/ceiling.ts +150 -24
- package/src/export.ts +94 -31
- package/src/fuse.ts +114 -23
- package/src/index.ts +18 -2
- package/src/measurements.ts +1 -0
- package/src/tree.ts +42 -10
- package/src/types.ts +22 -0
package/src/ceiling.ts
CHANGED
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* A ceiling in TIME for a BitGraph, carried beside the proof, never inside it.
|
|
5
5
|
*
|
|
6
|
-
* Every BitGraph already has a floor in time
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Every BitGraph already has a floor in time: the block the enclave fixes at
|
|
7
|
+
* slot allocation and signs at commit, an Ethereum anchor (`commit.slotAnchor`,
|
|
8
|
+
* enclave v7 to v9) or a Base block (`commit.slotFloor`, enclave v10; read both
|
|
9
|
+
* through signedFloorOf). An Ethereum-floor BitGraph also has a ceiling in
|
|
10
|
+
* POSITION (the anchors that follow it in the chain); after the cutover to Base
|
|
11
|
+
* floors there are no anchors, and order among BitGraphs is the chain of proof
|
|
12
|
+
* hashes. This adds the one thing a record
|
|
9
13
|
* cannot supply for itself: something outside the operator's control that
|
|
10
14
|
* depends on the record. After a commit, a writer puts a Merkle root over
|
|
11
15
|
* record hashes into a Base transaction. The block that includes it proves
|
|
@@ -30,9 +34,10 @@ import { sha256 } from "@noble/hashes/sha256";
|
|
|
30
34
|
import { verifyProofIntegrity, createVerificationContext } from "./verifier.js";
|
|
31
35
|
import { computeProofHash } from "./proof-hash.js";
|
|
32
36
|
import { merkleLeafHash, merkleRootFromPath } from "./fuse-merkle.js";
|
|
33
|
-
import { base64ToBytes } from "./fuse.js";
|
|
37
|
+
import { base64ToBytes, signedFloorOf, type SignedFloor } from "./fuse.js";
|
|
34
38
|
import {
|
|
35
|
-
bytesEqual, bytesToHex, decodeEip1559, decodeHeader, hexToBytes, keccak256, mptVerify, txTrieKey,
|
|
39
|
+
bytesEqual, bytesToHex, decodeEip1559, decodeHeader, hexToBytes, keccak256, mptVerify, rlpEncode, txTrieKey,
|
|
40
|
+
type DecodedHeader,
|
|
36
41
|
} from "./ceiling-evm.js";
|
|
37
42
|
import type { BitGraphProof, VerificationPolicy } from "./types.js";
|
|
38
43
|
|
|
@@ -70,9 +75,12 @@ export interface CeilingSidecar {
|
|
|
70
75
|
statusObserved: { included: string | null; safe: string | null; finalized: string | null };
|
|
71
76
|
/**
|
|
72
77
|
* The floor block's header, so the window reads offline. Optional and
|
|
73
|
-
* unsigned: checked by keccak256 against the
|
|
78
|
+
* unsigned: checked by keccak256 against the floor the proof SIGNS
|
|
79
|
+
* (signedFloorOf). `chain` names the floor's chain: absent is Ethereum (every
|
|
80
|
+
* sidecar before enclave v10), "base" a Base floor, whose header's time must
|
|
81
|
+
* also equal the signed blockTimestamp.
|
|
74
82
|
*/
|
|
75
|
-
floor?: { blockNumber: number; blockHash: string; blockTimestamp: number; blockHeader: string } | null;
|
|
83
|
+
floor?: { blockNumber: number; blockHash: string; blockTimestamp: number; blockHeader: string; chain?: "ethereum" | "base" } | null;
|
|
76
84
|
/** Reserved for v2: the Ethereum batch that settles this Base block. */
|
|
77
85
|
settlement: null;
|
|
78
86
|
}
|
|
@@ -138,8 +146,8 @@ export interface CeilingVerifyResult {
|
|
|
138
146
|
checks: CeilingCheck[];
|
|
139
147
|
status?: CeilingStatus;
|
|
140
148
|
window?: {
|
|
141
|
-
/** Floor: the proof
|
|
142
|
-
floor: { blockNumber: number; blockHash: string; blockTimestamp: number | null };
|
|
149
|
+
/** Floor: the block the proof signs (signedFloorOf), on its chain. Time only if a checked header was carried. */
|
|
150
|
+
floor: { chain: "ethereum" | "base" | null; blockNumber: number; blockHash: string; blockTimestamp: number | null };
|
|
143
151
|
/** Ceiling: the Base block, time read from its header. */
|
|
144
152
|
ceiling: { chainId: number; blockNumber: number; blockHash: string; blockTimestamp: number };
|
|
145
153
|
widthSeconds: number | null;
|
|
@@ -298,29 +306,38 @@ async function verifyCeilingChecks(
|
|
|
298
306
|
if (!inBlock || !bytesEqual(inBlock, rawTx)) return fail("inclusion", "the transaction is not in this block");
|
|
299
307
|
pass("inclusion", `transaction ${a.txIndex} of block ${header.number}`);
|
|
300
308
|
|
|
301
|
-
// 5. The window. The floor is the proof
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
309
|
+
// 5. The window. The floor is the block the proof itself signs, on its own chain.
|
|
310
|
+
let signed: SignedFloor | null;
|
|
311
|
+
try {
|
|
312
|
+
signed = signedFloorOf(proof);
|
|
313
|
+
} catch (e) {
|
|
314
|
+
return fail("floor", (e as Error).message);
|
|
315
|
+
}
|
|
316
|
+
let floor: { chain: "ethereum" | "base"; blockNumber: number; blockHash: string; blockTimestamp: number | null } | null = null;
|
|
317
|
+
if (signed) {
|
|
318
|
+
floor = { chain: signed.chain, blockNumber: signed.blockNumber, blockHash: signed.blockHash, blockTimestamp: null };
|
|
306
319
|
const w = sidecar.floor;
|
|
307
320
|
if (w !== null && w !== undefined) {
|
|
308
321
|
if (typeof w !== "object" || typeof w.blockHeader !== "string" || w.blockHeader.length === 0) {
|
|
309
322
|
return fail("floor", "the sidecar carries a floor without a header (absence is null; a present floor carries its header)");
|
|
310
323
|
}
|
|
324
|
+
let raw: Uint8Array;
|
|
311
325
|
try {
|
|
312
|
-
|
|
313
|
-
if (fh.hash === slotAnchor.blockHash.toLowerCase() && fh.number === slotAnchor.blockNumber) {
|
|
314
|
-
floor.blockTimestamp = fh.timestamp;
|
|
315
|
-
pass("floor", `Ethereum block ${fh.number}, header checked against the signed hash`);
|
|
316
|
-
} else {
|
|
317
|
-
// Every part a sidecar carries must hold: a copy of the floor that
|
|
318
|
-
// is not the signed floor block fails the sidecar, it is not skipped.
|
|
319
|
-
return fail("floor", "the carried floor header does not match the proof's signed slotAnchor");
|
|
320
|
-
}
|
|
326
|
+
raw = hexToBytes(w.blockHeader);
|
|
321
327
|
} catch {
|
|
322
328
|
return fail("floor", "the carried floor header does not decode");
|
|
323
329
|
}
|
|
330
|
+
// Every part a sidecar carries must hold: a copy of the floor that is
|
|
331
|
+
// not the signed floor block fails the sidecar, it is not skipped.
|
|
332
|
+
const fh = checkFloorHeader(signed, raw, w.chain);
|
|
333
|
+
if (!fh.ok) {
|
|
334
|
+
if (fh.reason.startsWith("the header does not decode")) return fail("floor", "the carried floor header does not decode");
|
|
335
|
+
const field = signed.chain === "base" ? "slotFloor" : "slotAnchor";
|
|
336
|
+
const said = signed.chain === "ethereum" && w.chain === undefined ? "" : `: ${fh.reason}`;
|
|
337
|
+
return fail("floor", `the carried floor header does not match the proof's signed ${field}${said}`);
|
|
338
|
+
}
|
|
339
|
+
floor.blockTimestamp = fh.header.timestamp;
|
|
340
|
+
pass("floor", `${chainName(signed.chain)} block ${fh.header.number}, header checked against the signed hash`);
|
|
324
341
|
}
|
|
325
342
|
}
|
|
326
343
|
const width = floor?.blockTimestamp != null ? header.timestamp - floor.blockTimestamp : null;
|
|
@@ -330,7 +347,7 @@ async function verifyCeilingChecks(
|
|
|
330
347
|
checks,
|
|
331
348
|
status,
|
|
332
349
|
window: {
|
|
333
|
-
floor: floor ?? { blockNumber: 0, blockHash: "", blockTimestamp: null },
|
|
350
|
+
floor: floor ?? { chain: null, blockNumber: 0, blockHash: "", blockTimestamp: null },
|
|
334
351
|
ceiling: { chainId: a.chainId, blockNumber: header.number, blockHash: header.hash, blockTimestamp: header.timestamp },
|
|
335
352
|
widthSeconds: width,
|
|
336
353
|
},
|
|
@@ -364,6 +381,115 @@ export async function checkCeilingOnline(
|
|
|
364
381
|
|
|
365
382
|
export { keccak256 as ceilingKeccak256 };
|
|
366
383
|
|
|
384
|
+
// ── The floor block's header ───────────────────────────────────────────────
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Base mainnet stamps every block by its height: block n is
|
|
388
|
+
* BASE_MAINNET_GENESIS_TIME + BASE_BLOCK_TIME_SECONDS * n (OP Stack, checked
|
|
389
|
+
* against the live chain 2026-10-06). The enclave (v10) refuses a floor header
|
|
390
|
+
* off this schedule; a verifier refuses one too, since such a header is not a
|
|
391
|
+
* Base mainnet block (another chain, a testnet, or made up).
|
|
392
|
+
*/
|
|
393
|
+
export const BASE_MAINNET_GENESIS_TIME = 1686789347;
|
|
394
|
+
export const BASE_BLOCK_TIME_SECONDS = 2;
|
|
395
|
+
|
|
396
|
+
/** True when a block's stamp is Base mainnet's schedule for its number. */
|
|
397
|
+
export function onBaseSchedule(blockNumber: number, timestampSec: number): boolean {
|
|
398
|
+
return timestampSec === BASE_MAINNET_GENESIS_TIME + BASE_BLOCK_TIME_SECONDS * blockNumber;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const chainName = (c: "ethereum" | "base") => (c === "base" ? "Base" : "Ethereum");
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Check a floor header against the floor the proof signs (signedFloorOf). The
|
|
405
|
+
* header must decode, hash (keccak-256) to the signed block hash and carry the
|
|
406
|
+
* signed number. For a Base floor its time must also equal the signed
|
|
407
|
+
* blockTimestamp and be Base mainnet's schedule for its number. When the
|
|
408
|
+
* carrier of the header names a chain (`declaredChain`, absent = Ethereum), it
|
|
409
|
+
* must be the signed floor's chain: a Base floor read as an Ethereum header,
|
|
410
|
+
* or the reverse, fails here even before any hash is compared.
|
|
411
|
+
*/
|
|
412
|
+
export function checkFloorHeader(
|
|
413
|
+
signed: SignedFloor,
|
|
414
|
+
headerRlp: Uint8Array,
|
|
415
|
+
declaredChain?: unknown,
|
|
416
|
+
): { ok: true; header: DecodedHeader } | { ok: false; reason: string } {
|
|
417
|
+
const declared = declaredChain === undefined || declaredChain === null ? "ethereum" : declaredChain;
|
|
418
|
+
if (declared !== "ethereum" && declared !== "base") return { ok: false, reason: `the header names an unknown chain (${JSON.stringify(declaredChain)})` };
|
|
419
|
+
const aBlock = (c: "ethereum" | "base") => (c === "base" ? "a Base block" : "an Ethereum block");
|
|
420
|
+
if (declared !== signed.chain) return { ok: false, reason: `the header is given as ${aBlock(declared)}, and the proof signs ${aBlock(signed.chain)}` };
|
|
421
|
+
let h: DecodedHeader;
|
|
422
|
+
try {
|
|
423
|
+
h = decodeHeader(headerRlp);
|
|
424
|
+
} catch (e) {
|
|
425
|
+
return { ok: false, reason: `the header does not decode (${(e as Error).message})` };
|
|
426
|
+
}
|
|
427
|
+
if (h.hash !== signed.blockHash.toLowerCase()) return { ok: false, reason: `the header does not hash to the signed ${chainName(signed.chain)} block hash` };
|
|
428
|
+
if (h.number !== signed.blockNumber) return { ok: false, reason: `the header is block ${h.number}, the proof signs block ${signed.blockNumber}` };
|
|
429
|
+
if (signed.chain === "base") {
|
|
430
|
+
if (h.timestamp !== signed.blockTimestamp) return { ok: false, reason: `the header's time is ${h.timestamp}, the proof signs ${signed.blockTimestamp}` };
|
|
431
|
+
if (!onBaseSchedule(h.number, h.timestamp)) return { ok: false, reason: `Base block ${h.number} is stamped ${h.timestamp}, off Base mainnet's schedule (${BASE_MAINNET_GENESIS_TIME + BASE_BLOCK_TIME_SECONDS * h.number})` };
|
|
432
|
+
}
|
|
433
|
+
return { ok: true, header: h };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Whether the floor block's time may be stated as a bound (review, 2026-10-06):
|
|
438
|
+
* the floor block must be no later than the commit's attestation document,
|
|
439
|
+
* the time AWS's hardware signed. A floor stamped after it cannot be a "not
|
|
440
|
+
* before" for a record that already existed; the block hash still floors the
|
|
441
|
+
* record (it did not exist before its block), but its time is withheld.
|
|
442
|
+
* Holds for either chain.
|
|
443
|
+
*/
|
|
444
|
+
export function floorTimeIsBound(floorTimestampSec: number, attestedAtMs: number | null | undefined): { ok: true } | { ok: false; reason: string } {
|
|
445
|
+
if (attestedAtMs != null && floorTimestampSec * 1000 > attestedAtMs) {
|
|
446
|
+
return { ok: false, reason: `the floor block is stamped ${isoSec(floorTimestampSec)}, after the attestation document was made (${isoMs(attestedAtMs)})` };
|
|
447
|
+
}
|
|
448
|
+
return { ok: true };
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** A block as an EVM node's JSON-RPC returns it (eth_getBlockByNumber), the header fields only. */
|
|
452
|
+
export interface RpcBlockHeader {
|
|
453
|
+
hash: string; parentHash: string; sha3Uncles: string; miner: string; stateRoot: string;
|
|
454
|
+
transactionsRoot: string; receiptsRoot: string; logsBloom: string;
|
|
455
|
+
difficulty: string; number: string; gasLimit: string; gasUsed: string;
|
|
456
|
+
timestamp: string; extraData: string; mixHash: string; nonce: string;
|
|
457
|
+
baseFeePerGas?: string; withdrawalsRoot?: string; blobGasUsed?: string;
|
|
458
|
+
excessBlobGas?: string; parentBeaconBlockRoot?: string; requestsHash?: string;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* The header's RLP, rebuilt from a node's JSON in canonical field order
|
|
463
|
+
* (through Prague; Base headers have the same shape), or null when it does not
|
|
464
|
+
* reproduce `expectedHash`. Null is the honest answer for a field this encoder
|
|
465
|
+
* does not know: nothing unchecked is ever returned.
|
|
466
|
+
*/
|
|
467
|
+
export function headerRlpFromRpc(b: RpcBlockHeader | null | undefined, expectedHash: string): Uint8Array | null {
|
|
468
|
+
if (!b || typeof b !== "object") return null;
|
|
469
|
+
try {
|
|
470
|
+
const q = (x: string | undefined) => {
|
|
471
|
+
const h = String(x ?? "0x").replace(/^0x/i, "").replace(/^0+/, "");
|
|
472
|
+
return h === "" ? new Uint8Array(0) : hexToBytes(h.length % 2 ? `0${h}` : h);
|
|
473
|
+
};
|
|
474
|
+
const d = (x: string | undefined) => hexToBytes(String(x ?? "0x"));
|
|
475
|
+
const fields: Uint8Array[] = [
|
|
476
|
+
d(b.parentHash), d(b.sha3Uncles), d(b.miner), d(b.stateRoot), d(b.transactionsRoot),
|
|
477
|
+
d(b.receiptsRoot), d(b.logsBloom), q(b.difficulty), q(b.number), q(b.gasLimit),
|
|
478
|
+
q(b.gasUsed), q(b.timestamp), d(b.extraData), d(b.mixHash), d(b.nonce),
|
|
479
|
+
];
|
|
480
|
+
if (b.baseFeePerGas != null) fields.push(q(b.baseFeePerGas));
|
|
481
|
+
if (b.withdrawalsRoot != null) fields.push(d(b.withdrawalsRoot));
|
|
482
|
+
if (b.blobGasUsed != null) fields.push(q(b.blobGasUsed));
|
|
483
|
+
if (b.excessBlobGas != null) fields.push(q(b.excessBlobGas));
|
|
484
|
+
if (b.parentBeaconBlockRoot != null) fields.push(d(b.parentBeaconBlockRoot));
|
|
485
|
+
if (b.requestsHash != null) fields.push(d(b.requestsHash));
|
|
486
|
+
const rlp = rlpEncode(fields);
|
|
487
|
+
return bytesToHex(keccak256(rlp)) === expectedHash.toLowerCase() ? rlp : null;
|
|
488
|
+
} catch {
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
367
493
|
// ── The Base stamp as a time bound ─────────────────────────────────────────
|
|
368
494
|
|
|
369
495
|
const isoSec = (unix: number) => new Date(unix * 1000).toISOString().replace(".000Z", "Z");
|
package/src/export.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* "member": TreeMemberEvidence one file's export
|
|
13
13
|
* or "leaves": base64(count x 65 bytes), the owner's export
|
|
14
14
|
* "names"?: [file name per leaf] }, unsigned, informational
|
|
15
|
-
* "floor": { "blockNumber", "blockHash", "header" } | null,
|
|
15
|
+
* "floor": { "chain"?, "blockNumber", "blockHash", "header" } | null, chain: "ethereum" (absent) or "base"
|
|
16
16
|
* "ceiling": a bitgraph-ceiling/1 sidecar | { "status": "pending" } | null,
|
|
17
17
|
* "settlement": a bitgraph-output-root/1 settlement | { "status": "pending", "baseBlock"? } | null
|
|
18
18
|
* }
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
* lookups say those blocks are the chains' own). This module never fetches.
|
|
24
24
|
*
|
|
25
25
|
* Three time claims, never merged:
|
|
26
|
-
* floor the committed bytes were finished after
|
|
26
|
+
* floor the committed bytes were finished after the floor block N, on the chain the
|
|
27
|
+
* proof signs: an Ethereum anchor (commit.slotAnchor, enclave v7 to v9) or a Base
|
|
28
|
+
* block (commit.slotFloor, enclave v10) (needs N canonical on that chain)
|
|
27
29
|
* ceiling.base the record existed by Base block B, at B's time (needs B canonical on Base; provisional until then)
|
|
28
30
|
* ceiling.ethereum the record existed by Ethereum block H (needs H canonical; Base's honesty not needed)
|
|
29
31
|
*/
|
|
@@ -32,9 +34,9 @@ import { sha256 } from "@noble/hashes/sha256";
|
|
|
32
34
|
import { verifyProofIntegrity, createVerificationContext } from "./verifier.js";
|
|
33
35
|
import { computeSignedBodyHash } from "./proof-hash.js";
|
|
34
36
|
import { verifyNitroAttestation } from "./nitro.js";
|
|
35
|
-
import { CEILING_VERSION, baseTimeIsBound, verifyCeiling, type CeilingSidecar } from "./ceiling.js";
|
|
36
|
-
import {
|
|
37
|
-
import { base64ToBytes, bytesEqual, hexToBytes } from "./fuse.js";
|
|
37
|
+
import { CEILING_VERSION, baseTimeIsBound, checkFloorHeader, floorTimeIsBound, verifyCeiling, type CeilingSidecar } from "./ceiling.js";
|
|
38
|
+
import { hexToBytes as evmHex } from "./ceiling-evm.js";
|
|
39
|
+
import { base64ToBytes, bytesEqual, hexToBytes, signedFloorOf, type SignedFloor } from "./fuse.js";
|
|
38
40
|
import { OUTPUT_ROOT_VERSION, verifyOutputRootSettlement, type OutputRootSettlement } from "./output-root.js";
|
|
39
41
|
import { MerkleTree } from "./fuse-merkle.js";
|
|
40
42
|
import { streamDigest, type ByteSource } from "./stream.js";
|
|
@@ -63,7 +65,8 @@ export interface BitGraphExport {
|
|
|
63
65
|
leaves?: string;
|
|
64
66
|
names?: string[];
|
|
65
67
|
};
|
|
66
|
-
floor
|
|
68
|
+
/** The floor block's header. `chain` absent is Ethereum (every export before enclave v10); "base" a Base floor. */
|
|
69
|
+
floor: { chain?: "ethereum" | "base"; blockNumber: number; blockHash: string; header: string } | null;
|
|
67
70
|
ceiling: CeilingSidecar | { status: "pending" } | null;
|
|
68
71
|
settlement: OutputRootSettlement | { status: "pending"; baseBlock?: number } | null;
|
|
69
72
|
}
|
|
@@ -121,7 +124,8 @@ export interface ExportVerifyResult {
|
|
|
121
124
|
floorCovers: TreeVerifyResult["floorCovers"];
|
|
122
125
|
/** The three time claims, as established. Null fields were not established. */
|
|
123
126
|
times: {
|
|
124
|
-
floor
|
|
127
|
+
/** `chain` is present only for a Base floor, so an Ethereum floor's result is exactly what it was before enclave v10. */
|
|
128
|
+
floor: { chain?: "base"; blockNumber: number; blockHash: string; blockTimestamp: number } | null;
|
|
125
129
|
ceilingBase: { chainId: number; blockNumber: number; blockHash: string; blockTimestamp: number; provisional: boolean } | null;
|
|
126
130
|
ceilingEthereum: { chainId: number; blockNumber: number; blockHash: string; blockTimestamp: number } | null;
|
|
127
131
|
};
|
|
@@ -131,6 +135,12 @@ export interface ExportVerifyResult {
|
|
|
131
135
|
* document (see baseTimeIsBound). The inclusion itself still holds.
|
|
132
136
|
*/
|
|
133
137
|
baseTimeWithheld: string | null;
|
|
138
|
+
/**
|
|
139
|
+
* Why the floor block's time is not stated as a bound, when it is not: the
|
|
140
|
+
* block is stamped after the attestation document (see floorTimeIsBound).
|
|
141
|
+
* The floor itself still holds: the record was made after that block.
|
|
142
|
+
*/
|
|
143
|
+
floorTimeWithheld: string | null;
|
|
134
144
|
/** Plain language, written from the claims. */
|
|
135
145
|
reading: string;
|
|
136
146
|
}
|
|
@@ -163,6 +173,7 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
163
173
|
let member: TreeVerifyResult["member"] = null;
|
|
164
174
|
|
|
165
175
|
let baseTimeWithheld: string | null = null;
|
|
176
|
+
let floorTimeWithheld: string | null = null;
|
|
166
177
|
|
|
167
178
|
const exp = parseExport(input);
|
|
168
179
|
if (exp === null) {
|
|
@@ -177,10 +188,19 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
177
188
|
if (declared === EXPORT_FORMAT) add("format", "This is a bitgraph-export/1 file", "FALSE", "its structure", "it says bitgraph-export/1 but lacks the parts that format requires (proof, tree.rootDocument)");
|
|
178
189
|
else if (typeof declared === "string" && declared.startsWith("bitgraph-export/")) add("format", "This is a bitgraph-export/1 file", "UNDETERMINED", "", `not judged: a format this verifier does not know (${declared})`);
|
|
179
190
|
else add("format", "This is a bitgraph-export/1 file", "UNDETERMINED", "", "not a bitgraph-export/1 document");
|
|
180
|
-
return finish(claims, null, times, member, null, null);
|
|
191
|
+
return finish(claims, null, times, member, null, null, null);
|
|
181
192
|
}
|
|
182
193
|
add("format", "This is a bitgraph-export/1 file", "TRUE", "its structure", "format, proof and tree present");
|
|
183
194
|
const proof = exp.proof;
|
|
195
|
+
// The floor the proof signs, whichever chain it is on. A proof that signs two is ambiguous: no floor is read from it.
|
|
196
|
+
let signedFloor: SignedFloor | null = null;
|
|
197
|
+
let floorAmbiguous: string | null = null;
|
|
198
|
+
try {
|
|
199
|
+
signedFloor = signedFloorOf(proof);
|
|
200
|
+
} catch (e) {
|
|
201
|
+
floorAmbiguous = (e as Error).message;
|
|
202
|
+
}
|
|
203
|
+
const chainName = (c: "ethereum" | "base") => (c === "base" ? "Base" : "Ethereum");
|
|
184
204
|
|
|
185
205
|
// An optional part is absent (null or missing) or an object of its format;
|
|
186
206
|
// anything else is a malformed part, never read as "not carried".
|
|
@@ -325,8 +345,7 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
325
345
|
// Two floors, stated apart (SPEC 8.6). The record floor is every member's:
|
|
326
346
|
// the root document was signed after the floor block. The content floor
|
|
327
347
|
// is a placed member's: its committed bytes carry the commitment.
|
|
328
|
-
const
|
|
329
|
-
const block = typeof n === "number" ? `Ethereum block ${n}` : "the signed floor block";
|
|
348
|
+
const block = signedFloor ? `${chainName(signedFloor.chain)} block ${signedFloor.blockNumber}` : "the signed floor block";
|
|
330
349
|
add("floor.record", "The record was made after the floor block", "TRUE", "the signed root document, which carries the commitment to the floor block",
|
|
331
350
|
`recorded after ${block}: the tree this file is a leaf of was signed after it`);
|
|
332
351
|
if (tr.floorCovers === "content") {
|
|
@@ -339,23 +358,47 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
339
358
|
}
|
|
340
359
|
}
|
|
341
360
|
|
|
342
|
-
// 3. The floor: the header hashes to the SIGNED
|
|
343
|
-
|
|
361
|
+
// 3. The floor: the header hashes to the SIGNED floor block hash, on the chain the proof signs.
|
|
362
|
+
let floorBlock: { chain: "ethereum" | "base"; blockNumber: number; blockHash: string } | null = null;
|
|
363
|
+
let floorHeaderTs: number | null = null;
|
|
364
|
+
const fname = "The floor block's header is the one the proof signs";
|
|
344
365
|
if (isAbsent(exp.floor)) {
|
|
345
|
-
add("floor.header",
|
|
366
|
+
add("floor.header", fname, "NOT_CARRIED", "", "no floor header in the export");
|
|
346
367
|
} else if (!isObject(exp.floor)) {
|
|
347
|
-
add("floor.header",
|
|
348
|
-
} else if (
|
|
349
|
-
add("floor.header",
|
|
368
|
+
add("floor.header", fname, "FALSE", "", "the export's floor is neither absent nor a { blockNumber, blockHash, header } object");
|
|
369
|
+
} else if (floorAmbiguous !== null) {
|
|
370
|
+
add("floor.header", fname, "FALSE", "", floorAmbiguous);
|
|
371
|
+
} else if (!signedFloor) {
|
|
372
|
+
add("floor.header", fname, "FALSE", "", "the proof signs no floor block (commit.slotAnchor or commit.slotFloor)");
|
|
350
373
|
} else {
|
|
374
|
+
const f = exp.floor as Record<string, unknown>;
|
|
375
|
+
const chain = chainName(signedFloor.chain);
|
|
376
|
+
let raw: Uint8Array | null = null;
|
|
351
377
|
try {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
add("floor.header",
|
|
378
|
+
raw = evmHex(String(f["header"]));
|
|
379
|
+
} catch {
|
|
380
|
+
raw = null;
|
|
381
|
+
}
|
|
382
|
+
const fh = raw === null ? { ok: false as const, reason: "the header is not hex" } : checkFloorHeader(signedFloor, raw, f["chain"]);
|
|
383
|
+
if (!fh.ok) {
|
|
384
|
+
add("floor.header", fname, "FALSE", "", `floor header: ${fh.reason}`);
|
|
385
|
+
} else if (String(f["blockHash"]).toLowerCase() !== fh.header.hash || f["blockNumber"] !== fh.header.number) {
|
|
386
|
+
add("floor.header", fname, "FALSE", "", "the export's floor names a different block than its header");
|
|
387
|
+
} else {
|
|
388
|
+
const h = fh.header;
|
|
389
|
+
floorBlock = { chain: signedFloor.chain, blockNumber: h.number, blockHash: h.hash };
|
|
390
|
+
floorHeaderTs = h.timestamp;
|
|
391
|
+
// The floor's time is a bound only when it is no later than the attestation document.
|
|
392
|
+
const bound = floorTimeIsBound(h.timestamp, attestedAtMs);
|
|
393
|
+
if (bound.ok) {
|
|
394
|
+
times.floor = { ...(signedFloor.chain === "base" ? { chain: "base" as const } : {}), blockNumber: h.number, blockHash: h.hash, blockTimestamp: h.timestamp };
|
|
395
|
+
add("floor.header", fname, "TRUE", `${chain} block ${h.number}, header as given`,
|
|
396
|
+
`keccak-256 of the header equals the signed block hash${signedFloor.chain === "base" ? ", and its time is the signed one, on Base mainnet's schedule" : ""}; its time is ${iso(h.timestamp)}`);
|
|
397
|
+
} else {
|
|
398
|
+
floorTimeWithheld = bound.reason;
|
|
399
|
+
add("floor.header", fname, "TRUE", `${chain} block ${h.number}, header as given`,
|
|
400
|
+
`keccak-256 of the header equals the signed block hash; ${bound.reason}, so its time is not used as a bound`);
|
|
401
|
+
}
|
|
359
402
|
}
|
|
360
403
|
}
|
|
361
404
|
|
|
@@ -387,7 +430,7 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
387
430
|
ceilingB = { blockNumber: r.window.ceiling.blockNumber, blockHash: r.window.ceiling.blockHash };
|
|
388
431
|
const where = `under the root in transaction ${(c as CeilingSidecar).anchor!.txIndex} of Base block ${r.window.ceiling.blockNumber}`;
|
|
389
432
|
// The floor's time: the export's own header, else the verified header the sidecar carries.
|
|
390
|
-
const stamp = baseTimeIsBound(r.window.ceiling.blockTimestamp, { floorTimestampSec:
|
|
433
|
+
const stamp = baseTimeIsBound(r.window.ceiling.blockTimestamp, { floorTimestampSec: floorHeaderTs ?? r.window.floor.blockTimestamp ?? null, attestedAtMs });
|
|
391
434
|
if (stamp.ok) {
|
|
392
435
|
times.ceilingBase = { ...r.window.ceiling, provisional: true };
|
|
393
436
|
add("ceiling.base", "The record is in a Base block", "TRUE", `SHA-256 path, the BGC1 payload, secp256k1, Merkle-Patricia; Base block ${r.window.ceiling.blockNumber}, header as given`,
|
|
@@ -452,19 +495,20 @@ export async function verifyExport(input: unknown, opts: ExportVerifyOptions = {
|
|
|
452
495
|
add(id, name, "UNDETERMINED", "", `lookup failed: ${(e as Error).message}`, "confirmed");
|
|
453
496
|
}
|
|
454
497
|
};
|
|
455
|
-
|
|
498
|
+
// The floor is asked of its own chain, by height: the chain's block at N must be the signed one.
|
|
499
|
+
if (floorBlock !== null) await confirm("confirmed.floor", `The floor block is ${chainName(floorBlock.chain)}'s own`, floorBlock.chain, floorBlock);
|
|
456
500
|
await confirm("confirmed.ceiling.base", "The ceiling block is Base's own (makes its time final)", "base", ceilingB);
|
|
457
501
|
await confirm("confirmed.ceiling.ethereum", "The settlement block is Ethereum's own", "ethereum", times.ceilingEthereum);
|
|
458
502
|
const baseConfirmed = claims.find((x) => x.id === "confirmed.ceiling.base")?.result === "TRUE";
|
|
459
503
|
if (times.ceilingBase) times.ceilingBase.provisional = !baseConfirmed;
|
|
460
504
|
|
|
461
|
-
return finish(claims, exp, times, member, tr.floorCovers, baseTimeWithheld);
|
|
505
|
+
return finish(claims, exp, times, member, tr.floorCovers, baseTimeWithheld, floorTimeWithheld, floorBlock);
|
|
462
506
|
};
|
|
463
507
|
try {
|
|
464
508
|
return await run();
|
|
465
509
|
} catch (e) {
|
|
466
510
|
add("wellformed", "Every part of the export is well formed", "FALSE", "", `a part of this export is malformed: ${(e as Error).message}`);
|
|
467
|
-
return finish(claims, exp, times, member, null, baseTimeWithheld);
|
|
511
|
+
return finish(claims, exp, times, member, null, baseTimeWithheld, floorTimeWithheld);
|
|
468
512
|
}
|
|
469
513
|
}
|
|
470
514
|
|
|
@@ -485,6 +529,8 @@ function finish(
|
|
|
485
529
|
member: TreeVerifyResult["member"],
|
|
486
530
|
floorCovers: TreeVerifyResult["floorCovers"] = null,
|
|
487
531
|
baseTimeWithheld: string | null = null,
|
|
532
|
+
floorTimeWithheld: string | null = null,
|
|
533
|
+
floorBlock: { chain: "ethereum" | "base"; blockNumber: number } | null = null,
|
|
488
534
|
): ExportVerifyResult {
|
|
489
535
|
const offline = claims.filter((c) => c.level === "offline");
|
|
490
536
|
const failed = claims.filter((c) => c.result === "FALSE");
|
|
@@ -505,25 +551,42 @@ function finish(
|
|
|
505
551
|
const lc1 = (t: string) => t.charAt(0).toLowerCase() + t.slice(1);
|
|
506
552
|
if (unjudged.length > 0) parts.push(`Not judged in full: ${unjudged.map((c) => lc1(c.name)).join("; ")}.`);
|
|
507
553
|
const givenEth = "; that block's header is taken as given until it is checked against Ethereum";
|
|
508
|
-
|
|
509
|
-
|
|
554
|
+
const floorRead = floorBlock ?? (times.floor ? { chain: times.floor.chain ?? "ethereum", blockNumber: times.floor.blockNumber } : null);
|
|
555
|
+
if (floorRead) {
|
|
556
|
+
const chain = floorRead.chain === "base" ? "Base" : "Ethereum";
|
|
557
|
+
const time = times.floor ? ` (${iso(times.floor.blockTimestamp)})` : "";
|
|
558
|
+
const given = confirmedTrue("confirmed.floor") ? "" : `; that block's header is taken as given until it is checked against ${chain}`;
|
|
559
|
+
const at = `${chain} block ${floorRead.blockNumber}${time}${given}`;
|
|
510
560
|
parts.push(floorCovers === "record"
|
|
511
561
|
? `Recorded after ${at}; this file was kept as is, so the bytes themselves are not dated.`
|
|
512
562
|
: floorCovers === "content"
|
|
513
563
|
? `Recorded after ${at}, and these committed bytes were finished after that block; an original inside them is not dated by it.`
|
|
514
564
|
: `Recorded after ${at}.`);
|
|
565
|
+
if (!times.floor && floorTimeWithheld) parts.push(`The floor block's time is not used as a bound: ${floorTimeWithheld}.`);
|
|
515
566
|
}
|
|
516
567
|
if (times.ceilingBase) parts.push(`The record existed by Base block ${times.ceilingBase.blockNumber} (${iso(times.ceilingBase.blockTimestamp)}${times.ceilingBase.provisional ? ", provisional until checked against Base" : ""}).`);
|
|
517
568
|
else if (baseTimeWithheld) parts.push(`The record is in a Base block, but its time is not used as a bound: ${baseTimeWithheld}.`);
|
|
518
569
|
if (times.ceilingEthereum) parts.push(`It existed by Ethereum block ${times.ceilingEthereum.blockNumber} (${iso(times.ceilingEthereum.blockTimestamp)})${confirmedTrue("confirmed.ceiling.ethereum") ? "" : givenEth}.`);
|
|
519
570
|
if (member) parts.push(`The file is leaf ${member.index} of ${member.count} in the committed tree.`);
|
|
520
571
|
}
|
|
521
|
-
return { verdict, reasons, claims, member, floorCovers, times, baseTimeWithheld, reading: parts.join(" ") };
|
|
572
|
+
return { verdict, reasons, claims, member, floorCovers, times, baseTimeWithheld, floorTimeWithheld, reading: parts.join(" ") };
|
|
522
573
|
}
|
|
523
574
|
|
|
575
|
+
|
|
524
576
|
/** Build an export object from its parts (producers). Fields are written in the order the spec lists them. */
|
|
525
577
|
export function buildExport(parts: Omit<BitGraphExport, "format" | "spec">): BitGraphExport {
|
|
526
578
|
const spec = parts.proof.attribution?.message;
|
|
527
579
|
if (typeof spec !== "string") throw new TypeError("a tree/1 proof pins its spec in attribution.message");
|
|
528
|
-
|
|
580
|
+
// A Base floor names its chain; an Ethereum floor leaves it out, so exports made before enclave v10 stay byte for byte what they were.
|
|
581
|
+
let floor = parts.floor;
|
|
582
|
+
if (floor && floor.chain === undefined) {
|
|
583
|
+
let chain: "ethereum" | "base" | undefined;
|
|
584
|
+
try {
|
|
585
|
+
chain = signedFloorOf(parts.proof)?.chain;
|
|
586
|
+
} catch {
|
|
587
|
+
chain = undefined;
|
|
588
|
+
}
|
|
589
|
+
if (chain === "base") floor = { chain: "base", blockNumber: floor.blockNumber, blockHash: floor.blockHash, header: floor.header };
|
|
590
|
+
}
|
|
591
|
+
return { format: EXPORT_FORMAT, spec, proof: parts.proof, tree: parts.tree, floor, ceiling: parts.ceiling, settlement: parts.settlement };
|
|
529
592
|
}
|