@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/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025-2026 Argento Computing Inc.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Offline audit of BitGraph evidence: `npx @mikeargento/bitgraph-audit <bundle>`.
|
|
4
4
|
|
|
5
|
-
An Audit Bundle is a portable collection of BitGraph proofs, optionally
|
|
5
|
+
An Audit Bundle is a portable collection of BitGraph proofs, optionally with the original files and a manifest, packaged as a directory, a `.tar`, or a `.tar.gz`. A folder of files with their `.bitgraph.json` proofs beside them is such a bundle. The premise: the operator's database is not the evidence. BitGraph proofs are self-contained objects, and this package lets an independent reader take a bundle, verify whatever evidence it contains fully offline, and reconstruct the sequence without asking the operator which history to trust. The on-disk format is specified in [docs/BUNDLE-FORMAT.md](https://github.com/mikeargento/bitgraph/blob/main/docs/BUNDLE-FORMAT.md).
|
|
6
6
|
|
|
7
|
-
The tool reports exactly what the evidence supports, nothing more. Incomplete input produces an incomplete reconstruction: missing proofs surface as unexplained counter positions and broken predecessor links, which means the supplied evidence cannot reconstruct those positions, not that the
|
|
7
|
+
The tool reports exactly what the evidence supports, nothing more. Incomplete input produces an incomplete reconstruction: missing proofs surface as unexplained counter positions and broken predecessor links, which means the supplied evidence cannot reconstruct those positions, not that the enclave failed to create them. Divergence between valid objects is presented, never resolved; the reader adjudicates. Proofs without their file pass through the checks that need no bytes and are reported as artifact-unavailable, never as fully verified. A file is matched to a proof when its SHA-256 is the digest the proof binds. A file that is one of a tree is not: its proof binds the tree's root, so the audit reports that proof as artifact-unavailable. Check such a file against its own proof with `verifyAttested` from `@mikeargento/bitgraph-verify`, or `bitgraph verify` from the SDK, which walk the file's hash up to the root. There is no network access at runtime of any kind.
|
|
8
8
|
|
|
9
|
-
Exactly one proof schema is supported: `bitgraph/1`.
|
|
9
|
+
Exactly one proof schema is supported: `bitgraph/1`. Proof-shaped files with any other version are rejected at ingest with the stable code `unsupported-version`. All verification semantics come from `@mikeargento/bitgraph-verify` (MIT), the same verifier anyone can run against a single proof. The `bitgraph-audit` CLI runs the whole pipeline (ingest, verification, reconstruction of each epoch's sequence from counts and predecessor hashes, anomaly classification, offline attestation validation) and writes `audit-report.json` and `audit-report.md`; `runAudit()` is the one-call library entry point, and every stage is also exported individually. See [docs/HOW-TO-AUDIT.md](https://github.com/mikeargento/bitgraph/blob/main/docs/HOW-TO-AUDIT.md) for the recipient walkthrough.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Counts order proofs inside one epoch. Epochs are separate runs of the enclave, each with its own key and a count from zero, so counts never order proofs across epochs.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Evidence in earlier formats
|
|
14
|
+
|
|
15
|
+
Bundles made from earlier proofs still audit. The tool finds each of these by what it is, not by its name: a `bitgraph-export/1` file (checked with `verifyExport` once for each file in the bundle it covers), a BitGraphed file (a file with its proof inside, unpacked and audited as the bundle it carries), block header witnesses for proofs that sign an Ethereum or Base block, and a download package from a bitgraph.ing proof page. An export with a FALSE claim fails the audit (exit 1); a claim an export does not carry never does.
|
|
14
16
|
|
|
15
17
|
## License
|
|
16
18
|
|
package/dist/anchors.js
CHANGED
package/dist/anomalies.js
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
|
import { byCounterThenHash, isIntrinsicallyValid, parseCounter, pushMap } from "./validity.js";
|
|
3
3
|
/**
|
|
4
4
|
* Cap on the flat unexplained-position list. Ranges and the total count
|
package/dist/attestation.js
CHANGED
package/dist/audit.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { AuditOptions, AuditResult, ExitFlags, IngestResult } from "./types
|
|
|
8
8
|
* this equals package.json's version, so the constant cannot drift silently
|
|
9
9
|
* across releases.
|
|
10
10
|
*/
|
|
11
|
-
export declare const AUDIT_VERSION = "0.11.
|
|
11
|
+
export declare const AUDIT_VERSION = "0.11.1";
|
|
12
12
|
/** The audit package's own version. */
|
|
13
13
|
export declare function auditToolVersion(): string;
|
|
14
14
|
/** Options for auditIngest(): the audit options plus the run stamp. */
|
package/dist/audit.js
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
|
* Audit orchestrator: the full offline pipeline in canonical order.
|
|
4
4
|
*
|
|
@@ -36,7 +36,7 @@ import { validateAttestations } from "./attestation.js";
|
|
|
36
36
|
* this equals package.json's version, so the constant cannot drift silently
|
|
37
37
|
* across releases.
|
|
38
38
|
*/
|
|
39
|
-
export const AUDIT_VERSION = "0.11.
|
|
39
|
+
export const AUDIT_VERSION = "0.11.1";
|
|
40
40
|
/** The audit package's own version. */
|
|
41
41
|
export function auditToolVersion() {
|
|
42
42
|
return AUDIT_VERSION;
|
package/dist/authority.js
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
|
import { pushMap } from "./validity.js";
|
|
3
3
|
/**
|
|
4
4
|
* Analyze authority structure over every observed proof (including
|
package/dist/ceilings.js
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
|
* Ceilings in time (bitgraph-ceiling/1): each ceiling file in the bundle is
|
|
4
4
|
* matched to its proof by proofHash and checked with verifyCeiling, offline.
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Copyright (c)
|
|
2
|
+
// Copyright (c) 2025-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
|
|
3
3
|
/**
|
|
4
4
|
* bitgraph-audit CLI: run the full offline audit pipeline over a bundle
|
|
5
5
|
* and write audit-report.json and/or audit-report.md.
|
package/dist/contents-hash.js
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
|
* Deterministic bundle contents hash, per docs/BUNDLE-FORMAT.md section 8.
|
|
4
4
|
*
|
package/dist/export.js
CHANGED
package/dist/exports.js
CHANGED
package/dist/floors.js
CHANGED
package/dist/index.js
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
|
export { ingestBundle, ingestEntries, streamMatchedArtifacts, streamArtifactsByHash, DEFAULT_INGEST_LIMITS } from "./ingest.js";
|
|
3
3
|
export { verifyObservedProofs } from "./verify-tiers.js";
|
|
4
4
|
export { reconstructChains } from "./reconstruct.js";
|
package/dist/ingest.js
CHANGED
package/dist/reconstruct.js
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
|
import { byCounterThenHash, isIntrinsicallyValid, parseCounter, pushMap } from "./validity.js";
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
4
|
// Public API
|
package/dist/report-json.js
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
|
* JSON report builder: turns an AuditResult into the audit-report.json
|
|
4
4
|
* object (schema "bitgraph-audit-report/1").
|
package/dist/report-md.js
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
|
* Markdown report builder: turns an AuditResult into audit-report.md.
|
|
4
4
|
*
|
package/dist/rlp.js
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
|
* Decode a complete RLP buffer whose top level is a list. Throws Error
|
|
4
4
|
* with a precise message on malformed input or trailing bytes.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When a rollup's blocks are stamped.
|
|
3
|
+
*
|
|
4
|
+
* Base made one block every two seconds through block 53,556,126, so a
|
|
5
|
+
* block's time was genesis + 2 * number and a timestamp named one block.
|
|
6
|
+
* From block 53,556,127 (stamped 1,793,901,601, 2026-11-05 18:00:01 UTC) it
|
|
7
|
+
* makes five blocks a second. A block's timestamp is still whole seconds, so
|
|
8
|
+
* five consecutive blocks share each one: a timestamp names a second, and a
|
|
9
|
+
* block is one of the five in it.
|
|
10
|
+
*
|
|
11
|
+
* Both facts were read from Base itself: blocks 53,556,127 to 53,556,131 are
|
|
12
|
+
* stamped 1,793,901,601 and block 53,556,132 is stamped 1,793,901,602.
|
|
13
|
+
*
|
|
14
|
+
* Nothing here is trusted for what a record proves. The schedule only says
|
|
15
|
+
* when to look and where a batch sits among its neighbours; what is found is
|
|
16
|
+
* then checked by hash.
|
|
17
|
+
*/
|
|
18
|
+
export interface RollupSchedule {
|
|
19
|
+
l2GenesisTime: number;
|
|
20
|
+
/** Seconds per block before `subSecond` starts, and always for a rollup that has none. */
|
|
21
|
+
blockTime: number;
|
|
22
|
+
/** From `fromBlock`, stamped `fromTime`, each whole second holds `blocksPerSecond` blocks. */
|
|
23
|
+
subSecond?: {
|
|
24
|
+
fromBlock: number;
|
|
25
|
+
fromTime: number;
|
|
26
|
+
blocksPerSecond: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare const BASE_MAINNET_ROLLUP: RollupSchedule;
|
|
30
|
+
/** The timestamp the schedule gives block `blockNumber`, in seconds. */
|
|
31
|
+
export declare function timeOfBlock(blockNumber: number, s: RollupSchedule): number;
|
|
32
|
+
/** The blocks stamped `timestamp`: the first one and how many. Null when the schedule stamps no block with it. */
|
|
33
|
+
export declare function blocksAt(timestamp: number, s: RollupSchedule): {
|
|
34
|
+
first: number;
|
|
35
|
+
count: number;
|
|
36
|
+
} | null;
|
|
37
|
+
/** The newest block the schedule has stamped by `timestamp` (the head, by the clock alone). */
|
|
38
|
+
export declare function headAt(timestamp: number, s: RollupSchedule): number;
|
|
39
|
+
/**
|
|
40
|
+
* Block numbers for the singular batches of one channel, in the channel's
|
|
41
|
+
* order. A singular batch carries its block's timestamp and its parent's
|
|
42
|
+
* hash, never its number. Where a timestamp names one block the number is
|
|
43
|
+
* read from it. Where it names several, the batches sharing it are counted
|
|
44
|
+
* off in order: a channel holds consecutive blocks, so a second in the
|
|
45
|
+
* middle holds all of its blocks, the channel's last second holds the first
|
|
46
|
+
* of its blocks, and the channel's first second holds the last of its
|
|
47
|
+
* blocks.
|
|
48
|
+
*
|
|
49
|
+
* One case has no answer from the channel alone: every batch shares one
|
|
50
|
+
* second and there are fewer than the second holds. `pin` then places them:
|
|
51
|
+
* the index of a batch already identified by hash, and its block's number.
|
|
52
|
+
* Without it they are counted from the second's first block.
|
|
53
|
+
*/
|
|
54
|
+
export declare function numberSingularBatches(timestamps: readonly number[], s: RollupSchedule, pin?: {
|
|
55
|
+
index: number;
|
|
56
|
+
number: number;
|
|
57
|
+
}): number[];
|
|
58
|
+
//# sourceMappingURL=rollup-schedule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-schedule.d.ts","sourceRoot":"","sources":["../src/rollup-schedule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,0FAA0F;IAC1F,SAAS,EAAE,MAAM,CAAC;IAClB,8FAA8F;IAC9F,SAAS,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9E;AAED,eAAO,MAAM,mBAAmB,EAAE,cAIhC,CAAC;AAEH,wEAAwE;AACxE,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,GAAG,MAAM,CAI1E;AAED,kHAAkH;AAClH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAStG;AAED,+FAA+F;AAC/F,wBAAgB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,GAAG,MAAM,CAInE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,EAAE,CA+BzI"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When a rollup's blocks are stamped.
|
|
3
|
+
*
|
|
4
|
+
* Base made one block every two seconds through block 53,556,126, so a
|
|
5
|
+
* block's time was genesis + 2 * number and a timestamp named one block.
|
|
6
|
+
* From block 53,556,127 (stamped 1,793,901,601, 2026-11-05 18:00:01 UTC) it
|
|
7
|
+
* makes five blocks a second. A block's timestamp is still whole seconds, so
|
|
8
|
+
* five consecutive blocks share each one: a timestamp names a second, and a
|
|
9
|
+
* block is one of the five in it.
|
|
10
|
+
*
|
|
11
|
+
* Both facts were read from Base itself: blocks 53,556,127 to 53,556,131 are
|
|
12
|
+
* stamped 1,793,901,601 and block 53,556,132 is stamped 1,793,901,602.
|
|
13
|
+
*
|
|
14
|
+
* Nothing here is trusted for what a record proves. The schedule only says
|
|
15
|
+
* when to look and where a batch sits among its neighbours; what is found is
|
|
16
|
+
* then checked by hash.
|
|
17
|
+
*/
|
|
18
|
+
export const BASE_MAINNET_ROLLUP = Object.freeze({
|
|
19
|
+
l2GenesisTime: 1686789347,
|
|
20
|
+
blockTime: 2,
|
|
21
|
+
subSecond: Object.freeze({ fromBlock: 53_556_127, fromTime: 1_793_901_601, blocksPerSecond: 5 }),
|
|
22
|
+
});
|
|
23
|
+
/** The timestamp the schedule gives block `blockNumber`, in seconds. */
|
|
24
|
+
export function timeOfBlock(blockNumber, s) {
|
|
25
|
+
const sub = s.subSecond;
|
|
26
|
+
if (sub && blockNumber >= sub.fromBlock)
|
|
27
|
+
return sub.fromTime + Math.floor((blockNumber - sub.fromBlock) / sub.blocksPerSecond);
|
|
28
|
+
return s.l2GenesisTime + blockNumber * s.blockTime;
|
|
29
|
+
}
|
|
30
|
+
/** The blocks stamped `timestamp`: the first one and how many. Null when the schedule stamps no block with it. */
|
|
31
|
+
export function blocksAt(timestamp, s) {
|
|
32
|
+
const sub = s.subSecond;
|
|
33
|
+
if (sub && timestamp >= sub.fromTime) {
|
|
34
|
+
if (!Number.isInteger(timestamp))
|
|
35
|
+
return null;
|
|
36
|
+
return { first: sub.fromBlock + (timestamp - sub.fromTime) * sub.blocksPerSecond, count: sub.blocksPerSecond };
|
|
37
|
+
}
|
|
38
|
+
const n = (timestamp - s.l2GenesisTime) / s.blockTime;
|
|
39
|
+
if (!Number.isInteger(n) || n < 0)
|
|
40
|
+
return null;
|
|
41
|
+
return { first: n, count: 1 };
|
|
42
|
+
}
|
|
43
|
+
/** The newest block the schedule has stamped by `timestamp` (the head, by the clock alone). */
|
|
44
|
+
export function headAt(timestamp, s) {
|
|
45
|
+
const sub = s.subSecond;
|
|
46
|
+
if (sub && timestamp >= sub.fromTime)
|
|
47
|
+
return sub.fromBlock + (Math.floor(timestamp) - sub.fromTime + 1) * sub.blocksPerSecond - 1;
|
|
48
|
+
return Math.max(0, Math.floor((timestamp - s.l2GenesisTime) / s.blockTime));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Block numbers for the singular batches of one channel, in the channel's
|
|
52
|
+
* order. A singular batch carries its block's timestamp and its parent's
|
|
53
|
+
* hash, never its number. Where a timestamp names one block the number is
|
|
54
|
+
* read from it. Where it names several, the batches sharing it are counted
|
|
55
|
+
* off in order: a channel holds consecutive blocks, so a second in the
|
|
56
|
+
* middle holds all of its blocks, the channel's last second holds the first
|
|
57
|
+
* of its blocks, and the channel's first second holds the last of its
|
|
58
|
+
* blocks.
|
|
59
|
+
*
|
|
60
|
+
* One case has no answer from the channel alone: every batch shares one
|
|
61
|
+
* second and there are fewer than the second holds. `pin` then places them:
|
|
62
|
+
* the index of a batch already identified by hash, and its block's number.
|
|
63
|
+
* Without it they are counted from the second's first block.
|
|
64
|
+
*/
|
|
65
|
+
export function numberSingularBatches(timestamps, s, pin) {
|
|
66
|
+
const out = [];
|
|
67
|
+
let i = 0;
|
|
68
|
+
while (i < timestamps.length) {
|
|
69
|
+
const t = timestamps[i];
|
|
70
|
+
const at = blocksAt(t, s);
|
|
71
|
+
if (!at)
|
|
72
|
+
throw new TypeError(`batch timestamp ${t} is not on the rollup's schedule`);
|
|
73
|
+
let j = i;
|
|
74
|
+
while (j < timestamps.length && timestamps[j] === t)
|
|
75
|
+
j++;
|
|
76
|
+
const run = j - i;
|
|
77
|
+
if (run > at.count)
|
|
78
|
+
throw new TypeError(`${run} batches are stamped ${t}, which holds ${at.count} block${at.count === 1 ? "" : "s"}`);
|
|
79
|
+
const opens = i === 0;
|
|
80
|
+
const closes = j === timestamps.length;
|
|
81
|
+
let offset = 0;
|
|
82
|
+
if (run < at.count) {
|
|
83
|
+
if (!opens && !closes)
|
|
84
|
+
throw new TypeError(`${run} batches are stamped ${t} in the middle of a channel, which holds ${at.count} blocks`);
|
|
85
|
+
if (opens && !closes)
|
|
86
|
+
offset = at.count - run;
|
|
87
|
+
else if (opens && closes && pin && pin.index >= i && pin.index < j) {
|
|
88
|
+
offset = pin.number - pin.index - at.first;
|
|
89
|
+
if (offset < 0 || offset + run > at.count)
|
|
90
|
+
throw new TypeError(`block ${pin.number} is not stamped ${t} on the rollup's schedule`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (let k = 0; k < run; k++)
|
|
94
|
+
out.push(at.first + offset + k);
|
|
95
|
+
i = j;
|
|
96
|
+
}
|
|
97
|
+
// Counting off is only right for consecutive blocks, so a gap where seconds are shared is refused.
|
|
98
|
+
const shared = s.subSecond?.fromTime ?? Number.POSITIVE_INFINITY;
|
|
99
|
+
for (let k = 1; k < out.length; k++) {
|
|
100
|
+
if (timestamps[k] >= shared && out[k] !== out[k - 1] + 1)
|
|
101
|
+
throw new TypeError(`the batches stamped ${timestamps[k - 1]} and ${timestamps[k]} are not consecutive blocks`);
|
|
102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,SAAS,CAAC,SAAS,GAAG,CAAC,MAAM,mBAAmB,CAAC,2BAA2B,CAAC,CAAC;YACrI,CAAC;QACH,CAAC;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;YAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC,GAAG,CAAC,CAAC;IACR,CAAC;IACD,mGAAmG;IACnG,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,QAAQ,IAAI,MAAM,CAAC,iBAAiB,CAAC;IACjE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,UAAU,CAAC,CAAC,CAAE,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAE,GAAG,CAAC;YAAE,MAAM,IAAI,SAAS,CAAC,uBAAuB,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,UAAU,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC;IAC9K,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { type SettlementPointer } from "@mikeargento/bitgraph-verify";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
l2GenesisTime: 1686789347;
|
|
5
|
-
blockTime: 2;
|
|
6
|
-
}>;
|
|
2
|
+
import { BASE_MAINNET_ROLLUP, type RollupSchedule } from "./rollup-schedule.js";
|
|
3
|
+
export { BASE_MAINNET_ROLLUP, type RollupSchedule };
|
|
7
4
|
export declare const BLOB_BYTES = 131072;
|
|
8
5
|
/** OP Stack blob encoding version 0: (4 * 31 + 3) * 1024 - 4 bytes of data per blob. */
|
|
9
6
|
export declare const MAX_BLOB_DATA_BYTES = 130044;
|
|
@@ -13,7 +10,7 @@ export interface SettlementBlobsCheck {
|
|
|
13
10
|
detail?: string;
|
|
14
11
|
}
|
|
15
12
|
export interface SettlementLocated {
|
|
16
|
-
/** The Base block the batch places the transaction in,
|
|
13
|
+
/** The Base block the batch places the transaction in: its timestamp's second, and its place among the batches of that second. */
|
|
17
14
|
baseBlockNumber: number;
|
|
18
15
|
baseBlockTimestamp: number;
|
|
19
16
|
/** The batch's parent_hash (the hash of the block before), when the batch form carries one. */
|
|
@@ -45,11 +42,8 @@ export interface SettlementBlobsResult {
|
|
|
45
42
|
located?: SettlementLocated;
|
|
46
43
|
}
|
|
47
44
|
export interface SettlementBlobsOptions {
|
|
48
|
-
/**
|
|
49
|
-
rollup?:
|
|
50
|
-
l2GenesisTime: number;
|
|
51
|
-
blockTime: number;
|
|
52
|
-
};
|
|
45
|
+
/** When the rollup's blocks are stamped, which places a batch by its timestamp. Base mainnet by default. */
|
|
46
|
+
rollup?: RollupSchedule;
|
|
53
47
|
/** The L2 chain id, for rebuilding transactions out of span batches. Base mainnet by default. */
|
|
54
48
|
chainId?: bigint;
|
|
55
49
|
/** What the ceiling record says, each matched against what the batch says when given. */
|
|
@@ -99,15 +93,21 @@ export interface DecodedBatch {
|
|
|
99
93
|
complete: boolean;
|
|
100
94
|
}>;
|
|
101
95
|
}
|
|
96
|
+
/** A batch already identified by hash, to number a channel that cannot be numbered from its own bytes. */
|
|
97
|
+
export interface BatchPin {
|
|
98
|
+
number: number;
|
|
99
|
+
parentHash?: string;
|
|
100
|
+
txHash?: string;
|
|
101
|
+
}
|
|
102
102
|
/**
|
|
103
103
|
* Batches out of a decompressed channel. Each is an RLP byte string
|
|
104
104
|
* `batch_version ++ content`. When `complete` is false the stream may be cut:
|
|
105
105
|
* the last batch is then read as far as it goes and marked incomplete.
|
|
106
|
+
* Singular batches are numbered together once all are read
|
|
107
|
+
* (numberSingularBatches says how); `pin` is used only where the channel
|
|
108
|
+
* alone cannot say.
|
|
106
109
|
*/
|
|
107
|
-
export declare function decodeBatches(channel: Uint8Array, complete: boolean, rollup:
|
|
108
|
-
l2GenesisTime: number;
|
|
109
|
-
blockTime: number;
|
|
110
|
-
}, chainId: bigint): DecodedBatch[];
|
|
110
|
+
export declare function decodeBatches(channel: Uint8Array, complete: boolean, rollup: RollupSchedule, chainId: bigint, pin?: BatchPin): DecodedBatch[];
|
|
111
111
|
/**
|
|
112
112
|
* A span batch (OP Stack Delta): prefix (rel_timestamp, l1_origin_num,
|
|
113
113
|
* parent_check, l1_origin_check) then payload (block_count, origin_bits,
|
|
@@ -115,10 +115,7 @@ export declare function decodeBatches(channel: Uint8Array, complete: boolean, ro
|
|
|
115
115
|
* recipients, data, nonces, gas limits, protected bits) and are rebuilt
|
|
116
116
|
* here into their raw form so they can be hashed.
|
|
117
117
|
*/
|
|
118
|
-
export declare function decodeSpanBatch(data: Uint8Array, rollup:
|
|
119
|
-
l2GenesisTime: number;
|
|
120
|
-
blockTime: number;
|
|
121
|
-
}, chainId: bigint): DecodedBatch["blocks"];
|
|
118
|
+
export declare function decodeSpanBatch(data: Uint8Array, rollup: RollupSchedule, chainId: bigint): DecodedBatch["blocks"];
|
|
122
119
|
/**
|
|
123
120
|
* Verify blob bytes against a settlement pointer and locate the ceiling
|
|
124
121
|
* transaction inside them. `blobBytesByVersionedHash` holds the bytes the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settlement-blobs.d.ts","sourceRoot":"","sources":["../src/settlement-blobs.ts"],"names":[],"mappings":"AAmCA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,8BAA8B,CAAC;AAEtC,
|
|
1
|
+
{"version":3,"file":"settlement-blobs.d.ts","sourceRoot":"","sources":["../src/settlement-blobs.ts"],"names":[],"mappings":"AAmCA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,mBAAmB,EAAmC,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEj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;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;AAElF;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,MAAM,EACf,GAAG,CAAC,EAAE,QAAQ,GACb,YAAY,EAAE,CAqChB;AAwFD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GACxD,YAAY,CAAC,QAAQ,CAAC,CAgFxB;AAqBD;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,iBAAiB,EAC1B,wBAAwB,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EACzD,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,qBAAqB,CAAC,CAqJhC"}
|
package/dist/settlement-blobs.js
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
|
* The BLOB layer of a Base ceiling's settlement on Ethereum
|
|
4
4
|
* (bitgraph-settlement/1). The pointer layer, in bitgraph-verify, shows that
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import { brotliDecompressSync, inflateSync, constants as zlibConstants } from "node:zlib";
|
|
34
34
|
import { keccak256, rlpEncode, versionedHashOf, evmHexToBytes as hexToBytes, evmBytesToHex as bytesToHex, } from "@mikeargento/bitgraph-verify";
|
|
35
|
-
|
|
36
|
-
export
|
|
35
|
+
import { BASE_MAINNET_ROLLUP, blocksAt, numberSingularBatches } from "./rollup-schedule.js";
|
|
36
|
+
export { BASE_MAINNET_ROLLUP };
|
|
37
37
|
export const BLOB_BYTES = 131072;
|
|
38
38
|
/** OP Stack blob encoding version 0: (4 * 31 + 3) * 1024 - 4 bytes of data per blob. */
|
|
39
39
|
export const MAX_BLOB_DATA_BYTES = 130044;
|
|
@@ -225,9 +225,13 @@ export function decompressChannel(data, complete) {
|
|
|
225
225
|
* Batches out of a decompressed channel. Each is an RLP byte string
|
|
226
226
|
* `batch_version ++ content`. When `complete` is false the stream may be cut:
|
|
227
227
|
* the last batch is then read as far as it goes and marked incomplete.
|
|
228
|
+
* Singular batches are numbered together once all are read
|
|
229
|
+
* (numberSingularBatches says how); `pin` is used only where the channel
|
|
230
|
+
* alone cannot say.
|
|
228
231
|
*/
|
|
229
|
-
export function decodeBatches(channel, complete, rollup, chainId) {
|
|
232
|
+
export function decodeBatches(channel, complete, rollup, chainId, pin) {
|
|
230
233
|
const out = [];
|
|
234
|
+
const singular = [];
|
|
231
235
|
const limit = channel.length;
|
|
232
236
|
let p = 0;
|
|
233
237
|
while (p < limit) {
|
|
@@ -250,9 +254,11 @@ export function decodeBatches(channel, complete, rollup, chainId) {
|
|
|
250
254
|
const contentStart = s.start + 1;
|
|
251
255
|
const contentEnd = Math.min(s.end, limit);
|
|
252
256
|
if (type === 0) {
|
|
253
|
-
const sb = parseSingularBatch(channel, contentStart, contentEnd, !cut
|
|
254
|
-
if (sb)
|
|
257
|
+
const sb = parseSingularBatch(channel, contentStart, contentEnd, !cut);
|
|
258
|
+
if (sb) {
|
|
259
|
+
singular.push(sb);
|
|
255
260
|
out.push({ type, offset: p, blocks: [sb] });
|
|
261
|
+
}
|
|
256
262
|
}
|
|
257
263
|
else if (type === 1) {
|
|
258
264
|
if (!cut)
|
|
@@ -265,14 +271,22 @@ export function decodeBatches(channel, complete, rollup, chainId) {
|
|
|
265
271
|
break;
|
|
266
272
|
p = s.end;
|
|
267
273
|
}
|
|
274
|
+
if (singular.length > 0) {
|
|
275
|
+
const want = pin && { parent: pin.parentHash?.toLowerCase(), tx: pin.txHash?.toLowerCase() };
|
|
276
|
+
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;
|
|
277
|
+
const numbers = numberSingularBatches(singular.map((b) => b.timestamp), rollup, at >= 0 ? { index: at, number: pin.number } : undefined);
|
|
278
|
+
for (const [k, b] of singular.entries())
|
|
279
|
+
b.number = numbers[k];
|
|
280
|
+
}
|
|
268
281
|
return out;
|
|
269
282
|
}
|
|
270
283
|
/**
|
|
271
284
|
* rlp([parent_hash, epoch_number, epoch_hash, timestamp, transaction_list]).
|
|
272
285
|
* `limit` is where readable bytes end; with `complete` the list must end
|
|
273
286
|
* exactly there. Returns null when not even the header fields are readable.
|
|
287
|
+
* The block's number is set by decodeBatches.
|
|
274
288
|
*/
|
|
275
|
-
function parseSingularBatch(buf, start, limit, complete
|
|
289
|
+
function parseSingularBatch(buf, start, limit, complete) {
|
|
276
290
|
const outer = rlpSpan(buf, start, limit);
|
|
277
291
|
if (!outer)
|
|
278
292
|
return null;
|
|
@@ -333,14 +347,7 @@ function parseSingularBatch(buf, start, limit, complete, rollup) {
|
|
|
333
347
|
throw new TypeError("singular batch: transaction_list overran its length");
|
|
334
348
|
if (complete && list.end !== outer.end)
|
|
335
349
|
throw new TypeError("singular batch: bytes after transaction_list");
|
|
336
|
-
|
|
337
|
-
return { number, timestamp: Number(timestamp), parentHash: bytesToHex(parent.bytes), txs, complete: listComplete };
|
|
338
|
-
}
|
|
339
|
-
function blockNumberOf(timestamp, rollup) {
|
|
340
|
-
const n = (timestamp - rollup.l2GenesisTime) / rollup.blockTime;
|
|
341
|
-
if (!Number.isInteger(n) || n < 0)
|
|
342
|
-
throw new TypeError(`batch timestamp ${timestamp} is not on the rollup's block grid`);
|
|
343
|
-
return n;
|
|
350
|
+
return { number: -1, timestamp: Number(timestamp), parentHash: bytesToHex(parent.bytes), txs, complete: listComplete };
|
|
344
351
|
}
|
|
345
352
|
// ── Span batches (type 1), rebuilt into raw transactions ───────────────────
|
|
346
353
|
class Reader {
|
|
@@ -474,8 +481,16 @@ export function decodeSpanBatch(data, rollup, chainId) {
|
|
|
474
481
|
}
|
|
475
482
|
return { raw, hash: bytesToHex(keccak256(raw)) };
|
|
476
483
|
});
|
|
484
|
+
// A span batch counts on from its first block's time one block time apiece, which only describes
|
|
485
|
+
// blocks that each have a timestamp of their own; one reaching into shared seconds is refused.
|
|
477
486
|
const firstTimestamp = rollup.l2GenesisTime + Number(relTimestamp);
|
|
478
|
-
const
|
|
487
|
+
const first = blocksAt(firstTimestamp, rollup);
|
|
488
|
+
if (!first)
|
|
489
|
+
throw new TypeError(`batch timestamp ${firstTimestamp} is not on the rollup's schedule`);
|
|
490
|
+
const lastTimestamp = firstTimestamp + (blockCount - 1) * rollup.blockTime;
|
|
491
|
+
if (first.count !== 1 || blocksAt(lastTimestamp, rollup)?.count !== 1)
|
|
492
|
+
throw new TypeError(`span batch: its blocks from ${firstTimestamp} to ${lastTimestamp} share their seconds, so their numbers cannot be read from it`);
|
|
493
|
+
const firstBlock = first.first;
|
|
479
494
|
const blocks = [];
|
|
480
495
|
let k = 0;
|
|
481
496
|
for (let b = 0; b < blockCount; b++) {
|
|
@@ -621,7 +636,12 @@ export async function verifySettlementBlobs(pointer, blobBytesByVersionedHash, o
|
|
|
621
636
|
return fail("decompress", `the channel is ${decomp.compression}, the pointer says ${pointer.channel.compression}`);
|
|
622
637
|
let batches;
|
|
623
638
|
try {
|
|
624
|
-
|
|
639
|
+
const pinTx = (options.expect?.txHash ?? pointer.located?.txHash)?.toLowerCase();
|
|
640
|
+
batches = decodeBatches(decomp.bytes, complete, rollup, chainId, {
|
|
641
|
+
number: pointer.baseBlockNumber,
|
|
642
|
+
...(options.expect?.baseParentHash ? { parentHash: options.expect.baseParentHash } : {}),
|
|
643
|
+
...(pinTx ? { txHash: pinTx } : {}),
|
|
644
|
+
});
|
|
625
645
|
}
|
|
626
646
|
catch (e) {
|
|
627
647
|
return fail("batches", e.message);
|