@mikeargento/bitgraph-verify 1.13.1 → 1.15.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 +1 -1
- package/dist/__tests__/carrier.test.js +19 -0
- package/dist/__tests__/carrier.test.js.map +1 -1
- package/dist/__tests__/carrier2.test.d.ts +2 -0
- package/dist/__tests__/carrier2.test.d.ts.map +1 -0
- package/dist/__tests__/carrier2.test.js +172 -0
- package/dist/__tests__/carrier2.test.js.map +1 -0
- package/dist/__tests__/ceiling.test.d.ts +8 -0
- package/dist/__tests__/ceiling.test.d.ts.map +1 -0
- package/dist/__tests__/ceiling.test.js +247 -0
- package/dist/__tests__/ceiling.test.js.map +1 -0
- package/dist/__tests__/settlement.test.d.ts +12 -0
- package/dist/__tests__/settlement.test.d.ts.map +1 -0
- package/dist/__tests__/settlement.test.js +185 -0
- package/dist/__tests__/settlement.test.js.map +1 -0
- package/dist/carrier-assemble.d.ts +33 -0
- package/dist/carrier-assemble.d.ts.map +1 -0
- package/dist/carrier-assemble.js +57 -0
- package/dist/carrier-assemble.js.map +1 -0
- package/dist/carrier-verify.d.ts +47 -1
- package/dist/carrier-verify.d.ts.map +1 -1
- package/dist/carrier-verify.js +292 -53
- package/dist/carrier-verify.js.map +1 -1
- package/dist/carrier.d.ts +93 -3
- package/dist/carrier.d.ts.map +1 -1
- package/dist/carrier.js +144 -19
- package/dist/carrier.js.map +1 -1
- package/dist/ceiling-evm.d.ts +49 -0
- package/dist/ceiling-evm.d.ts.map +1 -0
- package/dist/ceiling-evm.js +331 -0
- package/dist/ceiling-evm.js.map +1 -0
- package/dist/ceiling-trie.d.ts +9 -0
- package/dist/ceiling-trie.d.ts.map +1 -0
- package/dist/ceiling-trie.js +113 -0
- package/dist/ceiling-trie.js.map +1 -0
- package/dist/ceiling.d.ts +123 -0
- package/dist/ceiling.d.ts.map +1 -0
- package/dist/ceiling.js +247 -0
- package/dist/ceiling.js.map +1 -0
- package/dist/fuse-member.js +2 -2
- package/dist/fuse-member.js.map +1 -1
- package/dist/fuse-verify.js +3 -3
- package/dist/fuse-verify.js.map +1 -1
- package/dist/fuse.d.ts +34 -2
- package/dist/fuse.d.ts.map +1 -1
- package/dist/fuse.js +83 -6
- package/dist/fuse.js.map +1 -1
- package/dist/index.d.ts +15 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/nitro.d.ts +128 -0
- package/dist/nitro.d.ts.map +1 -0
- package/dist/nitro.js +551 -0
- package/dist/nitro.js.map +1 -0
- package/dist/settlement.d.ts +114 -0
- package/dist/settlement.d.ts.map +1 -0
- package/dist/settlement.js +194 -0
- package/dist/settlement.js.map +1 -0
- package/package.json +2 -1
- package/src/__tests__/carrier.test.ts +18 -0
- package/src/__tests__/carrier2.test.ts +193 -0
- package/src/__tests__/ceiling.test.ts +281 -0
- package/src/__tests__/fixtures/carrier2/ceiling-26088459.witness.json +1 -0
- package/src/__tests__/fixtures/carrier2/ceiling-4548.anchor.json +1 -0
- package/src/__tests__/fixtures/carrier2/demo4546.ceiling.json +106 -0
- package/src/__tests__/fixtures/carrier2/demo4546.proof.json +47 -0
- package/src/__tests__/fixtures/carrier2/demo4546.txt +29 -0
- package/src/__tests__/fixtures/carrier2/floor-26088457.witness.json +1 -0
- package/src/__tests__/fixtures/carrier2/floor-4542.anchor.json +1 -0
- package/src/__tests__/fixtures/ceiling/floor-26037892.header.hex +1 -0
- package/src/__tests__/fixtures/settlement/pointer-51979918-tx1.json +39 -0
- package/src/__tests__/fixtures/settlement/pointer-51979918.json +69 -0
- package/src/__tests__/settlement.test.ts +215 -0
- package/src/carrier-assemble.ts +74 -0
- package/src/carrier-verify.ts +328 -47
- package/src/carrier.ts +174 -18
- package/src/ceiling-evm.ts +326 -0
- package/src/ceiling-trie.ts +112 -0
- package/src/ceiling.ts +333 -0
- package/src/fuse-member.ts +2 -2
- package/src/fuse-verify.ts +3 -3
- package/src/fuse.ts +93 -6
- package/src/index.ts +42 -2
- package/src/nitro.ts +602 -0
- package/src/settlement.ts +263 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "bitgraph-settlement/1",
|
|
3
|
+
"baseBlockNumber": 51979918,
|
|
4
|
+
"baseBlockHash": "0x6844d628876ff2663cbd7f8b9bc39b0dc9a86a1d18d68ac26474ea63c6a81d6f",
|
|
5
|
+
"l1": {
|
|
6
|
+
"chainId": 1,
|
|
7
|
+
"txHash": "0xcb575f2482a33ce5678997adcb082d4b68f7927c932a07a7a89090e61c6ea63a",
|
|
8
|
+
"rawTx": "0x03f9013b01832571d584959b8f808501c0d2ae8082520894ff000000000000000000000000000000000084538080c0843b9aca00f8c6a0018efc046e94610e2530344caf1574e507a3182e1a975fb25b032ec1434a3f5ca001c01a93e0e3cd2212776aa2d4cc4e0c07c85cb75b968525f4e5859bae6773c4a00118b59a40847e830edd78f12799a36b697087938f5be61d6aca024f98c9b79ba00120c9a9f71037bbe073b4979641a40642a8d6e9babb851bd7e513981f1316d2a0013b850872322a5032994968f043cac34ddf72cb04e387d6b86ac268990b5a17a001b2946a71b7c1e08dff34496e274da1e5ef2dbedd62ed6bab6b07c12d08302701a0f48e45e81f193edea8a7f2e319169201ea084490a282ebfa944a53155125ba90a037f9784866387921294f047d9e00eae3acf249add9880889f797784c496ea9b1",
|
|
9
|
+
"blockNumber": 26088463,
|
|
10
|
+
"blockHash": "0x8608654cd9d6d66c2ce8a80108db7e5202a6d9ad0072f8c81353cc988d3a93f2",
|
|
11
|
+
"blockTimestamp": 1790749235,
|
|
12
|
+
"blockHeader": "0xf90289a0bd893b925b3482c78646c1df70696e0d301cd5d09dcc34dc2ecc24441e4bc40ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794396343362be2a4da1ce0c1c210945346fb82aa49a0e6bd281387b53a52427452d620531da5d0c670d1a72feacf6d4534700bbdad93a083e423e98cf59e848d311a37f7b9511e8ecbdf2f69a3d9a0a96df448eb593dd7a0c31336933abc1b6e3e3f2c8dbbe2ccc65d4bb9179e665cbb7a06b7ff14085242b90100fff3f3fbffffb9fdefffebfdfffebfdfdfdfffbdfebffffefbfff5f7fefeffebbedfffffeffdff7ff7f2d7cbbdfbfffbbffffdffdfffefe71fbfefb9fffebfffffffffdf7efffff9797fedffdf7fffbbeef7ffbd7e5efdbfffff7fbfbff7fbffeb7ffffeabef6efcffffbfff6fbfffbff3ff7dffafff7edfbefffff7fdff7fbf9b74bffdfefd7fffffeddc737ffa5fffff7fdde9f7f7bffff7bf6f7ffdfcffffdf7dbfffffffbfdfffffdff7f7effffbffdfdfffbeafffbfff7dbaffffffefe7d7e37faf77dffef3ffcffdfa75fe7b7fbd77fe7fe7ffff77ff3fffffffdfffffffdfff7ff7fffffffffe7fbdafbffffeffffb77fe7ffff7dfbfbfff7dbf6ffdf8084018e140f84039387008401ff939d846abcaa339be29ca82051756173617220287175617361722e77696e2920e29ca8a0aec208249057820706989e2a8d4882c6157bffb6f112847ca25c02b90f8bb17088000000000000000084057644a9a096b80d5bb80122a62a3905a4df56e93396c4cf0170a22efb1fdb0f1fe35307b3830e0000840ac7fb8ba0aa4880a6b37d3438d341144ce67680506b21b26e54a90835ce3e8aee0b44a3c9a0e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
|
13
|
+
"txIndex": 18,
|
|
14
|
+
"txInclusionProof": [
|
|
15
|
+
"0xf90131a0fcf4c1b6c3daaf8b4161626c0ed9ed20d4dda4438ac031b46a3a591c70ae3628a0d7b589907c8a5208ea55ae515cf9ee745d8e345f70260f3209e8056af35dbb2fa06ed025ba6929892c332be304b1cae217c390e16e73947c1777023bd6f9aad935a0995d136362f36671287a4eed2b7d0a6648b6d09d1e4c0cbfbf505b40a6452b4fa0c8396e60f6bd3f7eb429d358ecacc46ff149613bf5178c0664dc5070d8e8733ca0aa6c0b1d5e761bf8099cad7b1490374d7a919e439972be8c20a1ae13d1f034c9a0c5836776069aed36f670ecbbb053414f1e1abb8d269b2ce5e48bd45e5cfd768aa07968a3dc7587bd078c625feac0c52804e41040666b8c5e6153c863b1364a5551a013bd6039d33245072b97fc66551522295d420529896ab74387cabdcf9f3d725f8080808080808080",
|
|
16
|
+
"0xf90211a0156d28ae6d5df3abc7463d2cec2ac7fb426e48340f7f88ae36a81ca5f9dee8f6a09beca8566f0cba30be3f059b6aeae896fd3eab724eb84c9a10908c6009601945a07313d28dc0816c86e30466c06ab5474f24af70211db48fa9a734015534bd74d8a088f7968cbd63613ef3b06122a44ebcc7365dd75589f18cc58fce72064e0a0b1ea02b68f6d1691bce365cb8830fcf7543b95d42efe211e953b24cf61db79cb7e960a0325f1a33b83b8d23d38db039878112ee1d5eab679dbce8a41ebce109978c7e33a0425202aa631cc52afc7cccb657d001584be56cd3750ef4d0e131396bb2fd8a9aa0c1e1bcba129c311b46690757edd4c01a78fede9ed22c8ba1ac5fa07798d92f50a036a0cf8638d4d02175c4fc6871f58280d33c04eb543477a8ab214e270b25d0c0a0c60e6d24a1fe65c208f72e2a2449e50d2c02e001d1982c88d20a01ab5dcf8532a05ad4837ed4e5635fb687c5ae2129dea7c861ddffbbee442f5ad9faeb49ea5a07a01c74851d4ab86eec6c7bef0da2c9346ce8b52435a54f8570ade2d8c3c6e72861a0ff11b81c0f0a9fc418d4b9ec7b038c325a0e4d136ea0ffd2ddeba867ce4b377fa0b198d867690556a5dccc61c0e550be17b56ce3e6c5c1cbb20cc08892da37dec3a04bd945772c230c04f49eced9fe8f7d56d1f2c7f74143d35a81ce366c5fec91f2a0d01d267cecd0009859471b913c6d58150bde9a1f9c23e820fb0e723c70ddd77f80",
|
|
17
|
+
"0xf9014320b9013f03f9013b01832571d584959b8f808501c0d2ae8082520894ff000000000000000000000000000000000084538080c0843b9aca00f8c6a0018efc046e94610e2530344caf1574e507a3182e1a975fb25b032ec1434a3f5ca001c01a93e0e3cd2212776aa2d4cc4e0c07c85cb75b968525f4e5859bae6773c4a00118b59a40847e830edd78f12799a36b697087938f5be61d6aca024f98c9b79ba00120c9a9f71037bbe073b4979641a40642a8d6e9babb851bd7e513981f1316d2a0013b850872322a5032994968f043cac34ddf72cb04e387d6b86ac268990b5a17a001b2946a71b7c1e08dff34496e274da1e5ef2dbedd62ed6bab6b07c12d08302701a0f48e45e81f193edea8a7f2e319169201ea084490a282ebfa944a53155125ba90a037f9784866387921294f047d9e00eae3acf249add9880889f797784c496ea9b1"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"blobs": [
|
|
21
|
+
{
|
|
22
|
+
"versionedHash": "0x018efc046e94610e2530344caf1574e507a3182e1a975fb25b032ec1434a3f5c",
|
|
23
|
+
"kzgCommitment": "0x803d2d67bd32b2926c8c1f86146f88c2eced163e985d6109c5f399b636f3a81574f46e235ec0bf8138131fdf1ef0ea48",
|
|
24
|
+
"index": 0,
|
|
25
|
+
"file": "0x018efc046e94610e2530344caf1574e507a3182e1a975fb25b032ec1434a3f5c.bin"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"versionedHash": "0x01c01a93e0e3cd2212776aa2d4cc4e0c07c85cb75b968525f4e5859bae6773c4",
|
|
29
|
+
"kzgCommitment": "0x98995a21fb0e2f4e6be022dc43b93a1112d374ac646a8e9589a37708416803db825d5c14de8f26ccb0e1c5681b8321fa",
|
|
30
|
+
"index": 1,
|
|
31
|
+
"file": "0x01c01a93e0e3cd2212776aa2d4cc4e0c07c85cb75b968525f4e5859bae6773c4.bin"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"versionedHash": "0x0118b59a40847e830edd78f12799a36b697087938f5be61d6aca024f98c9b79b",
|
|
35
|
+
"kzgCommitment": "0x80f0d5947c18906d06fc484165fb9d03b3e5dce7ac42f6cf7ceaae26eb8618d89950425af9fef93e3742c016b8fd801e",
|
|
36
|
+
"index": 2,
|
|
37
|
+
"file": "0x0118b59a40847e830edd78f12799a36b697087938f5be61d6aca024f98c9b79b.bin"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"versionedHash": "0x0120c9a9f71037bbe073b4979641a40642a8d6e9babb851bd7e513981f1316d2",
|
|
41
|
+
"kzgCommitment": "0x86727febe394e5f86626a81ce56daa98aa4a1c1a30ce3c3b8fe4dc66755f78ede7b12a073337ef39defaaafd6d6c013d",
|
|
42
|
+
"index": 3,
|
|
43
|
+
"file": "0x0120c9a9f71037bbe073b4979641a40642a8d6e9babb851bd7e513981f1316d2.bin"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"versionedHash": "0x013b850872322a5032994968f043cac34ddf72cb04e387d6b86ac268990b5a17",
|
|
47
|
+
"kzgCommitment": "0x933c609081278e6656f1a772b48597ce5e034e316572182cee0e7814fda66f11e5bdf5988ea6483ab16b8280afda9574",
|
|
48
|
+
"index": 4,
|
|
49
|
+
"file": "0x013b850872322a5032994968f043cac34ddf72cb04e387d6b86ac268990b5a17.bin"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"versionedHash": "0x01b2946a71b7c1e08dff34496e274da1e5ef2dbedd62ed6bab6b07c12d083027",
|
|
53
|
+
"kzgCommitment": "0x8d89e4a886782ebac5e2a188268a8bc26485abc259b281dac91a889aaa13c1e3ef8e65577029bc217eabb7d7da774f8a",
|
|
54
|
+
"index": 5,
|
|
55
|
+
"file": "0x01b2946a71b7c1e08dff34496e274da1e5ef2dbedd62ed6bab6b07c12d083027.bin"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"channel": {
|
|
59
|
+
"id": "0x42b5f4f4249919699b40a61bc497f4b5",
|
|
60
|
+
"frames": 7,
|
|
61
|
+
"compression": "brotli",
|
|
62
|
+
"firstBaseBlock": 51979915,
|
|
63
|
+
"lastBaseBlock": 51979939
|
|
64
|
+
},
|
|
65
|
+
"located": {
|
|
66
|
+
"baseTxIndex": 38,
|
|
67
|
+
"txHash": "0x72cc33632237a96db749836905e92e45bd5cc4167403bc7970a69f250b3e9450"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bitgraph-settlement/1, the pointer layer, on REAL data. Base block
|
|
3
|
+
* 51,979,918 (the ceiling transaction 0x72cc…9450, 2026-09-30 06:19:43 UTC)
|
|
4
|
+
* was batched to Ethereum in block 26,088,463 (06:20:35 UTC, 52 s later) by
|
|
5
|
+
* the batcher transactions 0xcb57…a63a (index 18, 6 blobs) and 0x6165…0190
|
|
6
|
+
* (index 19, 1 blob). The fixtures were captured from the chain by the
|
|
7
|
+
* settlement prototype on 2026-09-30. Nothing here touches a network.
|
|
8
|
+
*
|
|
9
|
+
* cd packages/verify && npx tsc -p . && node --test dist/__tests__/settlement.test.js
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { test } from "node:test";
|
|
13
|
+
import * as assert from "node:assert/strict";
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import {
|
|
16
|
+
BASE_MAINNET_SETTLEMENT_PINS, SETTLEMENT_VERSION, verifySettlementPointer, decodeEip4844, versionedHashOf, checkSettlementOnline,
|
|
17
|
+
type SettlementPointer, type SettlementPins,
|
|
18
|
+
} from "../settlement.js";
|
|
19
|
+
import { bytesToHex, hexToBytes, keccak256, decodeHeader, rlpEncode, rlpDecode } from "../ceiling-evm.js";
|
|
20
|
+
|
|
21
|
+
const fix = (name: string): string => readFileSync(new URL(`../../src/__tests__/fixtures/settlement/${name}`, import.meta.url), "utf8");
|
|
22
|
+
const pointer = JSON.parse(fix("pointer-51979918.json")) as SettlementPointer;
|
|
23
|
+
const pointerTx1 = JSON.parse(fix("pointer-51979918-tx1.json")) as SettlementPointer;
|
|
24
|
+
const clone = <T>(x: T): T => JSON.parse(JSON.stringify(x)) as T;
|
|
25
|
+
|
|
26
|
+
const PINS = BASE_MAINNET_SETTLEMENT_PINS;
|
|
27
|
+
const BATCHER = "0x5050f69a9786f081509234f1a7f4684b5e5b76c9";
|
|
28
|
+
const INBOX = "0xff00000000000000000000000000000000008453";
|
|
29
|
+
const L1 = { number: 26088463, hash: "0x8608654cd9d6d66c2ce8a80108db7e5202a6d9ad0072f8c81353cc988d3a93f2", timestamp: 1790749235 };
|
|
30
|
+
const TX0 = "0xcb575f2482a33ce5678997adcb082d4b68f7927c932a07a7a89090e61c6ea63a";
|
|
31
|
+
const TX1 = "0x6165d90f2133ad9154d99c46fdc734af9ab5e84ce63710b5997363e222db0190";
|
|
32
|
+
|
|
33
|
+
test("the real pointer verifies: the ceiling transaction's batch existed by Ethereum block 26,088,463 at 06:20:35 UTC", () => {
|
|
34
|
+
const r = verifySettlementPointer(pointer, PINS);
|
|
35
|
+
assert.equal(r.ok, true, r.reason);
|
|
36
|
+
assert.deepEqual(r.existedBy, { blockNumber: L1.number, blockHash: L1.hash, blockTimestamp: L1.timestamp });
|
|
37
|
+
assert.equal(new Date(L1.timestamp * 1000).toISOString(), "2026-09-30T06:20:35.000Z");
|
|
38
|
+
assert.equal(r.headerCheckedAgainstChain, false);
|
|
39
|
+
assert.deepEqual(r.checks.map((c) => c.name), ["header", "inclusion", "blobs"]);
|
|
40
|
+
assert.ok(r.checks.every((c) => c.ok));
|
|
41
|
+
assert.match(r.checks[2]!.detail!, /^6 blob commitments/);
|
|
42
|
+
assert.equal(pointer.baseBlockNumber, 51979918);
|
|
43
|
+
assert.equal(pointer.l1.txHash, TX0);
|
|
44
|
+
assert.equal(pointer.l1.txIndex, 18);
|
|
45
|
+
assert.equal(pointer.l1.txInclusionProof.length, 3);
|
|
46
|
+
// The pointer describes the find for readers of the blob layer.
|
|
47
|
+
assert.deepEqual(pointer.channel, { id: "0x42b5f4f4249919699b40a61bc497f4b5", frames: 7, compression: "brotli", firstBaseBlock: 51979915, lastBaseBlock: 51979939 });
|
|
48
|
+
assert.deepEqual(pointer.located, { baseTxIndex: 38, txHash: "0x72cc33632237a96db749836905e92e45bd5cc4167403bc7970a69f250b3e9450" });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("the second batcher transaction (one blob, the channel's last frame) verifies as a pointer too", () => {
|
|
52
|
+
const r = verifySettlementPointer(pointerTx1, PINS);
|
|
53
|
+
assert.equal(r.ok, true, r.reason);
|
|
54
|
+
assert.equal(pointerTx1.l1.txHash, TX1);
|
|
55
|
+
assert.equal(pointerTx1.l1.txIndex, 19);
|
|
56
|
+
assert.equal(pointerTx1.blobs.length, 1);
|
|
57
|
+
assert.equal(r.existedBy!.blockNumber, L1.number);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("decodeEip4844 recovers the batcher 0x5050f69a…76c9 from the real raw transaction", () => {
|
|
61
|
+
const tx = decodeEip4844(hexToBytes(pointer.l1.rawTx));
|
|
62
|
+
assert.equal(tx.from, BATCHER);
|
|
63
|
+
assert.equal(tx.to, INBOX);
|
|
64
|
+
assert.equal(tx.chainId, 1n);
|
|
65
|
+
assert.equal(tx.nonce, 0x2571d5n);
|
|
66
|
+
assert.equal(tx.hash, TX0);
|
|
67
|
+
assert.equal(tx.data.length, 0);
|
|
68
|
+
assert.deepEqual(tx.blobVersionedHashes, pointer.blobs.map((b) => b.versionedHash));
|
|
69
|
+
const tx1 = decodeEip4844(hexToBytes(pointerTx1.l1.rawTx));
|
|
70
|
+
assert.equal(tx1.from, BATCHER);
|
|
71
|
+
assert.equal(tx1.nonce, 0x2571d6n);
|
|
72
|
+
assert.equal(tx1.hash, TX1);
|
|
73
|
+
assert.deepEqual(tx1.blobVersionedHashes, [pointerTx1.blobs[0]!.versionedHash]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("every versioned hash is 0x01 || SHA-256(commitment)[1:]", () => {
|
|
77
|
+
for (const b of [...pointer.blobs, ...pointerTx1.blobs]) {
|
|
78
|
+
assert.equal(versionedHashOf(hexToBytes(b.kzgCommitment)), b.versionedHash);
|
|
79
|
+
assert.equal(hexToBytes(b.kzgCommitment).length, 48);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("the header decodes to the block the pointer names, and hashes to its hash", () => {
|
|
84
|
+
const h = decodeHeader(hexToBytes(pointer.l1.blockHeader));
|
|
85
|
+
assert.equal(h.number, L1.number);
|
|
86
|
+
assert.equal(h.timestamp, L1.timestamp);
|
|
87
|
+
assert.equal(h.hash, L1.hash);
|
|
88
|
+
assert.equal(bytesToHex(keccak256(hexToBytes(pointer.l1.blockHeader))), L1.hash);
|
|
89
|
+
assert.equal(bytesToHex(keccak256(hexToBytes(pointer.l1.rawTx))), TX0);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("decodeEip4844 refuses other transaction types and the blob-carrying wrapper", () => {
|
|
93
|
+
assert.throws(() => decodeEip4844(new Uint8Array([0x02, 0xc0])), /not an EIP-4844/);
|
|
94
|
+
const raw = hexToBytes(pointer.l1.rawTx);
|
|
95
|
+
const wrapper = new Uint8Array([0x03, ...rlpEncode([raw.slice(1), [], [], []])]);
|
|
96
|
+
assert.throws(() => decodeEip4844(wrapper), /14 fields|expected/);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("checkSettlementOnline confirms, refutes, or reports a missing block", async () => {
|
|
100
|
+
assert.equal((await checkSettlementOnline(pointer, async () => L1.hash.toUpperCase())).ok, true);
|
|
101
|
+
const other = await checkSettlementOnline(pointer, async () => "0x" + "ab".repeat(32));
|
|
102
|
+
assert.equal(other.ok, false);
|
|
103
|
+
assert.match(other.detail, /not the record's header/);
|
|
104
|
+
const none = await checkSettlementOnline(pointer, async () => null);
|
|
105
|
+
assert.equal(none.ok, false);
|
|
106
|
+
assert.match(none.detail, /no block/);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// ── tampers: every one is refused, and at the layer that catches it ──
|
|
110
|
+
|
|
111
|
+
const rejects = (name: string, mk: () => { p: SettlementPointer; pins?: SettlementPins }, re: RegExp): void => {
|
|
112
|
+
test(`rejects: ${name}`, () => {
|
|
113
|
+
const { p, pins } = mk();
|
|
114
|
+
const r = verifySettlementPointer(p, pins ?? PINS);
|
|
115
|
+
assert.equal(r.ok, false, `accepted: ${name}`);
|
|
116
|
+
assert.match(r.reason!, re);
|
|
117
|
+
assert.equal(r.existedBy, null);
|
|
118
|
+
assert.equal(r.checks[r.checks.length - 1]!.ok, false);
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
rejects("a header byte flipped", () => {
|
|
123
|
+
const p = clone(pointer);
|
|
124
|
+
const h = hexToBytes(p.l1.blockHeader);
|
|
125
|
+
h[300] = h[300]! ^ 1;
|
|
126
|
+
p.l1.blockHeader = bytesToHex(h);
|
|
127
|
+
return { p };
|
|
128
|
+
}, /^header: .*does not hash/);
|
|
129
|
+
|
|
130
|
+
rejects("the block time moved (record field)", () => {
|
|
131
|
+
const p = clone(pointer);
|
|
132
|
+
p.l1.blockTimestamp -= 60;
|
|
133
|
+
return { p };
|
|
134
|
+
}, /^header: .*timestamp/);
|
|
135
|
+
|
|
136
|
+
rejects("the block number moved (record field)", () => {
|
|
137
|
+
const p = clone(pointer);
|
|
138
|
+
p.l1.blockNumber += 1;
|
|
139
|
+
return { p };
|
|
140
|
+
}, /^header: .*block/);
|
|
141
|
+
|
|
142
|
+
rejects("a rebuilt header with a moved timestamp does not hash to blockHash", () => {
|
|
143
|
+
const p = clone(pointer);
|
|
144
|
+
// Header field 11 is the timestamp; re-encoding it changes the hash, which blockHash still pins.
|
|
145
|
+
const f = rlpDecode(hexToBytes(p.l1.blockHeader)) as Uint8Array[];
|
|
146
|
+
f[11] = hexToBytes((L1.timestamp - 3600).toString(16));
|
|
147
|
+
p.l1.blockHeader = bytesToHex(rlpEncode(f));
|
|
148
|
+
p.l1.blockTimestamp = L1.timestamp - 3600;
|
|
149
|
+
return { p };
|
|
150
|
+
}, /^header: .*does not hash/);
|
|
151
|
+
|
|
152
|
+
rejects("the transaction index of the other batcher transaction", () => {
|
|
153
|
+
const p = clone(pointer);
|
|
154
|
+
p.l1.txIndex = 19;
|
|
155
|
+
return { p };
|
|
156
|
+
}, /^inclusion:/);
|
|
157
|
+
|
|
158
|
+
rejects("a raw transaction byte flipped", () => {
|
|
159
|
+
const p = clone(pointer);
|
|
160
|
+
const t = hexToBytes(p.l1.rawTx);
|
|
161
|
+
t[200] = t[200]! ^ 1;
|
|
162
|
+
p.l1.rawTx = bytesToHex(t);
|
|
163
|
+
return { p };
|
|
164
|
+
}, /^transaction: .*does not hash/);
|
|
165
|
+
|
|
166
|
+
rejects("the other batcher transaction's bytes under this proof", () => {
|
|
167
|
+
const p = clone(pointer);
|
|
168
|
+
p.l1.rawTx = pointerTx1.l1.rawTx;
|
|
169
|
+
p.l1.txHash = pointerTx1.l1.txHash;
|
|
170
|
+
return { p };
|
|
171
|
+
}, /^inclusion:/);
|
|
172
|
+
|
|
173
|
+
rejects("the wrong batcher (pin)", () => ({ p: clone(pointer), pins: { ...PINS, batcher: "0x" + "11".repeat(20) } }), /^batcher:/);
|
|
174
|
+
|
|
175
|
+
rejects("the wrong batch inbox (pin)", () => ({ p: clone(pointer), pins: { ...PINS, batchInbox: "0x" + "22".repeat(20) } }), /^inbox:/);
|
|
176
|
+
|
|
177
|
+
rejects("the wrong chain (pin)", () => ({ p: clone(pointer), pins: { ...PINS, l1ChainId: 11155111 } }), /^chain:/);
|
|
178
|
+
|
|
179
|
+
rejects("a versioned hash the transaction does not list", () => {
|
|
180
|
+
const p = clone(pointer);
|
|
181
|
+
p.blobs[0]!.versionedHash = pointerTx1.blobs[0]!.versionedHash;
|
|
182
|
+
p.blobs[0]!.kzgCommitment = pointerTx1.blobs[0]!.kzgCommitment;
|
|
183
|
+
return { p };
|
|
184
|
+
}, /^blobs: .*not listed/);
|
|
185
|
+
|
|
186
|
+
rejects("a commitment that does not hash to its versioned hash", () => {
|
|
187
|
+
const p = clone(pointer);
|
|
188
|
+
const c = hexToBytes(p.blobs[2]!.kzgCommitment);
|
|
189
|
+
c[10] = c[10]! ^ 1;
|
|
190
|
+
p.blobs[2]!.kzgCommitment = bytesToHex(c);
|
|
191
|
+
return { p };
|
|
192
|
+
}, /^blobs: .*0x01 \|\| SHA-256/);
|
|
193
|
+
|
|
194
|
+
rejects("no blobs named", () => {
|
|
195
|
+
const p = clone(pointer);
|
|
196
|
+
p.blobs = [];
|
|
197
|
+
return { p };
|
|
198
|
+
}, /^blobs: .*no blobs/);
|
|
199
|
+
|
|
200
|
+
rejects("another format", () => {
|
|
201
|
+
const p = clone(pointer) as unknown as { version: string };
|
|
202
|
+
p.version = "bitgraph-settlement/2";
|
|
203
|
+
return { p: p as unknown as SettlementPointer };
|
|
204
|
+
}, /^format:/);
|
|
205
|
+
|
|
206
|
+
rejects("no l1 section", () => {
|
|
207
|
+
const p = clone(pointer) as unknown as Record<string, unknown>;
|
|
208
|
+
delete p["l1"];
|
|
209
|
+
return { p: p as unknown as SettlementPointer };
|
|
210
|
+
}, /^format:/);
|
|
211
|
+
|
|
212
|
+
test("SETTLEMENT_VERSION is the fixtures' version", () => {
|
|
213
|
+
assert.equal(pointer.version, SETTLEMENT_VERSION);
|
|
214
|
+
assert.equal(SETTLEMENT_VERSION, "bitgraph-settlement/1");
|
|
215
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Copyright (c) 2024-2026 Argento Computing Inc. Licensed under the MIT License. See LICENSE.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Assemble a bitgraph-carrier/2 payload from vetted parts. The caller has
|
|
5
|
+
* already verified every part (the anchors over their messages, the headers
|
|
6
|
+
* by hash, the Base sidecar with verifyCeiling); this lays them out, derives
|
|
7
|
+
* the attestation witness from the proof's own document, and declares the
|
|
8
|
+
* pins the file was made under. It computes nothing that a verifier would
|
|
9
|
+
* later trust: the witness is recomputed on read, the pins compared.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { CARRIER_VERSION_2, encodeCarrierBlock, type CarrierPayload, type CarrierFloor, type CarrierCeiling, type CarrierCeilingInTime, type CarrierSettlement, type CarrierPins, type CarrierProof } from "./carrier.js";
|
|
13
|
+
import { attestationWitness } from "./nitro.js";
|
|
14
|
+
import { computeProofHash, computeSignedBodyHash } from "./proof-hash.js";
|
|
15
|
+
import { BITGRAPH_CEILING_WRITER, BASE_MAINNET_CHAIN_ID } from "./carrier-verify.js";
|
|
16
|
+
import type { BitGraphProof } from "./types.js";
|
|
17
|
+
|
|
18
|
+
export interface CarrierV2Parts {
|
|
19
|
+
proof: CarrierProof;
|
|
20
|
+
floor: CarrierFloor;
|
|
21
|
+
ceiling: CarrierCeiling;
|
|
22
|
+
ceilingInTime: CarrierCeilingInTime;
|
|
23
|
+
settlement?: CarrierSettlement;
|
|
24
|
+
/** Overrides for the declared pins; defaults to the proof's measurement, BitGraph's ceiling writer, Ethereum mainnet and Base mainnet. */
|
|
25
|
+
pins?: Partial<CarrierPins>;
|
|
26
|
+
/** Set false to leave the openssl witness out (a ZIP-family file whose block would pass the limit). Default true when the proof carries an aws-nitro attestation. */
|
|
27
|
+
withAttestationWitness?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A ZIP-family file (docx, xlsx, pptx, zip) stops opening once the trailing
|
|
32
|
+
* block passes 65,535 bytes, because its end-of-archive record must sit within
|
|
33
|
+
* the last 64 KiB (measured 2026-09-30: Python and Spotlight fail at 65,536,
|
|
34
|
+
* QuickLook hangs; MP4 and MOV have no limit at all). Builders keep every
|
|
35
|
+
* block under this, dropping the attestation witness first (it is derivable
|
|
36
|
+
* from the proof) and refusing the carrier otherwise.
|
|
37
|
+
*/
|
|
38
|
+
export const CARRIER_BLOCK_ZIP_LIMIT = 60_000;
|
|
39
|
+
|
|
40
|
+
export function assembleCarrierV2Payload(parts: CarrierV2Parts): CarrierPayload {
|
|
41
|
+
const proof = parts.proof as unknown as BitGraphProof;
|
|
42
|
+
const att = proof.environment?.attestation;
|
|
43
|
+
const wantWitness = parts.withAttestationWitness ?? (att?.format === "aws-nitro" && typeof att.reportB64 === "string");
|
|
44
|
+
const pins: CarrierPins = {
|
|
45
|
+
pcr0: proof.environment?.measurement,
|
|
46
|
+
ceilingWriter: BITGRAPH_CEILING_WRITER,
|
|
47
|
+
chains: { ethereum: 1, base: BASE_MAINNET_CHAIN_ID },
|
|
48
|
+
...(parts.pins ?? {}),
|
|
49
|
+
};
|
|
50
|
+
const payload: CarrierPayload = {
|
|
51
|
+
carrier: CARRIER_VERSION_2,
|
|
52
|
+
proof: parts.proof,
|
|
53
|
+
floor: parts.floor,
|
|
54
|
+
ceiling: parts.ceiling,
|
|
55
|
+
ceilingInTime: parts.ceilingInTime,
|
|
56
|
+
...(parts.settlement ? { settlement: parts.settlement } : {}),
|
|
57
|
+
pins,
|
|
58
|
+
};
|
|
59
|
+
if (wantWitness && att && typeof att.reportB64 === "string") {
|
|
60
|
+
const signedBodyHashB64 = computeSignedBodyHash(proof);
|
|
61
|
+
const proofHashB64 = computeProofHash(proof);
|
|
62
|
+
payload.attestation = attestationWitness(att.reportB64, {
|
|
63
|
+
pcr0: proof.environment.measurement,
|
|
64
|
+
signedBodyHashB64,
|
|
65
|
+
...(proofHashB64 === signedBodyHashB64 ? { proofHashB64 } : {}),
|
|
66
|
+
}) as unknown as Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
return payload;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The size the block will have on disk for this payload. */
|
|
72
|
+
export function carrierBlockSize(payload: CarrierPayload): number {
|
|
73
|
+
return encodeCarrierBlock(payload).length;
|
|
74
|
+
}
|