@mikeargento/bitgraph-audit 0.11.0 → 0.11.1
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/LICENSE +1 -1
- package/README.md +7 -5
- package/dist/anchors.js +1 -1
- package/dist/anomalies.js +1 -1
- package/dist/attestation.js +1 -1
- package/dist/audit.d.ts +1 -1
- package/dist/audit.js +2 -2
- package/dist/authority.js +1 -1
- package/dist/aws-nitro-root-ca.js +1 -1
- package/dist/ceilings.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/contents-hash.js +1 -1
- package/dist/export.js +1 -1
- package/dist/exports.js +1 -1
- package/dist/floors.js +1 -1
- package/dist/index.js +1 -1
- package/dist/ingest.js +1 -1
- package/dist/reconstruct.js +1 -1
- package/dist/report-json.js +1 -1
- package/dist/report-md.js +1 -1
- package/dist/rlp.js +1 -1
- package/dist/rollup-schedule.d.ts +58 -0
- package/dist/rollup-schedule.d.ts.map +1 -0
- package/dist/rollup-schedule.js +105 -0
- package/dist/rollup-schedule.js.map +1 -0
- package/dist/settlement-blobs.d.ts +16 -19
- package/dist/settlement-blobs.d.ts.map +1 -1
- package/dist/settlement-blobs.js +37 -17
- package/dist/settlement-blobs.js.map +1 -1
- package/dist/tar.js +1 -1
- package/dist/temporal.js +1 -1
- package/dist/types.js +1 -1
- package/dist/validity.js +1 -1
- package/dist/verify-tiers.js +1 -1
- package/dist/witness.js +1 -1
- package/package.json +2 -2
- package/src/__tests__/anchors.test.ts +1 -1
- package/src/__tests__/base-floor.test.ts +1 -1
- package/src/__tests__/carrier-tree.test.ts +1 -1
- package/src/__tests__/settlement.test.ts +1 -1
- package/src/anchors.ts +1 -1
- package/src/anomalies.ts +1 -1
- package/src/attestation.ts +1 -1
- package/src/audit.ts +2 -2
- package/src/authority.ts +1 -1
- package/src/aws-nitro-root-ca.ts +1 -1
- package/src/ceilings.ts +1 -1
- package/src/cli.ts +1 -1
- package/src/contents-hash.ts +1 -1
- package/src/export.ts +1 -1
- package/src/exports.ts +1 -1
- package/src/floors.ts +1 -1
- package/src/index.ts +1 -1
- package/src/ingest.ts +1 -1
- package/src/reconstruct.ts +1 -1
- package/src/report-json.ts +1 -1
- package/src/report-md.ts +1 -1
- package/src/rlp.ts +1 -1
- package/src/rollup-schedule.ts +105 -0
- package/src/settlement-blobs.ts +41 -21
- package/src/tar.ts +1 -1
- package/src/temporal.ts +1 -1
- package/src/types.ts +1 -1
- package/src/validity.ts +1 -1
- package/src/verify-tiers.ts +1 -1
- package/src/witness.ts +1 -1
package/src/settlement-blobs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright (c)
|
|
1
|
+
// Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The BLOB layer of a Base ceiling's settlement on Ethereum
|
|
@@ -39,8 +39,9 @@ import {
|
|
|
39
39
|
type SettlementPointer, type RlpItem,
|
|
40
40
|
} from "@mikeargento/bitgraph-verify";
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
import { BASE_MAINNET_ROLLUP, blocksAt, numberSingularBatches, type RollupSchedule } from "./rollup-schedule.js";
|
|
43
|
+
|
|
44
|
+
export { BASE_MAINNET_ROLLUP, type RollupSchedule };
|
|
44
45
|
|
|
45
46
|
export const BLOB_BYTES = 131072;
|
|
46
47
|
/** OP Stack blob encoding version 0: (4 * 31 + 3) * 1024 - 4 bytes of data per blob. */
|
|
@@ -55,7 +56,7 @@ export interface SettlementBlobsCheck {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
export interface SettlementLocated {
|
|
58
|
-
/** The Base block the batch places the transaction in,
|
|
59
|
+
/** The Base block the batch places the transaction in: its timestamp's second, and its place among the batches of that second. */
|
|
59
60
|
baseBlockNumber: number;
|
|
60
61
|
baseBlockTimestamp: number;
|
|
61
62
|
/** The batch's parent_hash (the hash of the block before), when the batch form carries one. */
|
|
@@ -89,8 +90,8 @@ export interface SettlementBlobsResult {
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
export interface SettlementBlobsOptions {
|
|
92
|
-
/**
|
|
93
|
-
rollup?:
|
|
93
|
+
/** When the rollup's blocks are stamped, which places a batch by its timestamp. Base mainnet by default. */
|
|
94
|
+
rollup?: RollupSchedule;
|
|
94
95
|
/** The L2 chain id, for rebuilding transactions out of span batches. Base mainnet by default. */
|
|
95
96
|
chainId?: bigint;
|
|
96
97
|
/** What the ceiling record says, each matched against what the batch says when given. */
|
|
@@ -292,18 +293,26 @@ export interface DecodedBatch {
|
|
|
292
293
|
blocks: Array<{ number: number; timestamp: number; parentHash: string | null; txs: BatchTx[]; complete: boolean }>;
|
|
293
294
|
}
|
|
294
295
|
|
|
296
|
+
/** A batch already identified by hash, to number a channel that cannot be numbered from its own bytes. */
|
|
297
|
+
export interface BatchPin { number: number; parentHash?: string; txHash?: string }
|
|
298
|
+
|
|
295
299
|
/**
|
|
296
300
|
* Batches out of a decompressed channel. Each is an RLP byte string
|
|
297
301
|
* `batch_version ++ content`. When `complete` is false the stream may be cut:
|
|
298
302
|
* the last batch is then read as far as it goes and marked incomplete.
|
|
303
|
+
* Singular batches are numbered together once all are read
|
|
304
|
+
* (numberSingularBatches says how); `pin` is used only where the channel
|
|
305
|
+
* alone cannot say.
|
|
299
306
|
*/
|
|
300
307
|
export function decodeBatches(
|
|
301
308
|
channel: Uint8Array,
|
|
302
309
|
complete: boolean,
|
|
303
|
-
rollup:
|
|
310
|
+
rollup: RollupSchedule,
|
|
304
311
|
chainId: bigint,
|
|
312
|
+
pin?: BatchPin,
|
|
305
313
|
): DecodedBatch[] {
|
|
306
314
|
const out: DecodedBatch[] = [];
|
|
315
|
+
const singular: Array<DecodedBatch["blocks"][number]> = [];
|
|
307
316
|
const limit = channel.length;
|
|
308
317
|
let p = 0;
|
|
309
318
|
while (p < limit) {
|
|
@@ -321,8 +330,8 @@ export function decodeBatches(
|
|
|
321
330
|
const contentStart = s.start + 1;
|
|
322
331
|
const contentEnd = Math.min(s.end, limit);
|
|
323
332
|
if (type === 0) {
|
|
324
|
-
const sb = parseSingularBatch(channel, contentStart, contentEnd, !cut
|
|
325
|
-
if (sb) out.push({ type, offset: p, blocks: [sb] });
|
|
333
|
+
const sb = parseSingularBatch(channel, contentStart, contentEnd, !cut);
|
|
334
|
+
if (sb) { singular.push(sb); out.push({ type, offset: p, blocks: [sb] }); }
|
|
326
335
|
} else if (type === 1) {
|
|
327
336
|
if (!cut) out.push({ type, offset: p, blocks: decodeSpanBatch(channel.subarray(contentStart, contentEnd), rollup, chainId) });
|
|
328
337
|
} else if (!cut) {
|
|
@@ -331,6 +340,12 @@ export function decodeBatches(
|
|
|
331
340
|
if (cut) break;
|
|
332
341
|
p = s.end;
|
|
333
342
|
}
|
|
343
|
+
if (singular.length > 0) {
|
|
344
|
+
const want = pin && { parent: pin.parentHash?.toLowerCase(), tx: pin.txHash?.toLowerCase() };
|
|
345
|
+
const at = want ? singular.findIndex((b) => (want.parent !== undefined && b.parentHash === want.parent) || (want.tx !== undefined && b.txs.some((t) => t.hash === want.tx))) : -1;
|
|
346
|
+
const numbers = numberSingularBatches(singular.map((b) => b.timestamp), rollup, at >= 0 ? { index: at, number: pin!.number } : undefined);
|
|
347
|
+
for (const [k, b] of singular.entries()) b.number = numbers[k]!;
|
|
348
|
+
}
|
|
334
349
|
return out;
|
|
335
350
|
}
|
|
336
351
|
|
|
@@ -338,9 +353,10 @@ export function decodeBatches(
|
|
|
338
353
|
* rlp([parent_hash, epoch_number, epoch_hash, timestamp, transaction_list]).
|
|
339
354
|
* `limit` is where readable bytes end; with `complete` the list must end
|
|
340
355
|
* exactly there. Returns null when not even the header fields are readable.
|
|
356
|
+
* The block's number is set by decodeBatches.
|
|
341
357
|
*/
|
|
342
358
|
function parseSingularBatch(
|
|
343
|
-
buf: Uint8Array, start: number, limit: number, complete: boolean,
|
|
359
|
+
buf: Uint8Array, start: number, limit: number, complete: boolean,
|
|
344
360
|
): DecodedBatch["blocks"][number] | null {
|
|
345
361
|
const outer = rlpSpan(buf, start, limit);
|
|
346
362
|
if (!outer) return null;
|
|
@@ -382,14 +398,7 @@ function parseSingularBatch(
|
|
|
382
398
|
}
|
|
383
399
|
if (listComplete && q !== list.end) throw new TypeError("singular batch: transaction_list overran its length");
|
|
384
400
|
if (complete && list.end !== outer.end) throw new TypeError("singular batch: bytes after transaction_list");
|
|
385
|
-
|
|
386
|
-
return { number, timestamp: Number(timestamp), parentHash: bytesToHex(parent.bytes), txs, complete: listComplete };
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
function blockNumberOf(timestamp: number, rollup: { l2GenesisTime: number; blockTime: number }): number {
|
|
390
|
-
const n = (timestamp - rollup.l2GenesisTime) / rollup.blockTime;
|
|
391
|
-
if (!Number.isInteger(n) || n < 0) throw new TypeError(`batch timestamp ${timestamp} is not on the rollup's block grid`);
|
|
392
|
-
return n;
|
|
401
|
+
return { number: -1, timestamp: Number(timestamp), parentHash: bytesToHex(parent.bytes), txs, complete: listComplete };
|
|
393
402
|
}
|
|
394
403
|
|
|
395
404
|
// ── Span batches (type 1), rebuilt into raw transactions ───────────────────
|
|
@@ -434,7 +443,7 @@ class Reader {
|
|
|
434
443
|
* here into their raw form so they can be hashed.
|
|
435
444
|
*/
|
|
436
445
|
export function decodeSpanBatch(
|
|
437
|
-
data: Uint8Array, rollup:
|
|
446
|
+
data: Uint8Array, rollup: RollupSchedule, chainId: bigint,
|
|
438
447
|
): DecodedBatch["blocks"] {
|
|
439
448
|
const r = new Reader(data);
|
|
440
449
|
const relTimestamp = r.uvarint();
|
|
@@ -500,8 +509,14 @@ export function decodeSpanBatch(
|
|
|
500
509
|
}
|
|
501
510
|
return { raw, hash: bytesToHex(keccak256(raw)) };
|
|
502
511
|
});
|
|
512
|
+
// A span batch counts on from its first block's time one block time apiece, which only describes
|
|
513
|
+
// blocks that each have a timestamp of their own; one reaching into shared seconds is refused.
|
|
503
514
|
const firstTimestamp = rollup.l2GenesisTime + Number(relTimestamp);
|
|
504
|
-
const
|
|
515
|
+
const first = blocksAt(firstTimestamp, rollup);
|
|
516
|
+
if (!first) throw new TypeError(`batch timestamp ${firstTimestamp} is not on the rollup's schedule`);
|
|
517
|
+
const lastTimestamp = firstTimestamp + (blockCount - 1) * rollup.blockTime;
|
|
518
|
+
if (first.count !== 1 || blocksAt(lastTimestamp, rollup)?.count !== 1) throw new TypeError(`span batch: its blocks from ${firstTimestamp} to ${lastTimestamp} share their seconds, so their numbers cannot be read from it`);
|
|
519
|
+
const firstBlock = first.first;
|
|
505
520
|
const blocks: DecodedBatch["blocks"] = [];
|
|
506
521
|
let k = 0;
|
|
507
522
|
for (let b = 0; b < blockCount; b++) {
|
|
@@ -635,7 +650,12 @@ export async function verifySettlementBlobs(
|
|
|
635
650
|
if (pointer.channel?.compression && pointer.channel.compression !== decomp.compression) return fail("decompress", `the channel is ${decomp.compression}, the pointer says ${pointer.channel.compression}`);
|
|
636
651
|
let batches: DecodedBatch[];
|
|
637
652
|
try {
|
|
638
|
-
|
|
653
|
+
const pinTx = (options.expect?.txHash ?? pointer.located?.txHash)?.toLowerCase();
|
|
654
|
+
batches = decodeBatches(decomp.bytes, complete, rollup, chainId, {
|
|
655
|
+
number: pointer.baseBlockNumber,
|
|
656
|
+
...(options.expect?.baseParentHash ? { parentHash: options.expect.baseParentHash } : {}),
|
|
657
|
+
...(pinTx ? { txHash: pinTx } : {}),
|
|
658
|
+
});
|
|
639
659
|
} catch (e) {
|
|
640
660
|
return fail("batches", (e as Error).message);
|
|
641
661
|
}
|
package/src/tar.ts
CHANGED
package/src/temporal.ts
CHANGED
package/src/types.ts
CHANGED
package/src/validity.ts
CHANGED
package/src/verify-tiers.ts
CHANGED
package/src/witness.ts
CHANGED