@secondlayer/verify 0.2.0 → 0.4.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 +15 -12
- package/dist/index.d.ts +81 -15
- package/dist/index.js +135 -11
- package/dist/index.js.map +7 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,14 +6,15 @@ Check a Stacks block yourself instead of trusting the API or node that served it
|
|
|
6
6
|
|
|
7
7
|
```
|
|
8
8
|
checkpoint -> Bitcoin headers (proof of work) -> burn block -> signer set (MARF proof)
|
|
9
|
-
-> header signatures (70% of signer weight) ->
|
|
9
|
+
-> header signatures (70% of signer weight) -> transactions (tx merkle root)
|
|
10
|
+
-> state witness (state root) -> state diff
|
|
10
11
|
```
|
|
11
12
|
|
|
12
13
|
Blocks below the checkpoint take a shorter chain. The checkpoint's header commits to every ancestor by hash, so no signatures are needed:
|
|
13
14
|
|
|
14
15
|
```
|
|
15
16
|
checkpoint -> block id at that height (parent links, or one MARF proof) -> header hashes to the id
|
|
16
|
-
-> state witness (state root) -> state diff
|
|
17
|
+
-> transactions (tx merkle root) -> state witness (state root) -> state diff
|
|
17
18
|
```
|
|
18
19
|
|
|
19
20
|
Every byte comes from a source you don't have to trust. A lying source can make a link fail, never pass. Powers `secondlayer verify block` in [`@secondlayer/cli`](https://www.npmjs.com/package/@secondlayer/cli).
|
|
@@ -29,23 +30,22 @@ bun add @secondlayer/verify
|
|
|
29
30
|
```ts
|
|
30
31
|
import { SecondlayerProofSource, verifyBlock } from "@secondlayer/verify";
|
|
31
32
|
|
|
32
|
-
const source = new SecondlayerProofSource(
|
|
33
|
-
baseUrl: "https://api.secondlayer.tools",
|
|
34
|
-
apiKey: process.env.SECONDLAYER_API_KEY!, // any account key; proofs are never billed
|
|
35
|
-
});
|
|
33
|
+
const source = new SecondlayerProofSource(); // hosted API, no key needed
|
|
36
34
|
|
|
37
35
|
const result = await verifyBlock(9_137_005, { source });
|
|
38
36
|
if (!result.ok) throw new Error(result.failures[0]?.message); // first broken link
|
|
39
37
|
console.log(result.blockId, result.stateRoot, result.diff?.writes.length);
|
|
40
38
|
```
|
|
41
39
|
|
|
40
|
+
Limits on the hosted API: 10 requests per second per IP (1 for witnesses). Pass `{ apiKey }` for 20 and 2; `rows: true` needs a key. The package runs in browsers as well as Node.
|
|
41
|
+
|
|
42
42
|
With your own node, blocks and MARF proofs come from its RPC. Witnesses, burn preimages and Bitcoin headers still come from the API, checked the same way:
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
45
|
import { NodeRpcProofSource } from "@secondlayer/verify";
|
|
46
46
|
|
|
47
47
|
const source = {
|
|
48
|
-
...new SecondlayerProofSource(
|
|
48
|
+
...new SecondlayerProofSource(),
|
|
49
49
|
...new NodeRpcProofSource({ nodeUrl: "http://localhost:20443" }),
|
|
50
50
|
};
|
|
51
51
|
```
|
|
@@ -54,10 +54,11 @@ Heights below the checkpoint need no extra options: `verifyBlock(150_000, { sour
|
|
|
54
54
|
|
|
55
55
|
`verifyBlock` never throws for bad source data: it returns `ok: false` with `failures`, the first entry being the first broken link. Use `BlockVerifier` to verify many blocks from one checkpoint and reuse the synced Bitcoin headers and proven signer sets.
|
|
56
56
|
|
|
57
|
-
By default only proofs are read, and proofs are free.
|
|
57
|
+
By default only proofs are read, and proofs are free. That includes the block's state writes (`/v1/proofs/writes/{height}`), which name every written leaf of the diff; `result.writes` holds them and each named `diff.writes` entry carries its proven `value`. A source with no writes for the block (the API answers 404 until its node delivers `state_writes` for that height) leaves the diff proven but unnamed, with a note; it is never a failure. Pass `rows: true` to also check the indexed `vm_events` rows, which bill as Index rows on the Secondlayer API.
|
|
58
58
|
|
|
59
59
|
```ts
|
|
60
|
-
|
|
60
|
+
const keyed = new SecondlayerProofSource({ apiKey: process.env.SECONDLAYER_API_KEY });
|
|
61
|
+
await verifyBlock(9_137_005, { source: keyed, rows: true });
|
|
61
62
|
```
|
|
62
63
|
|
|
63
64
|
## What it proves
|
|
@@ -68,8 +69,9 @@ await verifyBlock(9_137_005, { source, rows: true });
|
|
|
68
69
|
| It was elected by a Bitcoin block | consensus hash preimage, burn header in the synced chain |
|
|
69
70
|
| The Bitcoin chain | every header from the checkpoint: proof of work, retargets, median time |
|
|
70
71
|
| The cycle's signers signed it | signer set proven by MARF against an earlier signed block, then 70% of weight |
|
|
72
|
+
| Its transactions | every transaction parses and the txids hash to the header's tx merkle root (`result.transactions`) |
|
|
71
73
|
| Its state | the witness recomputes the header's state root |
|
|
72
|
-
| Every key it wrote |
|
|
74
|
+
| Every key it wrote | a source with `state_writes` for the block: each written leaf is named, nothing hidden |
|
|
73
75
|
| Indexed rows | `rows: true`: each `vm_events` row matches a leaf the block wrote |
|
|
74
76
|
| Below the checkpoint: it is the checkpoint chain's block at that height | parent links or a MARF proof from the checkpoint's state root, then the header (Nakamoto or 2.x) hashes to that id |
|
|
75
77
|
|
|
@@ -79,8 +81,9 @@ await verifyBlock(9_137_005, { source, rows: true });
|
|
|
79
81
|
- **Bitcoin heights.** At or above the checkpoint, a block's burn block must be at or above the checkpoint's Bitcoin block. Below the checkpoint the burn block is checked only when it is (with the baked checkpoint it never is); the hash chain pins those blocks instead. Headers are checked for valid work, not compared against a competing chain, and reorgs past the synced tip are not followed.
|
|
80
82
|
- **MARF proofs of `__MARF_*` keys.** A node's `/v2/clarity/marf` answers only keys with a stored value string, and these have none. The API's `/v1/proofs/marf` falls back to its proof sidecar for them; with `NodeRpcProofSource` alone, blocks more than 16 below a trusted block fail `ancestry` as `unavailable`.
|
|
81
83
|
- **Epoch 2.x consensus hashes.** A 2.x header commits to its parent's block hash, not its id. The id always comes from a trusted descendant (its header, or a MARF proof), and the source's consensus hash must hash with the header to it. State proofs for 2.x heights are against the anchored block's root, which covers the microblocks it confirms.
|
|
82
|
-
- **Names need `
|
|
83
|
-
- **
|
|
84
|
+
- **Names need `state_writes`.** Without them every write is still proven, but unnamed; `notes` says so.
|
|
85
|
+
- **Transactions need the block body.** Epoch 2.x blocks, and a source that serves the header only, skip the `txs` link with a note. The root binds each transaction's bytes (sender, type, call target, arguments), not which transaction made which write, nor whether it succeeded.
|
|
86
|
+
- **Not covered:** print events and transaction results (Stacks headers don't commit to them).
|
|
84
87
|
|
|
85
88
|
## Docs
|
|
86
89
|
|
package/dist/index.d.ts
CHANGED
|
@@ -358,7 +358,10 @@ interface ProofSource {
|
|
|
358
358
|
getBurnPreimage(consensusHash: string): Promise<BurnPreimage>;
|
|
359
359
|
/** Raw 80-byte Bitcoin headers (hex or bytes) from height `from`. */
|
|
360
360
|
getBitcoinHeaders(from: number, count: number): Promise<(string | Bytes)[]>;
|
|
361
|
-
/**
|
|
361
|
+
/**
|
|
362
|
+
* Every MARF write of the block, in ordinal order; null (or empty) when
|
|
363
|
+
* the source has none for it. Names the block's diff.
|
|
364
|
+
*/
|
|
362
365
|
getStateWrites?(height: number): Promise<StateWrite[] | null>;
|
|
363
366
|
/** Indexed vm_events write rows of the block, checked against its proven diff. */
|
|
364
367
|
getVmEvents?(height: number): Promise<VmEventRow[]>;
|
|
@@ -370,17 +373,23 @@ declare class SourceError extends Error {
|
|
|
370
373
|
constructor(url: string, status: number | null, detail: string);
|
|
371
374
|
}
|
|
372
375
|
type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
376
|
+
/** The hosted API. */
|
|
377
|
+
declare const DEFAULT_API_URL = "https://api.secondlayer.tools";
|
|
373
378
|
interface SecondlayerSourceOptions {
|
|
374
|
-
/** API origin
|
|
375
|
-
baseUrl
|
|
376
|
-
/**
|
|
377
|
-
|
|
379
|
+
/** API origin. Defaults to {@link DEFAULT_API_URL}. */
|
|
380
|
+
baseUrl?: string;
|
|
381
|
+
/**
|
|
382
|
+
* Optional. Proofs are keyless; a key raises the rate limit. Required for
|
|
383
|
+
* `rows: true` (metered Index reads). Sent as `Authorization: Bearer`.
|
|
384
|
+
*/
|
|
385
|
+
apiKey?: string;
|
|
378
386
|
fetch?: Fetch;
|
|
379
387
|
}
|
|
380
388
|
/**
|
|
381
|
-
* Every proof input from the Secondlayer API: `/v1/proofs/*`
|
|
382
|
-
* 2.x headers, MARF proofs, witnesses, burn
|
|
383
|
-
*
|
|
389
|
+
* Every proof input from the Secondlayer API: `/v1/proofs/*` (free, rate
|
|
390
|
+
* limited) for blocks, epoch 2.x headers, MARF proofs, witnesses, burn
|
|
391
|
+
* preimages, Bitcoin headers and each block's state writes; the Index API
|
|
392
|
+
* (metered rows) for vm_events, read only when verifyBlock gets `rows: true`.
|
|
384
393
|
* Methods are own properties, so a partial source spreads over it:
|
|
385
394
|
* `{ ...new SecondlayerProofSource(o), ...new NodeRpcProofSource(n) }`.
|
|
386
395
|
*/
|
|
@@ -393,7 +402,7 @@ declare class SecondlayerProofSource implements ProofSource {
|
|
|
393
402
|
getBitcoinHeaders: (from: number, count: number) => Promise<string[]>;
|
|
394
403
|
getStateWrites: (height: number) => Promise<StateWrite[] | null>;
|
|
395
404
|
getVmEvents: (height: number) => Promise<VmEventRow[]>;
|
|
396
|
-
constructor(opts
|
|
405
|
+
constructor(opts?: SecondlayerSourceOptions);
|
|
397
406
|
}
|
|
398
407
|
interface NodeRpcSourceOptions {
|
|
399
408
|
/** Stacks node RPC origin, e.g. `http://localhost:20443`. */
|
|
@@ -420,6 +429,8 @@ interface DiffWrite {
|
|
|
420
429
|
valueHash: string;
|
|
421
430
|
/** Transaction of the last write; null for block-level writes. */
|
|
422
431
|
txIndex?: number | null;
|
|
432
|
+
/** The stored value string (hex of a Clarity value) the leaf holds; named writes only. */
|
|
433
|
+
value?: string;
|
|
423
434
|
/** False when the source had no state_writes: the leaf may also be a carried copy. */
|
|
424
435
|
named: boolean;
|
|
425
436
|
}
|
|
@@ -486,8 +497,33 @@ interface BlockStateResult {
|
|
|
486
497
|
* `parentLeaves`, and the remaining writes come back unnamed.
|
|
487
498
|
*/
|
|
488
499
|
declare function verifyBlockState(input: BlockStateInput): Promise<BlockStateResult>;
|
|
489
|
-
|
|
490
|
-
|
|
500
|
+
interface BlockTransaction {
|
|
501
|
+
/** sha512/256 of the transaction bytes, hex. */
|
|
502
|
+
txid: string;
|
|
503
|
+
/** The consensus-serialized transaction. */
|
|
504
|
+
raw: Bytes;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* tx_merkle_root over txids: leaf = H(0x00 ‖ txid), node = H(0x01 ‖ l ‖ r),
|
|
508
|
+
* an odd level duplicates its last node, and a lone leaf is still paired with
|
|
509
|
+
* itself (one-tx blocks hash H(0x01 ‖ leaf ‖ leaf)).
|
|
510
|
+
*/
|
|
511
|
+
declare function txMerkleRoot2(txids: Bytes[]): Bytes;
|
|
512
|
+
declare class TransactionsError extends Error {
|
|
513
|
+
readonly code: "malformed" | "tx-root-mismatch";
|
|
514
|
+
constructor(code: "malformed" | "tx-root-mismatch", message: string);
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* The block's transactions, each hashed to its txid, checked against the
|
|
518
|
+
* header's tx_merkle_root. The body after `header.byteLength` is a u32 count
|
|
519
|
+
* then the transactions back to back. Null when the bytes are the header
|
|
520
|
+
* alone (a source that serves headers only): nothing to check. Throws
|
|
521
|
+
* {@link TransactionsError} on a malformed body, trailing bytes or a root
|
|
522
|
+
* mismatch.
|
|
523
|
+
*/
|
|
524
|
+
declare function blockTransactions(raw: Bytes, header: NakamotoHeader): BlockTransaction[] | null;
|
|
525
|
+
type VerifyStep = "ancestry" | "block" | "bitcoin" | "burn" | "signer-set" | "signatures" | "txs" | "witness" | "names" | "rows";
|
|
526
|
+
type VerifyFailureCode = StateFailureCode | "unavailable" | "id-mismatch" | "tx-root-mismatch" | "height-mismatch" | "invalid-header" | "preimage-mismatch" | "burn-not-in-chain" | "before-checkpoint" | "not-ancestor" | "ancestry-proof-invalid" | "anchor-not-found" | "anchor-outside-window" | "anchor-unsigned" | "set-proof-invalid" | "below-threshold" | "unknown-signer" | "duplicate-signer" | "bad-signature";
|
|
491
527
|
interface VerifyFailure {
|
|
492
528
|
step: VerifyStep;
|
|
493
529
|
code: VerifyFailureCode;
|
|
@@ -521,6 +557,12 @@ interface BlockVerification {
|
|
|
521
557
|
ok: boolean;
|
|
522
558
|
height?: number;
|
|
523
559
|
blockId?: string;
|
|
560
|
+
/** Nakamoto block hash (the header's signer sighash), hex. Absent for epoch 2.x. */
|
|
561
|
+
blockHash?: string;
|
|
562
|
+
/** The header's consensus hash, hex. */
|
|
563
|
+
consensusHash?: string;
|
|
564
|
+
/** Nakamoto header timestamp, Unix seconds. Absent for epoch 2.x. */
|
|
565
|
+
timestamp?: number;
|
|
524
566
|
/** The header's state_index_root, hex: what the witness must hash to. */
|
|
525
567
|
stateRoot?: string;
|
|
526
568
|
/** Set for blocks below the checkpoint, which need no signatures. */
|
|
@@ -532,7 +574,14 @@ interface BlockVerification {
|
|
|
532
574
|
signerWeight?: bigint;
|
|
533
575
|
totalWeight?: bigint;
|
|
534
576
|
threshold?: bigint;
|
|
577
|
+
/**
|
|
578
|
+
* The block's transactions, checked against the header's tx_merkle_root.
|
|
579
|
+
* Absent for epoch 2.x blocks and when the source served the header only.
|
|
580
|
+
*/
|
|
581
|
+
transactions?: BlockTransaction[];
|
|
535
582
|
diff?: ProvenDiff;
|
|
583
|
+
/** Every state_writes row the names step checked, in ordinal order. */
|
|
584
|
+
writes?: StateWrite[];
|
|
536
585
|
/** vm_events rows proven against the diff. */
|
|
537
586
|
rowsChecked?: number;
|
|
538
587
|
notes: string[];
|
|
@@ -544,9 +593,10 @@ interface VerifyOptions {
|
|
|
544
593
|
/** Defaults to MAINNET_CHECKPOINT. */
|
|
545
594
|
checkpoint?: VerifyCheckpoint;
|
|
546
595
|
/**
|
|
547
|
-
* Also
|
|
548
|
-
* source's `
|
|
549
|
-
*
|
|
596
|
+
* Also prove the block's indexed vm_events rows against its diff: reads
|
|
597
|
+
* the source's `getVmEvents`, which bill as Index rows on the Secondlayer
|
|
598
|
+
* API. Off by default. Naming the diff's writes (`getStateWrites`, free on
|
|
599
|
+
* `/v1/proofs`) is always on when the source has them.
|
|
550
600
|
*/
|
|
551
601
|
rows?: boolean;
|
|
552
602
|
}
|
|
@@ -570,6 +620,9 @@ declare class BlockVerifier {
|
|
|
570
620
|
private readonly burns;
|
|
571
621
|
/** Unverified source answers by consensus hash. */
|
|
572
622
|
private readonly preimages;
|
|
623
|
+
/** Raw bytes of the last few blocks fetched, so the txs step reuses the
|
|
624
|
+
* block an ancestry walk just read. Bounded: blocks can be megabytes. */
|
|
625
|
+
private readonly raws;
|
|
573
626
|
private readonly start;
|
|
574
627
|
constructor(opts: VerifyOptions);
|
|
575
628
|
/** Verify one block by id (hex) or height. Never throws for bad source data. */
|
|
@@ -584,6 +637,13 @@ declare class BlockVerifier {
|
|
|
584
637
|
* by hash from a trusted descendant.
|
|
585
638
|
*/
|
|
586
639
|
private runBelow;
|
|
640
|
+
private rememberRaw;
|
|
641
|
+
/**
|
|
642
|
+
* The block's transactions against the authenticated header's
|
|
643
|
+
* tx_merkle_root: binds every txid, sender, type and call target to the
|
|
644
|
+
* signed (or hash-linked) header.
|
|
645
|
+
*/
|
|
646
|
+
private checkTransactions;
|
|
587
647
|
/**
|
|
588
648
|
* The checkpoint chain's block id at `height`, from the nearest trusted
|
|
589
649
|
* block above it: parent links when within MAX_WALK, else one MARF proof.
|
|
@@ -611,6 +671,12 @@ declare class BlockVerifier {
|
|
|
611
671
|
private bindBurnBelow;
|
|
612
672
|
/** Witness against the authenticated header's root, then the named diff and rows. */
|
|
613
673
|
private verifyState;
|
|
674
|
+
/**
|
|
675
|
+
* The block's state writes, to name its diff. Optional evidence: a source
|
|
676
|
+
* with none for the block (404, empty) or that fails leaves the diff
|
|
677
|
+
* proven but unnamed, with a note, never a failure.
|
|
678
|
+
*/
|
|
679
|
+
private stateWrites;
|
|
614
680
|
/** Header by id, from the cache or the source; it must hash to `id`. */
|
|
615
681
|
private header;
|
|
616
682
|
/**
|
|
@@ -661,4 +727,4 @@ declare class BlockVerifier {
|
|
|
661
727
|
}
|
|
662
728
|
/** One-shot: verify a block from a checkpoint (MAINNET_CHECKPOINT by default). */
|
|
663
729
|
declare const verifyBlock: (ref: string | number, opts: VerifyOptions) => Promise<BlockVerification>;
|
|
664
|
-
export { Ancestry, BlockDiff, BlockDiffInput, BlockStateInput, BlockStateResult, BlockVerification, BlockVerifier, BurnPreimage, Bytes, Checkpoint, ClassifiedLeaf, DiffLeaf, DiffWrite, Epoch2Header, Epoch2HeaderResponse, HeaderChain, HeaderRule, HeaderValidationError, MAINNET_CHECKPOINT, MAINNET_FIRST_BURN_HEIGHT, MAINNET_PREPARE_LENGTH, MAINNET_REWARD_CYCLE_LENGTH, MarfProofInput, MarfProofResponse, NakamotoHeader, NodeRpcProofSource, NodeRpcSourceOptions, ProofSource, ProvenDiff, SIGNERS_CONTRACT, SecondlayerProofSource, SecondlayerSourceOptions, SignerCheck, SignerSet, SourceError, StacksHeader, StateFailure, StateFailureCode, StateWitness, StateWrite, VerifyCheckpoint, VerifyFailure, VerifyFailureCode, VerifyOptions, VerifyStep, VmEventRow, WitnessLeaf, blockId2 as blockId, classifyBlockDiff, cycleStart, dataVarKey, decodeSignerSet, ftBalanceKey, hex, isEpoch2Header, mapEntryKey, marfPath, marfProofAncestors, marfValue, parseEpoch2Header, parseNakamotoHeader, parseWitness, rewardCycle, signerSignatureHash, unhex, verifyBlock, verifyBlockState, verifyConsensusPreimage, verifyMarfProof, verifySignerSignatures };
|
|
730
|
+
export { Ancestry, BlockDiff, BlockDiffInput, BlockStateInput, BlockStateResult, BlockTransaction, BlockVerification, BlockVerifier, BurnPreimage, Bytes, Checkpoint, ClassifiedLeaf, DEFAULT_API_URL, DiffLeaf, DiffWrite, Epoch2Header, Epoch2HeaderResponse, HeaderChain, HeaderRule, HeaderValidationError, MAINNET_CHECKPOINT, MAINNET_FIRST_BURN_HEIGHT, MAINNET_PREPARE_LENGTH, MAINNET_REWARD_CYCLE_LENGTH, MarfProofInput, MarfProofResponse, NakamotoHeader, NodeRpcProofSource, NodeRpcSourceOptions, ProofSource, ProvenDiff, SIGNERS_CONTRACT, SecondlayerProofSource, SecondlayerSourceOptions, SignerCheck, SignerSet, SourceError, StacksHeader, StateFailure, StateFailureCode, StateWitness, StateWrite, TransactionsError, VerifyCheckpoint, VerifyFailure, VerifyFailureCode, VerifyOptions, VerifyStep, VmEventRow, WitnessLeaf, blockId2 as blockId, blockTransactions, classifyBlockDiff, cycleStart, dataVarKey, decodeSignerSet, ftBalanceKey, hex, isEpoch2Header, mapEntryKey, marfPath, marfProofAncestors, marfValue, parseEpoch2Header, parseNakamotoHeader, parseWitness, rewardCycle, signerSignatureHash, txMerkleRoot2 as txMerkleRoot, unhex, verifyBlock, verifyBlockState, verifyConsensusPreimage, verifyMarfProof, verifySignerSignatures };
|
package/dist/index.js
CHANGED
|
@@ -993,7 +993,7 @@ async function get(url, opts, attempt = 1) {
|
|
|
993
993
|
}
|
|
994
994
|
if (res.status === 404)
|
|
995
995
|
return null;
|
|
996
|
-
if (res.status === 503 && attempt < MAX_ATTEMPTS) {
|
|
996
|
+
if ((res.status === 503 || res.status === 429) && attempt < MAX_ATTEMPTS) {
|
|
997
997
|
const header = res.headers.get("retry-after");
|
|
998
998
|
const seconds = header === null ? 1 : Number(header);
|
|
999
999
|
const wait = Number.isFinite(seconds) ? Math.min(Math.max(seconds, 0), MAX_RETRY_SECONDS) : 1;
|
|
@@ -1035,6 +1035,7 @@ var toMarf = (url, j) => {
|
|
|
1035
1035
|
throw new SourceError(url, 200, "MARF answer needs data and proof");
|
|
1036
1036
|
return { data: j.data, proof: unhex(proof) };
|
|
1037
1037
|
};
|
|
1038
|
+
var DEFAULT_API_URL = "https://api.secondlayer.tools";
|
|
1038
1039
|
var VM_WRITE_TYPES = [
|
|
1039
1040
|
"var_set",
|
|
1040
1041
|
"map_set",
|
|
@@ -1070,10 +1071,10 @@ class SecondlayerProofSource {
|
|
|
1070
1071
|
getBitcoinHeaders;
|
|
1071
1072
|
getStateWrites;
|
|
1072
1073
|
getVmEvents;
|
|
1073
|
-
constructor(opts) {
|
|
1074
|
-
const base = trimSlash(opts.baseUrl);
|
|
1074
|
+
constructor(opts = {}) {
|
|
1075
|
+
const base = trimSlash(opts.baseUrl ?? DEFAULT_API_URL);
|
|
1075
1076
|
const http = {
|
|
1076
|
-
headers: { authorization: `Bearer ${opts.apiKey}` },
|
|
1077
|
+
headers: opts.apiKey ? { authorization: `Bearer ${opts.apiKey}` } : {},
|
|
1077
1078
|
fetch: opts.fetch
|
|
1078
1079
|
};
|
|
1079
1080
|
this.getBlock = async (ref) => {
|
|
@@ -1104,11 +1105,22 @@ class SecondlayerProofSource {
|
|
|
1104
1105
|
throw new SourceError(url, 200, `headers start at ${j.from}`);
|
|
1105
1106
|
return j.headers;
|
|
1106
1107
|
};
|
|
1107
|
-
this.getStateWrites = (height) =>
|
|
1108
|
+
this.getStateWrites = async (height) => {
|
|
1109
|
+
const url = `${base}/v1/proofs/writes/${height}`;
|
|
1110
|
+
const j = await getJson(url, http);
|
|
1111
|
+
if (j === null)
|
|
1112
|
+
return null;
|
|
1113
|
+
if (!Array.isArray(j.state_writes))
|
|
1114
|
+
throw new SourceError(url, 200, "answer has no state_writes array");
|
|
1115
|
+
return j.state_writes;
|
|
1116
|
+
};
|
|
1108
1117
|
this.getVmEvents = async (height) => {
|
|
1118
|
+
const eventsUrl = (type) => `${base}/v1/index/events?event_type=${type}&from_height=${height}&to_height=${height}&limit=${PAGE}`;
|
|
1119
|
+
if (!opts.apiKey)
|
|
1120
|
+
throw new SourceError(eventsUrl(VM_WRITE_TYPES[0]), 401, "rows: true reads metered Index events and needs an apiKey");
|
|
1109
1121
|
const out = [];
|
|
1110
1122
|
for (const type of VM_WRITE_TYPES) {
|
|
1111
|
-
const url =
|
|
1123
|
+
const url = eventsUrl(type);
|
|
1112
1124
|
out.push(...await pages("events", url, http) ?? []);
|
|
1113
1125
|
}
|
|
1114
1126
|
return out.sort((a, b) => a.event_index - b.event_index);
|
|
@@ -1301,6 +1313,7 @@ async function verifyBlockState(input) {
|
|
|
1301
1313
|
...leafHex(l),
|
|
1302
1314
|
key: l.key,
|
|
1303
1315
|
txIndex: last.get(l.key)?.txIndex ?? null,
|
|
1316
|
+
value: last.get(l.key)?.value,
|
|
1304
1317
|
named: true
|
|
1305
1318
|
})) : d.hidden.map((l) => ({ ...leafHex(l), named: false })),
|
|
1306
1319
|
carried: d.carried.map(leafHex),
|
|
@@ -1329,6 +1342,58 @@ async function verifyBlockState(input) {
|
|
|
1329
1342
|
out.rowsChecked = checkRows(input.rows, leaves, out.failures);
|
|
1330
1343
|
return out;
|
|
1331
1344
|
}
|
|
1345
|
+
// src/txs.ts
|
|
1346
|
+
import { sha512_256 as sha512_2564 } from "@noble/hashes/sha2.js";
|
|
1347
|
+
import { splitTransactions } from "@secondlayer/stacks/transactions";
|
|
1348
|
+
var LEAF_TAG = new Uint8Array([0]);
|
|
1349
|
+
var NODE_TAG = new Uint8Array([1]);
|
|
1350
|
+
function txMerkleRoot(txids) {
|
|
1351
|
+
if (txids.length === 0)
|
|
1352
|
+
throw new Error("no transactions");
|
|
1353
|
+
let level = txids.map((t) => sha512_2564(concat([LEAF_TAG, t])));
|
|
1354
|
+
do {
|
|
1355
|
+
if (level.length % 2 === 1)
|
|
1356
|
+
level.push(level[level.length - 1]);
|
|
1357
|
+
const next = [];
|
|
1358
|
+
for (let i = 0;i < level.length; i += 2) {
|
|
1359
|
+
next.push(sha512_2564(concat([NODE_TAG, level[i], level[i + 1]])));
|
|
1360
|
+
}
|
|
1361
|
+
level = next;
|
|
1362
|
+
} while (level.length > 1);
|
|
1363
|
+
return level[0];
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
class TransactionsError extends Error {
|
|
1367
|
+
code;
|
|
1368
|
+
constructor(code, message) {
|
|
1369
|
+
super(message);
|
|
1370
|
+
this.code = code;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
function blockTransactions(raw, header) {
|
|
1374
|
+
const body = raw.subarray(header.byteLength);
|
|
1375
|
+
if (body.length === 0)
|
|
1376
|
+
return null;
|
|
1377
|
+
if (body.length < 4)
|
|
1378
|
+
throw new TransactionsError("malformed", "block body has no tx count");
|
|
1379
|
+
const count = new DataView(body.buffer, body.byteOffset, body.byteLength).getUint32(0);
|
|
1380
|
+
if (count === 0)
|
|
1381
|
+
throw new TransactionsError("malformed", "block has no transactions");
|
|
1382
|
+
let txs;
|
|
1383
|
+
try {
|
|
1384
|
+
txs = splitTransactions(body.subarray(4), count);
|
|
1385
|
+
} catch (err) {
|
|
1386
|
+
throw new TransactionsError("malformed", `transactions do not parse: ${err.message}`);
|
|
1387
|
+
}
|
|
1388
|
+
const used = txs.reduce((n, t) => n + t.length, 4);
|
|
1389
|
+
if (used !== body.length)
|
|
1390
|
+
throw new TransactionsError("malformed", `${body.length - used} bytes after the block's ${count} transactions`);
|
|
1391
|
+
const ids = txs.map((t) => sha512_2564(t));
|
|
1392
|
+
const root = txMerkleRoot(ids);
|
|
1393
|
+
if (!bytesEqual(root, header.txMerkleRoot))
|
|
1394
|
+
throw new TransactionsError("tx-root-mismatch", `transactions hash to ${hex(root)}, header tx_merkle_root is ${hex(header.txMerkleRoot)}`);
|
|
1395
|
+
return txs.map((t, i) => ({ txid: hex(ids[i]), raw: t }));
|
|
1396
|
+
}
|
|
1332
1397
|
// src/verify-block.ts
|
|
1333
1398
|
import { uintCV } from "@secondlayer/stacks/clarity";
|
|
1334
1399
|
class Broken extends Error {
|
|
@@ -1394,6 +1459,7 @@ class BlockVerifier {
|
|
|
1394
1459
|
below = new Map;
|
|
1395
1460
|
burns = new Map;
|
|
1396
1461
|
preimages = new Map;
|
|
1462
|
+
raws = new Map;
|
|
1397
1463
|
start;
|
|
1398
1464
|
constructor(opts) {
|
|
1399
1465
|
this.source = opts.source;
|
|
@@ -1438,6 +1504,7 @@ class BlockVerifier {
|
|
|
1438
1504
|
} else {
|
|
1439
1505
|
const raw = await fetchFor("block", `block ${ref}`, () => this.source.getBlock(ref));
|
|
1440
1506
|
header = parseHeader2(raw, "block");
|
|
1507
|
+
this.rememberRaw(hex(blockId(header)), raw);
|
|
1441
1508
|
}
|
|
1442
1509
|
const id = hex(blockId(header));
|
|
1443
1510
|
const height = Number(header.chainLength);
|
|
@@ -1453,7 +1520,7 @@ class BlockVerifier {
|
|
|
1453
1520
|
const height = Number(header.chainLength);
|
|
1454
1521
|
out.height = height;
|
|
1455
1522
|
out.blockId = id;
|
|
1456
|
-
|
|
1523
|
+
describeHeader(header, out);
|
|
1457
1524
|
const burn = await this.bindBurn(header, "burn");
|
|
1458
1525
|
const cycle = rewardCycle(burn.burnHeight);
|
|
1459
1526
|
out.burnHeight = burn.burnHeight;
|
|
@@ -1469,6 +1536,7 @@ class BlockVerifier {
|
|
|
1469
1536
|
out.threshold = sig.threshold;
|
|
1470
1537
|
if (!sig.valid)
|
|
1471
1538
|
fail(signatureFailure(sig, "signatures", cycle));
|
|
1539
|
+
await this.checkTransactions(header, id, out);
|
|
1472
1540
|
await this.verifyState(header, id, out);
|
|
1473
1541
|
}
|
|
1474
1542
|
async runBelow(height, claimed, out) {
|
|
@@ -1490,10 +1558,39 @@ class BlockVerifier {
|
|
|
1490
1558
|
message: `block ${id} claims height ${header.chainLength}, proven at ${height}`
|
|
1491
1559
|
});
|
|
1492
1560
|
out.blockId = id;
|
|
1493
|
-
|
|
1561
|
+
describeHeader(header, out);
|
|
1494
1562
|
await this.bindBurnBelow(header, out);
|
|
1563
|
+
await this.checkTransactions(header, id, out);
|
|
1495
1564
|
await this.verifyState(header, id, out);
|
|
1496
1565
|
}
|
|
1566
|
+
rememberRaw(id, raw) {
|
|
1567
|
+
this.raws.delete(id);
|
|
1568
|
+
this.raws.set(id, raw);
|
|
1569
|
+
while (this.raws.size > 4) {
|
|
1570
|
+
const oldest = this.raws.keys().next().value;
|
|
1571
|
+
this.raws.delete(oldest);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
async checkTransactions(header, id, out) {
|
|
1575
|
+
if (isEpoch2Header(header)) {
|
|
1576
|
+
out.notes.push("epoch 2.x: transactions not checked");
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
const raw = this.raws.get(id) ?? await fetchFor("txs", `block ${id}`, () => this.source.getBlock(id));
|
|
1580
|
+
let txs;
|
|
1581
|
+
try {
|
|
1582
|
+
txs = blockTransactions(raw, header);
|
|
1583
|
+
} catch (err) {
|
|
1584
|
+
if (!(err instanceof TransactionsError))
|
|
1585
|
+
throw err;
|
|
1586
|
+
return fail({ step: "txs", code: err.code, message: err.message });
|
|
1587
|
+
}
|
|
1588
|
+
if (txs === null) {
|
|
1589
|
+
out.notes.push(`transactions not checked: the source served block ${id}'s header only`);
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
out.transactions = txs;
|
|
1593
|
+
}
|
|
1497
1594
|
async ancestor(height) {
|
|
1498
1595
|
const known = this.below.get(height);
|
|
1499
1596
|
if (known)
|
|
@@ -1591,8 +1688,10 @@ class BlockVerifier {
|
|
|
1591
1688
|
const src = this.source;
|
|
1592
1689
|
const height = Number(header.chainLength);
|
|
1593
1690
|
const witness = await fetchFor("witness", `witness ${id}`, () => src.getWitness(id));
|
|
1594
|
-
const
|
|
1595
|
-
|
|
1691
|
+
const writes = await this.stateWrites(height, out.notes);
|
|
1692
|
+
if (writes)
|
|
1693
|
+
out.writes = writes;
|
|
1694
|
+
const { getVmEvents } = this.rows ? src : {};
|
|
1596
1695
|
const rows = getVmEvents ? await fetchFor("rows", `vm_events ${height}`, () => getVmEvents.call(src, height)) : undefined;
|
|
1597
1696
|
const parent = isEpoch2Header(header) ? epoch2ParentId(witness, header) : header.parentBlockId;
|
|
1598
1697
|
const parentId = parent && hex(parent);
|
|
@@ -1612,6 +1711,18 @@ class BlockVerifier {
|
|
|
1612
1711
|
out.notes.push(...state.notes);
|
|
1613
1712
|
out.failures.push(...state.failures);
|
|
1614
1713
|
}
|
|
1714
|
+
async stateWrites(height, notes) {
|
|
1715
|
+
const { getStateWrites } = this.source;
|
|
1716
|
+
if (!getStateWrites)
|
|
1717
|
+
return null;
|
|
1718
|
+
try {
|
|
1719
|
+
const writes = await getStateWrites.call(this.source, height);
|
|
1720
|
+
return writes?.length ? writes : null;
|
|
1721
|
+
} catch (err) {
|
|
1722
|
+
notes.push(`state writes for block ${height} unavailable: ${err.message}`);
|
|
1723
|
+
return null;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1615
1726
|
async header(id, step, extra = {}) {
|
|
1616
1727
|
const known = this.headers.get(id);
|
|
1617
1728
|
if (known)
|
|
@@ -1633,6 +1744,7 @@ class BlockVerifier {
|
|
|
1633
1744
|
let raw;
|
|
1634
1745
|
try {
|
|
1635
1746
|
raw = await src.getBlock(id);
|
|
1747
|
+
this.rememberRaw(id, raw);
|
|
1636
1748
|
} catch (err) {
|
|
1637
1749
|
const reason = `block ${id}: ${err.message}`;
|
|
1638
1750
|
const { getEpoch2Header } = src;
|
|
@@ -1852,6 +1964,14 @@ class BlockVerifier {
|
|
|
1852
1964
|
return set;
|
|
1853
1965
|
}
|
|
1854
1966
|
}
|
|
1967
|
+
function describeHeader(header, out) {
|
|
1968
|
+
out.stateRoot = hex(header.stateIndexRoot);
|
|
1969
|
+
out.consensusHash = hex(header.consensusHash);
|
|
1970
|
+
if (!isEpoch2Header(header)) {
|
|
1971
|
+
out.blockHash = hex(signerSignatureHash(header));
|
|
1972
|
+
out.timestamp = Number(header.timestamp);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1855
1975
|
function parseHeader2(raw, step) {
|
|
1856
1976
|
try {
|
|
1857
1977
|
return parseNakamotoHeader(raw);
|
|
@@ -1910,6 +2030,7 @@ function signatureFailure(sig, step, cycle) {
|
|
|
1910
2030
|
var verifyBlock = (ref, opts) => new BlockVerifier(opts).verify(ref);
|
|
1911
2031
|
export {
|
|
1912
2032
|
BlockVerifier,
|
|
2033
|
+
DEFAULT_API_URL,
|
|
1913
2034
|
HeaderChain,
|
|
1914
2035
|
HeaderValidationError,
|
|
1915
2036
|
MAINNET_CHECKPOINT,
|
|
@@ -1920,7 +2041,9 @@ export {
|
|
|
1920
2041
|
SIGNERS_CONTRACT,
|
|
1921
2042
|
SecondlayerProofSource,
|
|
1922
2043
|
SourceError,
|
|
2044
|
+
TransactionsError,
|
|
1923
2045
|
blockId,
|
|
2046
|
+
blockTransactions,
|
|
1924
2047
|
classifyBlockDiff,
|
|
1925
2048
|
cycleStart,
|
|
1926
2049
|
dataVarKey,
|
|
@@ -1937,6 +2060,7 @@ export {
|
|
|
1937
2060
|
parseWitness,
|
|
1938
2061
|
rewardCycle,
|
|
1939
2062
|
signerSignatureHash,
|
|
2063
|
+
txMerkleRoot,
|
|
1940
2064
|
unhex,
|
|
1941
2065
|
verifyBlock,
|
|
1942
2066
|
verifyBlockState,
|
|
@@ -1945,5 +2069,5 @@ export {
|
|
|
1945
2069
|
verifySignerSignatures
|
|
1946
2070
|
};
|
|
1947
2071
|
|
|
1948
|
-
//# debugId=
|
|
2072
|
+
//# debugId=14EE5CF6A37C9A0B64756E2164756E21
|
|
1949
2073
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/bytes.ts", "../src/header.ts", "../src/marf.ts", "../src/witness.ts", "../src/signers.ts", "../src/burn.ts", "../src/keys.ts", "../src/bitcoin/chain.ts", "../src/bitcoin/header.ts", "../src/bitcoin/pow.ts", "../src/checkpoint.ts", "../src/source.ts", "../src/state.ts", "../src/verify-block.ts"],
|
|
3
|
+
"sources": ["../src/bytes.ts", "../src/header.ts", "../src/marf.ts", "../src/witness.ts", "../src/signers.ts", "../src/burn.ts", "../src/keys.ts", "../src/bitcoin/chain.ts", "../src/bitcoin/header.ts", "../src/bitcoin/pow.ts", "../src/checkpoint.ts", "../src/source.ts", "../src/state.ts", "../src/txs.ts", "../src/verify-block.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"// Byte helpers shared by every codec here. Browser-safe: no Buffer.\nimport { sha512_256 } from \"@noble/hashes/sha2.js\";\nimport { bytesToHex, concatBytes, hexToBytes } from \"@noble/hashes/utils.js\";\n\nexport type Bytes = Uint8Array;\n\nexport const hex = (b: Bytes): string => bytesToHex(b);\n\n/** Hex to bytes; tolerates a 0x prefix. */\nexport const unhex = (s: string): Bytes =>\n\thexToBytes(s.startsWith(\"0x\") ? s.slice(2) : s);\n\nexport const concat = (parts: Bytes[]): Bytes => concatBytes(...parts);\n\nexport const bytesEqual = (a: Bytes, b: Bytes): boolean => {\n\tif (a.length !== b.length) return false;\n\tfor (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n\treturn true;\n};\n\n/** sha512/256 over the concatenation of `parts` (stacks-core TrieHasher). */\nexport const hashAll = (parts: Bytes[]): Bytes => {\n\tconst h = sha512_256.create();\n\tfor (const p of parts) h.update(p);\n\treturn h.digest();\n};\n\n/** Big-endian cursor over consensus-serialized bytes. Throws on overrun. */\nexport class Reader {\n\tpos = 0;\n\tconstructor(readonly buf: Bytes) {}\n\n\tbytes(n: number): Bytes {\n\t\tif (n < 0 || this.pos + n > this.buf.length)\n\t\t\tthrow new Error(`unexpected end of input at ${this.pos} reading ${n}`);\n\t\tconst out = this.buf.subarray(this.pos, this.pos + n);\n\t\tthis.pos += n;\n\t\treturn out;\n\t}\n\n\tprivate view(n: number): DataView {\n\t\tconst b = this.bytes(n);\n\t\treturn new DataView(b.buffer, b.byteOffset, n);\n\t}\n\n\tu8 = (): number => this.bytes(1)[0] as number;\n\tu16 = (): number => this.view(2).getUint16(0);\n\tu32 = (): number => this.view(4).getUint32(0);\n\tu64 = (): bigint => this.view(8).getBigUint64(0);\n\ti64 = (): bigint => this.view(8).getBigInt64(0);\n\n\t/** StacksMessageCodec Vec<T>: u32 count prefix, then items. */\n\tvec<T>(item: () => T, max: number): T[] {\n\t\tconst n = this.u32();\n\t\tif (n > max) throw new Error(`vec length ${n} exceeds ${max}`);\n\t\treturn Array.from({ length: n }, item);\n\t}\n\n\tget done(): boolean {\n\t\treturn this.pos === this.buf.length;\n\t}\n}\n",
|
|
6
6
|
"// Stacks block header codecs + identity hashes: Nakamoto (stackslib\n// chainstate/nakamoto/mod.rs NakamotoBlockHeader) and epoch 2.x\n// (chainstate/stacks/block.rs StacksBlockHeader).\nimport { sha512_256 } from \"@noble/hashes/sha2.js\";\nimport { type Bytes, Reader, concat, hashAll } from \"./bytes.ts\";\n\nexport interface NakamotoHeader {\n\t/** Low 7 bits = header version; high bit = shadow block. */\n\tversion: number;\n\tchainLength: bigint;\n\tburnSpent: bigint;\n\tconsensusHash: Bytes;\n\tparentBlockId: Bytes;\n\ttxMerkleRoot: Bytes;\n\tstateIndexRoot: Bytes;\n\ttimestamp: bigint;\n\tminerSignature: Bytes;\n\t/** 65-byte recoverable signatures: recovery id, r, s. */\n\tsignerSignatures: Bytes[];\n\t/** Header bytes minus the signer_signature vec: the signer sighash preimage. */\n\tsignerSighashPreimage: Bytes;\n\t/** Serialized header length; block bytes after this are the transactions. */\n\tbyteLength: number;\n}\n\n/** First header version whose sighash commits to `problematic_txs` (epoch 4.0). */\nconst NAKAMOTO_BLOCK_VERSION_EPOCH_4 = 1;\nconst MAX_SIGNERS = 4000;\nconst MAX_PROBLEMATIC_TXS = 1 << 16;\n\n/**\n * Parse the NakamotoBlockHeader at the start of raw block bytes\n * (`/v3/blocks/<id>`). Handles v0 and v1 (v1 appends `problematic_txs`).\n */\nexport function parseNakamotoHeader(raw: Bytes): NakamotoHeader {\n\tconst r = new Reader(raw);\n\tconst version = r.u8();\n\tconst chainLength = r.u64();\n\tconst burnSpent = r.u64();\n\tconst consensusHash = r.bytes(20);\n\tconst parentBlockId = r.bytes(32);\n\tconst txMerkleRoot = r.bytes(32);\n\tconst stateIndexRoot = r.bytes(32);\n\tconst timestamp = r.u64();\n\tconst minerSignature = r.bytes(65);\n\tconst sigStart = r.pos;\n\tconst signerSignatures = r.vec(() => r.bytes(65), MAX_SIGNERS);\n\tconst sigEnd = r.pos;\n\t// pox_treatment: BitVec<4000> = u16 bit length, then Vec<u8> of exactly ceil(len/8).\n\tconst bits = r.u16();\n\tif (bits === 0 || bits > MAX_SIGNERS)\n\t\tthrow new Error(`bad pox_treatment length ${bits}`);\n\tconst bitBytes = Math.ceil(bits / 8);\n\tif (r.u32() !== bitBytes) throw new Error(\"bad pox_treatment data length\");\n\tr.bytes(bitBytes);\n\tif ((version & 0x7f) >= NAKAMOTO_BLOCK_VERSION_EPOCH_4) {\n\t\t// problematic_txs: Vec<(u32 index, u8 marker)>\n\t\tr.vec(() => r.bytes(5), MAX_PROBLEMATIC_TXS);\n\t}\n\tconst end = r.pos;\n\treturn {\n\t\tversion,\n\t\tchainLength,\n\t\tburnSpent,\n\t\tconsensusHash,\n\t\tparentBlockId,\n\t\ttxMerkleRoot,\n\t\tstateIndexRoot,\n\t\ttimestamp,\n\t\tminerSignature,\n\t\tsignerSignatures,\n\t\tsignerSighashPreimage: concat([\n\t\t\traw.subarray(0, sigStart),\n\t\t\traw.subarray(sigEnd, end),\n\t\t]),\n\t\tbyteLength: end,\n\t};\n}\n\n/**\n * NakamotoBlockHeader::signer_signature_hash: sha512/256 over every header field\n * except the signer signatures. Also the header's block_hash.\n */\nexport const signerSignatureHash = (h: NakamotoHeader): Bytes =>\n\tsha512_256(h.signerSighashPreimage);\n\n/**\n * Epoch 2.x anchored block header. It commits to the parent's block hash, not\n * its index block hash, and carries no consensus hash: the source supplies\n * that, and `blockId` binds it to an id proven elsewhere.\n */\nexport interface Epoch2Header {\n\tversion: number;\n\t/** total_work.burn: burn spent on the fork so far. */\n\tburnSpent: bigint;\n\t/** total_work.work: the Stacks chain length (one per anchored block). */\n\tchainLength: bigint;\n\tvrfProof: Bytes;\n\tparentBlockHash: Bytes;\n\tparentMicroblock: Bytes;\n\tparentMicroblockSequence: number;\n\ttxMerkleRoot: Bytes;\n\t/** Covers the block and the parent microblock stream it confirms. */\n\tstateIndexRoot: Bytes;\n\tmicroblockPubkeyHash: Bytes;\n\t/** sha512/256 of the serialized header. */\n\tblockHash: Bytes;\n\tconsensusHash: Bytes;\n}\n\nexport type StacksHeader = NakamotoHeader | Epoch2Header;\n\n/** StacksBlockHeader is fixed width: no signatures, no variable fields. */\nexport const EPOCH2_HEADER_LENGTH = 247;\n\n/**\n * Parse the epoch 2.x StacksBlockHeader at the start of `raw` (a header from\n * `/v2/headers`, or block bytes from `/v2/blocks/<id>`), with the 20-byte\n * consensus hash of the sortition that elected it.\n */\nexport function parseEpoch2Header(\n\traw: Bytes,\n\tconsensusHash: Bytes,\n): Epoch2Header {\n\tif (consensusHash.length !== 20)\n\t\tthrow new Error(`consensus hash is ${consensusHash.length} bytes, not 20`);\n\tconst r = new Reader(raw);\n\tconst header: Omit<Epoch2Header, \"blockHash\" | \"consensusHash\"> = {\n\t\tversion: r.u8(),\n\t\tburnSpent: r.u64(),\n\t\tchainLength: r.u64(),\n\t\tvrfProof: r.bytes(80),\n\t\tparentBlockHash: r.bytes(32),\n\t\tparentMicroblock: r.bytes(32),\n\t\tparentMicroblockSequence: r.u16(),\n\t\ttxMerkleRoot: r.bytes(32),\n\t\tstateIndexRoot: r.bytes(32),\n\t\tmicroblockPubkeyHash: r.bytes(20),\n\t};\n\treturn {\n\t\t...header,\n\t\tblockHash: sha512_256(raw.subarray(0, EPOCH2_HEADER_LENGTH)),\n\t\tconsensusHash,\n\t};\n}\n\nexport const isEpoch2Header = (h: StacksHeader): h is Epoch2Header =>\n\t\"parentBlockHash\" in h;\n\n/**\n * StacksBlockId (index block hash) = sha512/256(block_hash || consensus_hash).\n * A Nakamoto block hash is its signer signature hash; a 2.x one hashes the\n * whole header.\n */\nexport const blockId = (h: StacksHeader): Bytes =>\n\thashAll([\n\t\tisEpoch2Header(h) ? h.blockHash : signerSignatureHash(h),\n\t\th.consensusHash,\n\t]);\n",
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
"/**\n * Bitcoin block header wire format: 80 bytes, all integers little-endian.\n *\n * version (i32) | prevHash (32) | merkleRoot (32) | time (u32) | bits (u32) | nonce (u32)\n *\n * Hashes are carried in display order (byte-reversed hex, as bitcoind and\n * explorers print them). `headerHash` returns the natural (internal) byte\n * order, which is what proof-of-work compares as a little-endian integer.\n */\n\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { bytesToHex, hexToBytes } from \"@noble/hashes/utils.js\";\n\nexport const HEADER_SIZE = 80;\n\nexport interface BlockHeader {\n\t/** Signed 32-bit version field. */\n\tversion: number;\n\t/** Display-order hex of the previous block hash. */\n\tprevHash: string;\n\t/** Display-order hex of the merkle root. */\n\tmerkleRoot: string;\n\t/** Unix timestamp, seconds. */\n\ttime: number;\n\t/** Compact-encoded target. */\n\tbits: number;\n\tnonce: number;\n}\n\nfunction toBytes(raw: Uint8Array | string): Uint8Array {\n\treturn typeof raw === \"string\" ? hexToBytes(raw) : raw;\n}\n\n/** Reverses byte order: natural <-> display. Returns a copy. */\nexport function reverseBytes(bytes: Uint8Array): Uint8Array {\n\treturn Uint8Array.from(bytes).reverse();\n}\n\nexport function parseHeader(raw: Uint8Array | string): BlockHeader {\n\tconst bytes = toBytes(raw);\n\tif (bytes.length !== HEADER_SIZE) {\n\t\tthrow new RangeError(\n\t\t\t`block header must be ${HEADER_SIZE} bytes, got ${bytes.length}`,\n\t\t);\n\t}\n\tconst view = new DataView(bytes.buffer, bytes.byteOffset, HEADER_SIZE);\n\treturn {\n\t\tversion: view.getInt32(0, true),\n\t\tprevHash: bytesToHex(reverseBytes(bytes.subarray(4, 36))),\n\t\tmerkleRoot: bytesToHex(reverseBytes(bytes.subarray(36, 68))),\n\t\ttime: view.getUint32(68, true),\n\t\tbits: view.getUint32(72, true),\n\t\tnonce: view.getUint32(76, true),\n\t};\n}\n\nexport function serializeHeader(header: BlockHeader): Uint8Array {\n\tconst bytes = new Uint8Array(HEADER_SIZE);\n\tconst view = new DataView(bytes.buffer);\n\tview.setInt32(0, header.version, true);\n\tbytes.set(reverseBytes(hexToBytes(header.prevHash)), 4);\n\tbytes.set(reverseBytes(hexToBytes(header.merkleRoot)), 36);\n\tview.setUint32(68, header.time, true);\n\tview.setUint32(72, header.bits, true);\n\tview.setUint32(76, header.nonce, true);\n\treturn bytes;\n}\n\n/** Double-SHA256 of the raw header, natural (internal) byte order. */\nexport function headerHash(raw: Uint8Array | string): Uint8Array {\n\tconst bytes = toBytes(raw);\n\tif (bytes.length !== HEADER_SIZE) {\n\t\tthrow new RangeError(\n\t\t\t`block header must be ${HEADER_SIZE} bytes, got ${bytes.length}`,\n\t\t);\n\t}\n\treturn sha256(sha256(bytes));\n}\n\n/** Block hash as display-order hex (what bitcoind prints). */\nexport function headerHashHex(raw: Uint8Array | string): string {\n\treturn bytesToHex(reverseBytes(headerHash(raw)));\n}\n",
|
|
14
14
|
"/**\n * Proof-of-work arithmetic, mirroring Bitcoin Core's arith_uint256\n * SetCompact/GetCompact, CheckProofOfWork, GetBlockProof and\n * CalculateNextWorkRequired (mainnet parameters only).\n */\n\n/** Mainnet powLimit, compact form. */\nexport const POW_LIMIT_BITS = 0x1d00ffff;\n/** Mainnet powLimit: 0x00000000ffff0000...0000. */\nexport const POW_LIMIT = 0xffffn << 208n;\n/** Blocks per difficulty period. */\nexport const RETARGET_INTERVAL = 2016;\n/** Two weeks, seconds. */\nexport const TARGET_TIMESPAN = 14 * 24 * 60 * 60;\n\nconst TWO_256 = 1n << 256n;\n\nexport interface DecodedCompact {\n\ttarget: bigint;\n\tnegative: boolean;\n\toverflow: boolean;\n}\n\n/** Core's arith_uint256::SetCompact, including its negative/overflow flags. */\nexport function decodeCompact(bits: number): DecodedCompact {\n\tconst size = bits >>> 24;\n\tlet word = bits & 0x007fffff;\n\tlet target: bigint;\n\tif (size <= 3) {\n\t\tword >>>= 8 * (3 - size);\n\t\ttarget = BigInt(word);\n\t} else {\n\t\ttarget = BigInt(word) << BigInt(8 * (size - 3));\n\t}\n\tconst negative = word !== 0 && (bits & 0x00800000) !== 0;\n\tconst overflow =\n\t\tword !== 0 &&\n\t\t(size > 34 || (word > 0xff && size > 33) || (word > 0xffff && size > 32));\n\treturn { target: target & (TWO_256 - 1n), negative, overflow };\n}\n\n/** Decodes compact bits to a target, throwing on negative/overflow/zero. */\nexport function bitsToTarget(bits: number): bigint {\n\tconst { target, negative, overflow } = decodeCompact(bits);\n\tif (negative || overflow || target === 0n) {\n\t\tthrow new RangeError(\n\t\t\t`bits 0x${bits.toString(16).padStart(8, \"0\")} do not encode a valid target`,\n\t\t);\n\t}\n\treturn target;\n}\n\n/** Core's arith_uint256::GetCompact for a non-negative target. */\nexport function targetToBits(target: bigint): number {\n\tif (target < 0n) throw new RangeError(\"target must be non-negative\");\n\tlet size = target === 0n ? 0 : Math.ceil(target.toString(2).length / 8);\n\tlet compact =\n\t\tsize <= 3\n\t\t\t? Number(target << BigInt(8 * (3 - size)))\n\t\t\t: Number(target >> BigInt(8 * (size - 3)));\n\tif (compact & 0x00800000) {\n\t\tcompact >>>= 8;\n\t\tsize += 1;\n\t}\n\treturn ((size << 24) | compact) >>> 0;\n}\n\n/** Interprets a natural-order hash as the little-endian 256-bit integer PoW compares. */\nexport function hashToBigInt(hash: Uint8Array): bigint {\n\tlet n = 0n;\n\tfor (let i = hash.length - 1; i >= 0; i--) {\n\t\tn = (n << 8n) | BigInt(hash[i] as number);\n\t}\n\treturn n;\n}\n\n/** Core's CheckProofOfWork: valid target ≤ powLimit and hash ≤ target. */\nexport function checkProofOfWork(hash: Uint8Array, bits: number): boolean {\n\tconst { target, negative, overflow } = decodeCompact(bits);\n\tif (negative || overflow || target === 0n || target > POW_LIMIT) {\n\t\treturn false;\n\t}\n\treturn hashToBigInt(hash) <= target;\n}\n\n/** Expected number of hashes for a block at `bits`: 2^256 / (target + 1). */\nexport function headerWork(bits: number): bigint {\n\tconst target = bitsToTarget(bits);\n\t// Core's GetBlockProof: (~target / (target + 1)) + 1, same value without overflow.\n\treturn (TWO_256 - 1n - target) / (target + 1n) + 1n;\n}\n\n/**\n * Core's CalculateNextWorkRequired. `firstTime` is the timestamp of the first\n * block of the closing period and `lastTime` of its last block, so the\n * measured span covers 2015 intervals, not 2016 (the well-known off-by-one\n * that consensus preserves).\n */\nexport function nextRetargetBits(\n\tlastBits: number,\n\tfirstTime: number,\n\tlastTime: number,\n): number {\n\tlet actual = lastTime - firstTime;\n\tif (actual < TARGET_TIMESPAN / 4) actual = TARGET_TIMESPAN / 4;\n\tif (actual > TARGET_TIMESPAN * 4) actual = TARGET_TIMESPAN * 4;\n\tlet target =\n\t\t(bitsToTarget(lastBits) * BigInt(actual)) / BigInt(TARGET_TIMESPAN);\n\tif (target > POW_LIMIT) target = POW_LIMIT;\n\treturn targetToBits(target);\n}\n",
|
|
15
15
|
"// Trusted starting point baked into each release. Everything verifyBlock\n// proves is relative to it: a Stacks block whose state holds one cycle's\n// signer set, and a Bitcoin header to sync proof-of-work from.\n//\n// Bump it once per release so the signer-set walk stays short:\n// 1. Pick a recent reward cycle C and a canonical Stacks block X whose burn\n// block is in C-1's prepare phase or later (its state holds set C).\n// 2. Fetch X's raw block (`/v3/blocks/<id>`, keep the header bytes) and\n// `cycle-signer-set[C]` with its proof at X (`/v2/clarity/marf/<path>?tip=X&proof=1`,\n// key `mapEntryKey(SIGNERS_CONTRACT, \"cycle-signer-set\", uintCV(C))`).\n// 3. Bitcoin: the retarget-period start (a multiple of 2016) at or below C's\n// first burn block, 666050 + 2100 * C. Blocks above X whose burn height\n// is below the Bitcoin checkpoint cannot be verified; blocks below X are\n// verified by hash chain from X instead.\n// 4. Add X's header, its proof ancestors and the set proof to test/fixtures:\n// the checkpoint test re-proves the baked set against X.\nimport type { Checkpoint } from \"./bitcoin/chain.ts\";\n\nexport interface VerifyCheckpoint {\n\tstacks: {\n\t\t/** Raw Nakamoto header (hex) of a trusted block whose state holds `signerSet`. */\n\t\theader: string;\n\t\t/** Reward cycle `signerSet` belongs to. */\n\t\tcycle: number;\n\t\t/** `.signers` `cycle-signer-set[cycle]` as stored: hex of `(some (list ...))`. */\n\t\tsignerSet: string;\n\t};\n\t/** Retarget-boundary Bitcoin header at or below the first burn block of `stacks.cycle`. */\n\tbitcoin: Checkpoint;\n}\n\n/**\n * Mainnet: Stacks block 8,956,304 (`3914ea5f…74bb`) holding the cycle 143\n * signer set (29 signers, weight 4000), and Bitcoin block 967,680 (a\n * retarget-period start inside cycle 143). Later blocks verify forward\n * (burn height 967,680 or later); earlier ones by hash chain from 8,956,304.\n */\nexport const MAINNET_CHECKPOINT: VerifyCheckpoint = {\n\tstacks: {\n\t\theader: [\n\t\t\t\"01000000000088a9900000006629951a50e3616a1c1e0b8c05ba66615c7065053804c56e2a68dc605cf905df5a754c57\",\n\t\t\t\"144e9ddde1191353b05f1a5e6d3c99244aeb006ba4f4db761cb1efecfb92693a8c08fefc766a4cd5ccfcb8f13789a809\",\n\t\t\t\"e7ee0c2e6b7dfb64868cf1e4e6acc50513202acfab84553454b433248c0ef06cebda3c734c000000006aa28bfd013be3\",\n\t\t\t\"826a60039f518d7021a4799f2e083dafaaaac7a2d56fda601d674d596d3046b9bbcd52e79fba491e54d92fdab0ca3ab9\",\n\t\t\t\"9ccf346c6e6726fbd4c8579a02b80000000d0004f2d135dd684fcdf24973ad0e9d4f11ef10890a8159614b1df97d8f31\",\n\t\t\t\"76532d1ce4ebdcbbf45afcd01d5bb298ef9556b232f877f3586d65303642dabc210059012d5f341c979fd10a1ce9b48f\",\n\t\t\t\"4a38f68da5ccbb8749c02e164a99668328890ed706accfbec155202f63ff487a26aba793169341c2ff91a43ffed38f0e\",\n\t\t\t\"941c3dc1012a12bb2148d6cf23dd05e228d29286e3bb87ff717712ecc2c9f0c4297c241ac41f879baeee87a570243a31\",\n\t\t\t\"cf43e775862e71a7f51cb150bbc31f3a2f62a1772d00f8bdd615ab5b58841c7918d69cf98a030f52ca410c9b91a188ba\",\n\t\t\t\"038138563ea35f8453075907fc3cdac7e3eff8fa9f61fcb53a1e14a102309fa297e420826bfe015628863a16f1bdc077\",\n\t\t\t\"90c6eead0cfd7a0aa7222df6d8d41415427b0b4057eb972dc31bd413f1e425ef1bc738cc5c3b8507890bad0940bafdf2\",\n\t\t\t\"220a6ecadb33ed002f9a476eb20c5e532bafa7b559b285932e1dab1159c93038d8cb0da8d55d25294cc8e6b0972efc08\",\n\t\t\t\"fdf825407e3215d8d01531f5cddfe993db10be07b38c18fa006999eb6418eac4696bb42ca149f79832442754ea08b0e1\",\n\t\t\t\"c6237feb522df034a3388c0de90b1a4652218b319f839ff16a132baa90dbbca2876f52b1a5750dc07001cffca3ed6e92\",\n\t\t\t\"2483e6567f183a78a1c09d16846743f08c5cce93e7e06294c4a722283d31195722b6ce97087c6dd00eedecd1db77be10\",\n\t\t\t\"9c298c322c53e83ea43201dd0684e8171ad29f6895ed9892d3932daeb0986f32992d6758db194ae9ba8eb256fdff3b61\",\n\t\t\t\"af0cd448aafe5e4e62e7e75409dfcd3cef3913c792e412849a02550109083fa52598f5fa2907e840050c41db32163838\",\n\t\t\t\"32aa7cb5e23de14ced47961e356b23e442f2a657ea89fed2845a6b380624dc12347e4d591c80e15016ae35fc005ae002\",\n\t\t\t\"f1fc5837c21185b88b06cc8611cfb482c021df5329d878e2b4f221341a47e6fe02182c9250d25fe162f42a0bbe9b8ce2\",\n\t\t\t\"f9a70aa2dcca9e955a61a0fe24016398a0fdf5e2541d3d0838d9f7e24b4093d27660a48cd71bf0728fe5d02e6d374a3e\",\n\t\t\t\"aa67c91aee87635d7458bb1fe89755021fbe8d34e271fba1d765b065e266008a862c839aeec0d6a9940cfe44e0bc1586\",\n\t\t\t\"2bd2ac23b3ab6fc59734a8171b44401b395984f0f906b2d15b4a3a24d2136a8ca925485f197197b3aa1bb2c46d02e000\",\n\t\t\t\"01000000010100000000\",\n\t\t].join(\"\"),\n\t\tcycle: 143,\n\t\tsignerSet: [\n\t\t\t\"0a0b0000001d0c00000002067369676e65720516f5061b1c62f399ecc0db8cbb21f8d481af079a380677656967687401\",\n\t\t\t\"000000000000000000000000000002860c00000002067369676e65720516a3bbf2a4133fbd5bd1880982957b7a760347\",\n\t\t\t\"b2dc0677656967687401000000000000000000000000000000090c00000002067369676e657205164f72f6b5a9f5d863\",\n\t\t\t\"34b2f0fe701db51a7a246f3d0677656967687401000000000000000000000000000000990c00000002067369676e6572\",\n\t\t\t\"051653ec8b4f51c8286dad6f4ff81ca2a3409d2f382d0677656967687401000000000000000000000000000000050c00\",\n\t\t\t\"000002067369676e65720516dba631825ff0f15c7c5946b560070f8f5f5747cb06776569676874010000000000000000\",\n\t\t\t\"00000000000000240c00000002067369676e6572051600d058b39f4495b412ff7eada763eaa6386eb90a067765696768\",\n\t\t\t\"7401000000000000000000000000000002860c00000002067369676e65720516321ac33715d684d5e8d0cf427cd98557\",\n\t\t\t\"6f64c6df06776569676874010000000000000000000000000000000b0c00000002067369676e6572051677a52718ba90\",\n\t\t\t\"fca67984166b2a084edb9b3bd8f10677656967687401000000000000000000000000000000030c00000002067369676e\",\n\t\t\t\"65720516a54a20479b3b65a461a427b9161b78e64db58ba70677656967687401000000000000000000000000000001a9\",\n\t\t\t\"0c00000002067369676e65720516bc1a58c2a058a9e4150db25562e8331ef8a4267c0677656967687401000000000000\",\n\t\t\t\"000000000000000000060c00000002067369676e657205161091d2da4c9ee17a340171c0d23c4304b54ef43f06776569\",\n\t\t\t\"67687401000000000000000000000000000000680c00000002067369676e6572051654d01a0973ed139736a1a43032a6\",\n\t\t\t\"a18d9295ec7206776569676874010000000000000000000000000000008d0c00000002067369676e657205160c49f5b6\",\n\t\t\t\"c62f1163ddbb21f92aba86f17f7be4880677656967687401000000000000000000000000000000680c00000002067369\",\n\t\t\t\"676e65720516ad16c79ac56b58f0797f78c5343853674606268006776569676874010000000000000000000000000000\",\n\t\t\t\"00680c00000002067369676e657205169689e56df00385b6bd81fb6b7769d5b04088acb8067765696768740100000000\",\n\t\t\t\"0000000000000000000000ad0c00000002067369676e65720516a4f7f81412f4413771a48825cfbe2062a774d4e90677\",\n\t\t\t\"656967687401000000000000000000000000000003090c00000002067369676e65720516ed73a7398f1c3eb566f3bd7f\",\n\t\t\t\"4bd43f52adf33d8f0677656967687401000000000000000000000000000000680c00000002067369676e65720516937b\",\n\t\t\t\"3b43e0d94c9ef8f171892bce949709e1d41f0677656967687401000000000000000000000000000000250c0000000206\",\n\t\t\t\"7369676e6572051631542aacfd6e04858181c3067b5eb07399ba89df0677656967687401000000000000000000000000\",\n\t\t\t\"0000005b0c00000002067369676e6572051649f034cd1662a222dbc38a6acd64008ba7e5576606776569676874010000\",\n\t\t\t\"00000000000000000000000000060c00000002067369676e65720516a20f660dea498c169897a39cb89ce0d98856e572\",\n\t\t\t\"0677656967687401000000000000000000000000000000090c00000002067369676e6572051652d58897b3678f3a758f\",\n\t\t\t\"a4b9270744fec0605b210677656967687401000000000000000000000000000000680c00000002067369676e65720516\",\n\t\t\t\"31733264626dc5fef36eb683a5069d89f63b64cc0677656967687401000000000000000000000000000000090c000000\",\n\t\t\t\"02067369676e65720516d80db618c2def577604cd8e40a3940b5b639b1ac067765696768740100000000000000000000\",\n\t\t\t\"00000000000a0c00000002067369676e657205162042a380d946a82866465af8521a273efe6d2a600677656967687401\",\n\t\t\t\"000000000000000000000000000000490c00000002067369676e6572051635e1b36efc22bc607db92f9100cb08e3473d\",\n\t\t\t\"602506776569676874010000000000000000000000000000006b0c00000002067369676e657205164843b97054e43dd1\",\n\t\t\t\"a8571fc1e72949c5bedfb7e906776569676874010000000000000000000000000000004d0c00000002067369676e6572\",\n\t\t\t\"05164883355670025c19ecae644ffa20e75ce1d730ad0677656967687401000000000000000000000000000000090c00\",\n\t\t\t\"000002067369676e65720516089ffd0e0ecd61d9e3c8ee42ef94148acf88aa8806776569676874010000000000000000\",\n\t\t\t\"0000000000000015\",\n\t\t].join(\"\"),\n\t},\n\tbitcoin: {\n\t\theight: 967680,\n\t\theader:\n\t\t\t\"00000030410ccb1cba623e26f2e02f3fcb0e7f06f66998b68cb5010000000000000000003d16ae2558e8ec7b8dd369ee29bb2733fbd39bcc1058c681970a36a7f1a2bdea1135ae6ac51e0217480c3581\",\n\t},\n};\n",
|
|
16
|
-
"// Proof data sources. Everything a source returns is untrusted: verifyBlock\n// checks every byte against the checkpoint, so a lying source can make a\n// check fail but never pass.\nimport { type Bytes, unhex } from \"./bytes.ts\";\n\n/** Sortition preimage behind a consensus hash. */\nexport interface BurnPreimage {\n\tpreimage: Bytes;\n\t/** The source's claimed burn height: a hint for how far to sync Bitcoin headers, never trusted. */\n\tburnHeight: number;\n}\n\n/** Node RPC `/v2/clarity/marf/<path>?proof=1` answer. */\nexport interface MarfProofResponse {\n\t/** Value string as Clarity stored it (hex for Clarity values), 0x prefix tolerated. */\n\tdata: string;\n\t/** Consensus-serialized TrieMerkleProof. */\n\tproof: Bytes;\n}\n\n/** One storage-layer MARF write (`state_writes` row), in block write order. */\nexport interface StateWrite {\n\t/** Null for block-level writes outside any transaction. */\n\ttx_index: number | null;\n\tordinal: number;\n\t/** Full MARF key, e.g. `vm::<contract>::0::<map>::<key hex>`. */\n\tkey: string;\n\t/** Hex of the stored value string's UTF-8 bytes. */\n\tvalue_hex: string;\n}\n\n/** A `vm_events` write row, as the Index API serves it. */\nexport interface VmEventRow {\n\tevent_type: \"var_set\" | \"map_set\" | \"map_insert\" | \"map_delete\";\n\t/** The row's ordinal within the block. */\n\tevent_index: number;\n\ttx_id?: string;\n\ttx_index?: number;\n\tcontract_id: string;\n\tvar_name?: string | null;\n\tmap?: string | null;\n\traw_key?: string | null;\n\traw_value?: string | null;\n}\n\n/** An epoch 2.x header and the consensus hash its index block hash commits to. */\nexport interface Epoch2HeaderResponse {\n\t/** Consensus-serialized StacksBlockHeader. */\n\theader: Bytes;\n\tconsensusHash: Bytes;\n}\n\nexport interface ProofSource {\n\t/** Raw Nakamoto block bytes (header first), by block id or height. */\n\tgetBlock(ref: string | number): Promise<Bytes>;\n\t/**\n\t * Epoch 2.x block header by index block hash: blocks below the checkpoint\n\t * from before Nakamoto. Without it only Nakamoto blocks verify.\n\t */\n\tgetEpoch2Header?(blockId: string): Promise<Epoch2HeaderResponse>;\n\t/**\n\t * MARF inclusion proof for a 32-byte path at `tipId`; null when the key is\n\t * absent. Blocks below the checkpoint also ask for\n\t * `__MARF_BLOCK_HEIGHT_TO_HASH::<height>`, whose value is no stored string:\n\t * only `proof` is read for it.\n\t */\n\tgetMarfProof(\n\t\tpathHex: string,\n\t\ttipId: string,\n\t): Promise<MarfProofResponse | null>;\n\t/** State witness (wire v3) for a block. */\n\tgetWitness(blockId: string): Promise<Bytes>;\n\tgetBurnPreimage(consensusHash: string): Promise<BurnPreimage>;\n\t/** Raw 80-byte Bitcoin headers (hex or bytes) from height `from`. */\n\tgetBitcoinHeaders(from: number, count: number): Promise<(string | Bytes)[]>;\n\t/** Every MARF write of the block; null when the source has none for it. */\n\tgetStateWrites?(height: number): Promise<StateWrite[] | null>;\n\t/** Indexed vm_events write rows of the block, checked against its proven diff. */\n\tgetVmEvents?(height: number): Promise<VmEventRow[]>;\n}\n\nexport class SourceError extends Error {\n\toverride readonly name = \"SourceError\";\n\tconstructor(\n\t\treadonly url: string,\n\t\treadonly status: number | null,\n\t\tdetail: string,\n\t) {\n\t\tsuper(`${url}: ${detail}`);\n\t}\n}\n\ntype Fetch = (url: string, init?: RequestInit) => Promise<Response>;\n\ninterface HttpOptions {\n\theaders?: Record<string, string>;\n\tfetch?: Fetch;\n}\n\nconst MAX_ATTEMPTS = 3;\nconst MAX_RETRY_SECONDS = 10;\n\n/** GET with retries on 503 (honoring retry-after); null on 404. */\nasync function get(\n\turl: string,\n\topts: HttpOptions,\n\tattempt = 1,\n): Promise<Response | null> {\n\tconst doFetch = opts.fetch ?? fetch;\n\tlet res: Response;\n\ttry {\n\t\tres = await doFetch(url, { headers: opts.headers });\n\t} catch (err) {\n\t\tthrow new SourceError(url, null, (err as Error).message);\n\t}\n\tif (res.status === 404) return null;\n\tif (res.status === 503 && attempt < MAX_ATTEMPTS) {\n\t\tconst header = res.headers.get(\"retry-after\");\n\t\tconst seconds = header === null ? 1 : Number(header);\n\t\tconst wait = Number.isFinite(seconds)\n\t\t\t? Math.min(Math.max(seconds, 0), MAX_RETRY_SECONDS)\n\t\t\t: 1;\n\t\tawait new Promise((r) => setTimeout(r, wait * 1000));\n\t\treturn get(url, opts, attempt + 1);\n\t}\n\tif (!res.ok) throw new SourceError(url, res.status, `HTTP ${res.status}`);\n\treturn res;\n}\n\nasync function getJson<T>(url: string, opts: HttpOptions): Promise<T | null> {\n\tconst res = await get(url, opts);\n\treturn res ? ((await res.json()) as T) : null;\n}\n\nasync function getBytes(url: string, opts: HttpOptions): Promise<Bytes | null> {\n\tconst res = await get(url, opts);\n\treturn res ? new Uint8Array(await res.arrayBuffer()) : null;\n}\n\nconst required = <T>(url: string, v: T | null): T => {\n\tif (v === null) throw new SourceError(url, 404, \"not found\");\n\treturn v;\n};\n\nconst trimSlash = (s: string) => s.replace(/\\/+$/, \"\");\n\ntype MarfJson = { data: string; proof?: string; marf_proof?: string };\n\ntype HeadersJson = { header?: unknown; consensus_hash?: unknown }[];\n\n/** The first entry of a node `/v2/headers/1?tip=<id>` answer: the tip itself. */\nconst toEpoch2 = (url: string, j: HeadersJson | null): Epoch2HeaderResponse => {\n\tconst tip = required(url, j)[0];\n\tif (typeof tip?.header !== \"string\" || typeof tip.consensus_hash !== \"string\")\n\t\tthrow new SourceError(url, 200, \"answer needs header and consensus_hash\");\n\treturn {\n\t\theader: unhex(tip.header),\n\t\tconsensusHash: unhex(tip.consensus_hash),\n\t};\n};\n\nconst toMarf = (url: string, j: MarfJson | null): MarfProofResponse | null => {\n\tif (j === null) return null;\n\tconst proof = j.proof ?? j.marf_proof;\n\tif (typeof proof !== \"string\" || typeof j.data !== \"string\")\n\t\tthrow new SourceError(url, 200, \"MARF answer needs data and proof\");\n\treturn { data: j.data, proof: unhex(proof) };\n};\n\nexport interface SecondlayerSourceOptions {\n\t/** API origin, e.g. `https://api.secondlayer.tools`. */\n\tbaseUrl: string;\n\t/** Account key, sent as `Authorization: Bearer`. */\n\tapiKey: string;\n\tfetch?: Fetch;\n}\n\nconst VM_WRITE_TYPES = [\n\t\"var_set\",\n\t\"map_set\",\n\t\"map_insert\",\n\t\"map_delete\",\n] as const;\nconst PAGE = 1000;\n\n/** Follow `next_cursor` until a page comes back empty. Null when the first page 404s. */\nasync function pages<T>(\n\tfield: string,\n\turl: string,\n\thttp: HttpOptions,\n): Promise<T[] | null> {\n\tconst out: T[] = [];\n\tlet cursor: string | null = null;\n\tfor (;;) {\n\t\tconst page: string = cursor\n\t\t\t? `${url}&cursor=${encodeURIComponent(cursor)}`\n\t\t\t: url;\n\t\tconst j = await getJson<Record<string, unknown>>(page, http);\n\t\tif (j === null) return cursor === null ? null : out;\n\t\tconst rows = j[field];\n\t\tif (!Array.isArray(rows))\n\t\t\tthrow new SourceError(page, 200, `answer has no ${field} array`);\n\t\tout.push(...(rows as T[]));\n\t\tconst next = j.next_cursor;\n\t\tif (rows.length < PAGE || typeof next !== \"string\" || next === cursor)\n\t\t\treturn out;\n\t\tcursor = next;\n\t}\n}\n\n// Both sources keep their origin and account key in constructor closures, not\n// fields: nothing leaks through a spread, a log or JSON.stringify.\n\n/**\n * Every proof input from the Secondlayer API: `/v1/proofs/*` for blocks, epoch\n * 2.x headers, MARF proofs, witnesses, burn preimages and Bitcoin headers; the Index API for\n * state_writes and vm_events, read only when verifyBlock gets `rows: true`.\n * Methods are own properties, so a partial source spreads over it:\n * `{ ...new SecondlayerProofSource(o), ...new NodeRpcProofSource(n) }`.\n */\nexport class SecondlayerProofSource implements ProofSource {\n\tgetBlock: (ref: string | number) => Promise<Bytes>;\n\tgetEpoch2Header: (blockId: string) => Promise<Epoch2HeaderResponse>;\n\tgetMarfProof: (\n\t\tpathHex: string,\n\t\ttipId: string,\n\t) => Promise<MarfProofResponse | null>;\n\tgetWitness: (blockId: string) => Promise<Bytes>;\n\tgetBurnPreimage: (consensusHash: string) => Promise<BurnPreimage>;\n\tgetBitcoinHeaders: (from: number, count: number) => Promise<string[]>;\n\tgetStateWrites: (height: number) => Promise<StateWrite[] | null>;\n\tgetVmEvents: (height: number) => Promise<VmEventRow[]>;\n\n\tconstructor(opts: SecondlayerSourceOptions) {\n\t\tconst base = trimSlash(opts.baseUrl);\n\t\tconst http: HttpOptions = {\n\t\t\theaders: { authorization: `Bearer ${opts.apiKey}` },\n\t\t\tfetch: opts.fetch,\n\t\t};\n\n\t\tthis.getBlock = async (ref) => {\n\t\t\tconst url =\n\t\t\t\ttypeof ref === \"number\"\n\t\t\t\t\t? `${base}/v1/proofs/block/height/${ref}`\n\t\t\t\t\t: `${base}/v1/proofs/block/${ref}`;\n\t\t\treturn required(url, await getBytes(url, http));\n\t\t};\n\n\t\tthis.getEpoch2Header = async (blockId) => {\n\t\t\tconst url = `${base}/v1/proofs/epoch2-header/${blockId}`;\n\t\t\treturn toEpoch2(url, await getJson<HeadersJson>(url, http));\n\t\t};\n\n\t\tthis.getMarfProof = async (pathHex, tipId) => {\n\t\t\tconst url = `${base}/v1/proofs/marf/${pathHex}?tip=${tipId}`;\n\t\t\treturn toMarf(url, await getJson<MarfJson>(url, http));\n\t\t};\n\n\t\tthis.getWitness = async (blockId) => {\n\t\t\tconst url = `${base}/v1/proofs/witness/${blockId}`;\n\t\t\treturn required(url, await getBytes(url, http));\n\t\t};\n\n\t\tthis.getBurnPreimage = async (consensusHash) => {\n\t\t\tconst url = `${base}/v1/proofs/burn/${consensusHash}`;\n\t\t\tconst j = required(\n\t\t\t\turl,\n\t\t\t\tawait getJson<{ burn_height: number; preimage: string }>(url, http),\n\t\t\t);\n\t\t\treturn { preimage: unhex(j.preimage), burnHeight: j.burn_height };\n\t\t};\n\n\t\tthis.getBitcoinHeaders = async (from, count) => {\n\t\t\tconst url = `${base}/v1/proofs/bitcoin-headers?from=${from}&count=${count}`;\n\t\t\tconst j = required(\n\t\t\t\turl,\n\t\t\t\tawait getJson<{ from: number; headers: string[] }>(url, http),\n\t\t\t);\n\t\t\tif (j.from !== from)\n\t\t\t\tthrow new SourceError(url, 200, `headers start at ${j.from}`);\n\t\t\treturn j.headers;\n\t\t};\n\n\t\tthis.getStateWrites = (height) =>\n\t\t\tpages<StateWrite>(\n\t\t\t\t\"state_writes\",\n\t\t\t\t`${base}/v1/index/state-writes?block_height=${height}&limit=${PAGE}`,\n\t\t\t\thttp,\n\t\t\t);\n\n\t\tthis.getVmEvents = async (height) => {\n\t\t\tconst out: VmEventRow[] = [];\n\t\t\tfor (const type of VM_WRITE_TYPES) {\n\t\t\t\tconst url = `${base}/v1/index/events?event_type=${type}&from_height=${height}&to_height=${height}&limit=${PAGE}`;\n\t\t\t\tout.push(...((await pages<VmEventRow>(\"events\", url, http)) ?? []));\n\t\t\t}\n\t\t\treturn out.sort((a, b) => a.event_index - b.event_index);\n\t\t};\n\t}\n}\n\nexport interface NodeRpcSourceOptions {\n\t/** Stacks node RPC origin, e.g. `http://localhost:20443`. */\n\tnodeUrl: string;\n\tfetch?: Fetch;\n}\n\n/**\n * Blocks, epoch 2.x headers and MARF proofs straight from a Stacks node's RPC.\n * Witnesses, burn preimages and Bitcoin headers need another source: spread\n * this over one.\n */\nexport class NodeRpcProofSource\n\timplements Pick<ProofSource, \"getBlock\" | \"getEpoch2Header\" | \"getMarfProof\">\n{\n\tgetBlock: (ref: string | number) => Promise<Bytes>;\n\tgetEpoch2Header: (blockId: string) => Promise<Epoch2HeaderResponse>;\n\tgetMarfProof: (\n\t\tpathHex: string,\n\t\ttipId: string,\n\t) => Promise<MarfProofResponse | null>;\n\n\tconstructor(opts: NodeRpcSourceOptions) {\n\t\tconst base = trimSlash(opts.nodeUrl);\n\t\tconst http: HttpOptions = { fetch: opts.fetch };\n\n\t\tthis.getBlock = async (ref) => {\n\t\t\tconst url =\n\t\t\t\ttypeof ref === \"number\"\n\t\t\t\t\t? `${base}/v3/blocks/height/${ref}`\n\t\t\t\t\t: `${base}/v3/blocks/${ref}`;\n\t\t\treturn required(url, await getBytes(url, http));\n\t\t};\n\n\t\tthis.getEpoch2Header = async (blockId) => {\n\t\t\tconst url = `${base}/v2/headers/1?tip=${blockId}`;\n\t\t\treturn toEpoch2(url, await getJson<HeadersJson>(url, http));\n\t\t};\n\n\t\tthis.getMarfProof = async (pathHex, tipId) => {\n\t\t\tconst url = `${base}/v2/clarity/marf/${pathHex}?tip=${tipId}&proof=1`;\n\t\t\treturn toMarf(url, await getJson<MarfJson>(url, http));\n\t\t};\n\t}\n}\n",
|
|
17
|
-
"// Steps 6-8 of verifyBlock: a block's state witness against its authenticated\n// header root, every leaf of its trie named, and indexed rows against the diff.\nimport { type Bytes, bytesEqual, hex, unhex } from \"./bytes.ts\";\nimport { dataVarKey } from \"./keys.ts\";\nimport {\n\tMARF_VALUE_SIZE,\n\theightToHashKey,\n\tmarfPath,\n\tmarfValue,\n} from \"./marf.ts\";\nimport type { StateWrite, VmEventRow } from \"./source.ts\";\nimport {\n\ttype WitnessLeaf,\n\tclassifyBlockDiff,\n\tparseWitness,\n} from \"./witness.ts\";\n\nexport interface DiffWrite {\n\t/** MARF key, when a state_writes row names the leaf. */\n\tkey?: string;\n\t/** Leaf path, hex. */\n\tpath: string;\n\t/** sha512/256 of the stored value string, hex. */\n\tvalueHash: string;\n\t/** Transaction of the last write; null for block-level writes. */\n\ttxIndex?: number | null;\n\t/** False when the source had no state_writes: the leaf may also be a carried copy. */\n\tnamed: boolean;\n}\n\nexport interface DiffLeaf {\n\tkey?: string;\n\tpath: string;\n\tvalueHash: string;\n}\n\nexport interface ProvenDiff {\n\t/** Every leaf is named (state_writes served) and classified. */\n\tnamed: boolean;\n\twrites: DiffWrite[];\n\t/** Unchanged values copied forward from the parent (proven at the parent). */\n\tcarried: DiffLeaf[];\n\t/** `__MARF_BLOCK_*` bookkeeping. */\n\tinternal: DiffLeaf[];\n}\n\nexport type StateFailureCode =\n\t| \"malformed\"\n\t| \"root-mismatch\"\n\t| \"bad-write\"\n\t| \"hidden-write\"\n\t| \"missing-write\"\n\t| \"key-not-written\"\n\t| \"value-mismatch\"\n\t| \"bad-row\";\n\nexport interface StateFailure {\n\tstep: \"witness\" | \"names\" | \"rows\";\n\tcode: StateFailureCode;\n\tmessage: string;\n\tkey?: string;\n\tpath?: string;\n\tordinal?: number;\n}\n\nexport interface BlockStateInput {\n\t/** MARF height of the block (its Stacks chain length). */\n\theight: number;\n\t/** Parent block id from the authenticated header. */\n\tparentBlockId: Bytes;\n\t/** state_index_root from the authenticated header. */\n\tstateRoot: Bytes;\n\twitness: Bytes;\n\t/** The block's state_writes; null when the source has none (names unavailable). */\n\twrites: StateWrite[] | null;\n\t/** Indexed rows to prove against the diff. */\n\trows?: VmEventRow[];\n\t/**\n\t * Leaves of the parent's own trie, from a parent witness whose root the\n\t * caller checked against the parent header: each is the parent state's\n\t * value at its path. Resolves carried leaves without a proof per leaf.\n\t */\n\tparentLeaves?: WitnessLeaf[];\n\t/**\n\t * True iff the leaf's value is stored at its path in the parent's state\n\t * (proven by the caller). Asked only with state_writes, for leaves the\n\t * parent's own trie does not explain.\n\t */\n\tparentHolds?: (leaf: WitnessLeaf) => Promise<boolean>;\n}\n\nexport interface BlockStateResult {\n\tdiff?: ProvenDiff;\n\trowsChecked: number;\n\tnotes: string[];\n\tfailures: StateFailure[];\n}\n\nconst INTERNAL = {\n\tself: \"__MARF_BLOCK_HEIGHT_SELF\",\n\thashToHeight: \"__MARF_BLOCK_HASH_TO_HEIGHT\",\n} as const;\n\n/** MARFValue of a u32 height: little-endian in the first 4 bytes. */\nconst heightValue = (h: number): string => {\n\tconst v = new Uint8Array(MARF_VALUE_SIZE);\n\tnew DataView(v.buffer).setUint32(0, h, true);\n\treturn hex(v);\n};\n/** 40-byte MARFValue hex of a 32-byte hash or block id (zero tail). */\nconst padded = (b32: Bytes): string => `${hex(b32)}${\"00\".repeat(8)}`;\n\n/**\n * The `__MARF_BLOCK_*` entries block `height` writes (stacks-core index/marf.rs).\n * The parent's are fixed by the header. The block's own id is not known while\n * its trie is built, so `HEIGHT_TO_HASH::{height}` holds a temporary hash; its\n * value is taken from the witness and must map back to `height`.\n */\nfunction internalEntries(\n\theight: number,\n\tparentBlockId: Bytes,\n\tleaves: WitnessLeaf[],\n): [key: string, valueHex: string][] {\n\tconst out: [string, string][] = [[INTERNAL.self, heightValue(height)]];\n\tconst ownKey = heightToHashKey(height);\n\tconst ownPath = marfPath(ownKey);\n\tconst own = leaves.find((l) => bytesEqual(l.path, ownPath));\n\tif (own) {\n\t\tout.push([ownKey, padded(own.valueHash)]);\n\t\tout.push([\n\t\t\t`${INTERNAL.hashToHeight}::${hex(own.valueHash)}`,\n\t\t\theightValue(height),\n\t\t]);\n\t}\n\tif (height > 0) {\n\t\tout.push([heightToHashKey(height - 1), padded(parentBlockId)]);\n\t\tout.push([\n\t\t\t`${INTERNAL.hashToHeight}::${hex(parentBlockId)}`,\n\t\t\theightValue(height - 1),\n\t\t]);\n\t}\n\treturn out;\n}\n\nconst utf8 = new TextDecoder(\"utf-8\", { fatal: true });\nconst strip0x = (s: string) => (s.startsWith(\"0x\") ? s.slice(2) : s);\nconst leafHex = (l: WitnessLeaf): DiffLeaf => ({\n\tpath: hex(l.path),\n\tvalueHash: hex(l.valueHash),\n});\n\n/** Last write per key, in ordinal order, with its value as the stored string. */\nfunction lastWrites(\n\twrites: StateWrite[],\n\tfailures: StateFailure[],\n): Map<string, { value: string; txIndex: number | null }> {\n\tconst out = new Map<string, { value: string; txIndex: number | null }>();\n\tfor (const w of [...writes].sort((a, b) => a.ordinal - b.ordinal)) {\n\t\ttry {\n\t\t\tout.set(w.key, {\n\t\t\t\tvalue: utf8.decode(unhex(strip0x(w.value_hex))),\n\t\t\t\ttxIndex: w.tx_index,\n\t\t\t});\n\t\t} catch {\n\t\t\tfailures.push({\n\t\t\t\tstep: \"names\",\n\t\t\t\tcode: \"bad-write\",\n\t\t\t\tmessage: `state write ${w.ordinal} value is not UTF-8 hex`,\n\t\t\t\tkey: w.key,\n\t\t\t\tordinal: w.ordinal,\n\t\t\t});\n\t\t}\n\t}\n\treturn out;\n}\n\n/** The MARF key and stored value string a vm_events row writes (mirrors clarity_db.rs). */\nfunction rowWrite(row: VmEventRow): [key: string, value: string] {\n\tconst need = (v: string | null | undefined, name: string): string => {\n\t\tif (!v) throw new Error(`${row.event_type} row has no ${name}`);\n\t\treturn v;\n\t};\n\tif (row.event_type === \"var_set\")\n\t\treturn [\n\t\t\tdataVarKey(row.contract_id, need(row.var_name, \"var_name\")),\n\t\t\tstrip0x(need(row.raw_value, \"raw_value\")).toLowerCase(),\n\t\t];\n\tconst key = `vm::${row.contract_id}::0::${need(row.map, \"map\")}::${strip0x(need(row.raw_key, \"raw_key\")).toLowerCase()}`;\n\tif (row.event_type === \"map_delete\") return [key, \"09\"];\n\t// put_value stores map entries as (some value).\n\treturn [key, `0a${strip0x(need(row.raw_value, \"raw_value\")).toLowerCase()}`];\n}\n\n/**\n * Rows against the block's leaves: every row's key must be a leaf, and the\n * last row per key must carry the leaf's value.\n */\nfunction checkRows(\n\trows: VmEventRow[],\n\tleaves: WitnessLeaf[],\n\tfailures: StateFailure[],\n): number {\n\tconst byPath = new Map(leaves.map((l) => [hex(l.path), l]));\n\tconst named: { row: VmEventRow; key: string; path: string; value: string }[] =\n\t\t[];\n\tfor (const row of [...rows].sort((a, b) => a.event_index - b.event_index)) {\n\t\ttry {\n\t\t\tconst [key, value] = rowWrite(row);\n\t\t\tnamed.push({ row, key, path: hex(marfPath(key)), value });\n\t\t} catch (err) {\n\t\t\tfailures.push({\n\t\t\t\tstep: \"rows\",\n\t\t\t\tcode: \"bad-row\",\n\t\t\t\tmessage: (err as Error).message,\n\t\t\t\tordinal: row.event_index,\n\t\t\t});\n\t\t}\n\t}\n\tconst last = new Map(named.map((n, i) => [n.path, i]));\n\tnamed.forEach((n, i) => {\n\t\tconst leaf = byPath.get(n.path);\n\t\tconst at = { key: n.key, path: n.path, ordinal: n.row.event_index };\n\t\tif (!leaf)\n\t\t\tfailures.push({\n\t\t\t\tstep: \"rows\",\n\t\t\t\tcode: \"key-not-written\",\n\t\t\t\tmessage: `${n.row.event_type} row ${n.row.event_index} names a key the block did not write`,\n\t\t\t\t...at,\n\t\t\t});\n\t\telse if (\n\t\t\tlast.get(n.path) === i &&\n\t\t\tpadded(leaf.valueHash) !== hex(marfValue(n.value))\n\t\t)\n\t\t\tfailures.push({\n\t\t\t\tstep: \"rows\",\n\t\t\t\tcode: \"value-mismatch\",\n\t\t\t\tmessage: `${n.row.event_type} row ${n.row.event_index} value differs from the block's leaf`,\n\t\t\t\t...at,\n\t\t\t});\n\t});\n\treturn named.length;\n}\n\n/**\n * Verify block state against an authenticated header: the witness must\n * recompute `stateRoot`, then every leaf is classified. With state_writes,\n * any leaf that is not a named write, a carried parent value or MARF\n * bookkeeping is a hidden write. Without them the diff is still proven\n * (every leaf is in the block): carried leaves are told apart only through\n * `parentLeaves`, and the remaining writes come back unnamed.\n */\nexport async function verifyBlockState(\n\tinput: BlockStateInput,\n): Promise<BlockStateResult> {\n\tconst out: BlockStateResult = { rowsChecked: 0, notes: [], failures: [] };\n\tlet witness: ReturnType<typeof parseWitness>;\n\ttry {\n\t\twitness = parseWitness(input.witness);\n\t} catch (err) {\n\t\tout.failures.push({\n\t\t\tstep: \"witness\",\n\t\t\tcode: \"malformed\",\n\t\t\tmessage: (err as Error).message,\n\t\t});\n\t\treturn out;\n\t}\n\tif (!bytesEqual(witness.root, input.stateRoot)) {\n\t\tout.failures.push({\n\t\t\tstep: \"witness\",\n\t\t\tcode: \"root-mismatch\",\n\t\t\tmessage: `witness root ${hex(witness.root)} != header state_index_root ${hex(input.stateRoot)}`,\n\t\t});\n\t\treturn out;\n\t}\n\tconst { leaves } = witness;\n\tconst internal = internalEntries(input.height, input.parentBlockId, leaves);\n\tconst named = input.writes !== null;\n\tconst last = lastWrites(input.writes ?? [], out.failures);\n\tconst writes = [...last].map(([k, w]): [string, string] => [k, w.value]);\n\t// First pass with no parent values finds the leaves that need one.\n\tconst first = classifyBlockDiff({\n\t\tleaves,\n\t\twrites,\n\t\tinternal,\n\t\tparentValue: () => undefined,\n\t});\n\tconst inParent = new Map(\n\t\t(input.parentLeaves ?? []).map((l) => [hex(l.path), hex(l.valueHash)]),\n\t);\n\tconst carried = new Map<string, string>();\n\tfor (const leaf of first.hidden) {\n\t\tconst pathHex = hex(leaf.path);\n\t\tif (\n\t\t\tinParent.get(pathHex) === hex(leaf.valueHash) ||\n\t\t\t(named && (await input.parentHolds?.(leaf)))\n\t\t)\n\t\t\tcarried.set(pathHex, padded(leaf.valueHash));\n\t}\n\tconst d = classifyBlockDiff({\n\t\tleaves,\n\t\twrites,\n\t\tinternal,\n\t\tparentValue: (p) => carried.get(p),\n\t});\n\tout.diff = {\n\t\tnamed,\n\t\twrites: named\n\t\t\t? d.writes.map((l) => ({\n\t\t\t\t\t...leafHex(l),\n\t\t\t\t\tkey: l.key,\n\t\t\t\t\ttxIndex: last.get(l.key)?.txIndex ?? null,\n\t\t\t\t\tnamed: true,\n\t\t\t\t}))\n\t\t\t: // Without names every unexplained leaf is a write we cannot label.\n\t\t\t\td.hidden.map((l) => ({ ...leafHex(l), named: false })),\n\t\tcarried: d.carried.map(leafHex),\n\t\tinternal: d.internal.map((l) => ({ ...leafHex(l), key: l.key })),\n\t};\n\tif (!named)\n\t\tout.notes.push(\n\t\t\t`source has no state_writes for block ${input.height}: ${d.hidden.length} written leaves are proven in the block but unnamed`,\n\t\t);\n\telse {\n\t\tfor (const l of d.hidden)\n\t\t\tout.failures.push({\n\t\t\t\tstep: \"names\",\n\t\t\t\tcode: \"hidden-write\",\n\t\t\t\tmessage: `leaf ${hex(l.path)} is not a named write, a carried parent value or MARF bookkeeping`,\n\t\t\t\tpath: hex(l.path),\n\t\t\t});\n\t\tfor (const key of d.missing)\n\t\t\tout.failures.push({\n\t\t\t\tstep: \"names\",\n\t\t\t\tcode: \"missing-write\",\n\t\t\t\tmessage: `state write ${key} has no leaf holding its value`,\n\t\t\t\tkey,\n\t\t\t\tpath: hex(marfPath(key)),\n\t\t\t});\n\t}\n\tif (input.rows) out.rowsChecked = checkRows(input.rows, leaves, out.failures);\n\treturn out;\n}\n",
|
|
18
|
-
"// verifyBlock: the end-to-end trustless check for one Stacks block.\n//\n// At or above the checkpoint, forward:\n// checkpoint ─▶ bitcoin headers (PoW) ─▶ burn height ─▶ cycle ─▶ signer set[cycle] (MARF-proven)\n// ─▶ header N (signatures ≥ 70%) ─▶ witness N (root) ─▶ named diff ─▶ indexed rows\n//\n// Below it, backward: a trusted descendant's id commits to every ancestor by\n// hash, so no signatures are needed:\n// checkpoint ─▶ id N (parent links, or one MARF proof of __MARF_BLOCK_HEIGHT_TO_HASH::N)\n// ─▶ header N (hashes to id N) ─▶ witness N (root) ─▶ named diff ─▶ indexed rows\n//\n// Every input comes from an untrusted ProofSource; only the checkpoint is trusted.\nimport { uintCV } from \"@secondlayer/stacks/clarity\";\nimport { HeaderChain, HeaderValidationError } from \"./bitcoin/chain.ts\";\nimport {\n\tMAINNET_PREPARE_LENGTH,\n\tcycleStart,\n\trewardCycle,\n\tverifyConsensusPreimage,\n} from \"./burn.ts\";\nimport { type Bytes, bytesEqual, hex, unhex } from \"./bytes.ts\";\nimport { MAINNET_CHECKPOINT, type VerifyCheckpoint } from \"./checkpoint.ts\";\nimport {\n\ttype Epoch2Header,\n\ttype NakamotoHeader,\n\ttype StacksHeader,\n\tblockId,\n\tisEpoch2Header,\n\tparseEpoch2Header,\n\tparseNakamotoHeader,\n} from \"./header.ts\";\nimport { mapEntryKey } from \"./keys.ts\";\nimport {\n\tMARF_VALUE_SIZE,\n\theightToHashKey,\n\tmarfPath,\n\tmarfProofAncestors,\n\tmarfProofValue,\n\tmarfValue,\n\tverifyMarfProof,\n} from \"./marf.ts\";\nimport {\n\tSIGNERS_CONTRACT,\n\ttype SignerSet,\n\tdecodeSignerSet,\n\tverifySignerSignatures,\n} from \"./signers.ts\";\nimport type { BurnPreimage, ProofSource } from \"./source.ts\";\nimport {\n\ttype ProvenDiff,\n\ttype StateFailureCode,\n\tverifyBlockState,\n} from \"./state.ts\";\nimport { type WitnessLeaf, parseWitness } from \"./witness.ts\";\n\nexport type VerifyStep =\n\t| \"ancestry\"\n\t| \"block\"\n\t| \"bitcoin\"\n\t| \"burn\"\n\t| \"signer-set\"\n\t| \"signatures\"\n\t| \"witness\"\n\t| \"names\"\n\t| \"rows\";\n\nexport type VerifyFailureCode =\n\t| StateFailureCode\n\t/** The source could not serve something the step needs. */\n\t| \"unavailable\"\n\t| \"id-mismatch\"\n\t| \"height-mismatch\"\n\t| \"invalid-header\"\n\t| \"preimage-mismatch\"\n\t| \"burn-not-in-chain\"\n\t| \"before-checkpoint\"\n\t/** The block is not the checkpoint chain's block at its height. */\n\t| \"not-ancestor\"\n\t| \"ancestry-proof-invalid\"\n\t| \"anchor-not-found\"\n\t| \"anchor-outside-window\"\n\t| \"anchor-unsigned\"\n\t| \"set-proof-invalid\"\n\t| \"below-threshold\"\n\t| \"unknown-signer\"\n\t| \"duplicate-signer\"\n\t| \"bad-signature\";\n\nexport interface VerifyFailure {\n\tstep: VerifyStep;\n\tcode: VerifyFailureCode;\n\tmessage: string;\n\t/** Reward cycle being proven (signer-set step). */\n\tcycle?: number;\n\t/** Block the failure is about, when not the target. */\n\tblockId?: string;\n\tkey?: string;\n\tpath?: string;\n\tordinal?: number;\n}\n\n/** How a block below the checkpoint was tied to it. */\nexport interface Ancestry {\n\t/** Trusted descendant it was proven from: the checkpoint, or a block proven below it earlier. */\n\tfromHeight: number;\n\tfromBlockId: string;\n\t/**\n\t * `parents`: each header hashes to the parent id its child commits to.\n\t * `marf`: one MARF proof of `__MARF_BLOCK_HEIGHT_TO_HASH::<height>` against\n\t * the descendant's state root.\n\t */\n\tvia: \"parents\" | \"marf\";\n}\n\nexport interface BlockVerification {\n\t/**\n\t * Every step passed. At or above the checkpoint: header, burn binding,\n\t * signatures, state root, names and rows. Below it: ancestry, header,\n\t * state root, names and rows (and the burn binding when Bitcoin reaches it).\n\t */\n\tok: boolean;\n\theight?: number;\n\tblockId?: string;\n\t/** The header's state_index_root, hex: what the witness must hash to. */\n\tstateRoot?: string;\n\t/** Set for blocks below the checkpoint, which need no signatures. */\n\tancestry?: Ancestry;\n\tcycle?: number;\n\tburnHeight?: number;\n\t/** Display-order hex. */\n\tbitcoinBlockHash?: string;\n\tsignerWeight?: bigint;\n\ttotalWeight?: bigint;\n\tthreshold?: bigint;\n\tdiff?: ProvenDiff;\n\t/** vm_events rows proven against the diff. */\n\trowsChecked?: number;\n\tnotes: string[];\n\t/** Empty when ok. The first entry is the first broken link. */\n\tfailures: VerifyFailure[];\n}\n\nexport interface VerifyOptions {\n\tsource: ProofSource;\n\t/** Defaults to MAINNET_CHECKPOINT. */\n\tcheckpoint?: VerifyCheckpoint;\n\t/**\n\t * Also name the block's writes and prove its indexed rows: reads the\n\t * source's `getStateWrites` and `getVmEvents`, which bill as Index rows on\n\t * the Secondlayer API. Off by default, so verification reads proofs only.\n\t */\n\trows?: boolean;\n}\n\nclass Broken extends Error {\n\tconstructor(readonly failure: VerifyFailure) {\n\t\tsuper(failure.message);\n\t}\n}\n\nconst fail = (f: VerifyFailure): never => {\n\tthrow new Broken(f);\n};\n\n/** Run a source call; a throw becomes an `unavailable` failure of `step`. */\nasync function fetchFor<T>(\n\tstep: VerifyStep,\n\twhat: string,\n\tcall: () => Promise<T>,\n\textra: Partial<VerifyFailure> = {},\n): Promise<T> {\n\ttry {\n\t\treturn await call();\n\t} catch (err) {\n\t\tif (err instanceof Broken) throw err;\n\t\treturn fail({\n\t\t\tstep,\n\t\t\tcode: \"unavailable\",\n\t\t\tmessage: `${what}: ${(err as Error).message}`,\n\t\t\t...extra,\n\t\t});\n\t}\n}\n\nconst BITCOIN_BATCH = 2016;\n/**\n * Below the checkpoint, ancestors this close to a trusted block are reached by\n * parent links (one block fetch each); farther ones by one MARF proof, which\n * costs the proof plus a header per ancestor trie it crosses.\n */\nconst MAX_WALK = 16;\n\n/** A block position for the anchor search; `burn` is a source hint. */\nexport interface SearchPoint {\n\theight: number;\n\tburn?: number;\n}\n\n/**\n * Find a block whose burn height lies in `[window[0], window[1])`, between\n * `lo` and `hi` (exclusive). Interpolates on burn height, falling back to\n * bisection whenever a probe fails to halve the bracket. Burn heights here\n * are unproven hints: the caller authenticates whatever this returns.\n */\nexport async function findAnchor<T extends SearchPoint & { burn: number }>(\n\tlow: SearchPoint,\n\thigh: SearchPoint,\n\twindow: readonly [number, number],\n\tprobe: (height: number) => Promise<T>,\n\tmaxProbes = 32,\n): Promise<T | null> {\n\tlet [lo, hi] = [low, high];\n\tconst target = (window[0] + window[1]) / 2;\n\tlet bisect = false;\n\tfor (let i = 0; i < maxProbes; i++) {\n\t\tconst span = hi.height - lo.height;\n\t\tif (span <= 1) return null;\n\t\tlet h = Math.floor((lo.height + hi.height) / 2);\n\t\tif (\n\t\t\t!bisect &&\n\t\t\tlo.burn !== undefined &&\n\t\t\thi.burn !== undefined &&\n\t\t\thi.burn > lo.burn\n\t\t)\n\t\t\th =\n\t\t\t\tlo.height +\n\t\t\t\tMath.round(((target - lo.burn) * span) / (hi.burn - lo.burn));\n\t\th = Math.min(Math.max(h, lo.height + 1), hi.height - 1);\n\t\tconst p = await probe(h);\n\t\tif (p.height <= lo.height || p.height >= hi.height) return null;\n\t\tif (p.burn >= window[0] && p.burn < window[1]) return p;\n\t\tif (p.burn < window[0]) lo = p;\n\t\telse hi = p;\n\t\tbisect = hi.height - lo.height > span / 2;\n\t}\n\treturn null;\n}\n\ninterface Probe extends SearchPoint {\n\tburn: number;\n\theader: NakamotoHeader;\n\tid: string;\n}\n\n/**\n * Verifies blocks from one checkpoint against one source, caching the Bitcoin\n * header chain, proven signer sets and fetched headers across calls.\n */\nexport class BlockVerifier {\n\tprivate readonly source: ProofSource;\n\tprivate readonly checkpoint: VerifyCheckpoint;\n\tprivate readonly rows: boolean;\n\tprivate readonly chain: HeaderChain;\n\t/** Proven signer sets by cycle. */\n\tprivate readonly sets = new Map<number, SignerSet>();\n\t/** Where each proven set was anchored: the lower bound for the next search. */\n\tprivate readonly anchors = new Map<number, SearchPoint>();\n\t/** Headers fetched by id, each checked to hash to it. */\n\tprivate readonly headers = new Map<string, StacksHeader>();\n\t/** Blocks proven on the checkpoint's chain below it, by height. */\n\tprivate readonly below = new Map<\n\t\tnumber,\n\t\t{ id: string; ancestry: Ancestry }\n\t>();\n\tprivate readonly burns = new Map<\n\t\tstring,\n\t\t{ burnHeight: number; hash: string }\n\t>();\n\t/** Unverified source answers by consensus hash. */\n\tprivate readonly preimages = new Map<string, BurnPreimage>();\n\tprivate readonly start: { header: NakamotoHeader; id: string };\n\n\tconstructor(opts: VerifyOptions) {\n\t\tthis.source = opts.source;\n\t\tthis.checkpoint = opts.checkpoint ?? MAINNET_CHECKPOINT;\n\t\tthis.rows = opts.rows ?? false;\n\t\tconst { stacks } = this.checkpoint;\n\t\tconst header = parseNakamotoHeader(unhex(stacks.header));\n\t\tthis.start = { header, id: hex(blockId(header)) };\n\t\tthis.headers.set(this.start.id, header);\n\t\tthis.sets.set(stacks.cycle, decodeSignerSet(stacks.signerSet));\n\t\tthis.chain = HeaderChain.fromCheckpoint(this.checkpoint.bitcoin);\n\t}\n\n\t/** Verify one block by id (hex) or height. Never throws for bad source data. */\n\tasync verify(ref: string | number): Promise<BlockVerification> {\n\t\tconst out: BlockVerification = { ok: false, notes: [], failures: [] };\n\t\ttry {\n\t\t\tawait this.run(ref, out);\n\t\t} catch (err) {\n\t\t\tif (!(err instanceof Broken)) throw err;\n\t\t\tout.failures.unshift(err.failure);\n\t\t}\n\t\tout.ok = out.failures.length === 0;\n\t\treturn out;\n\t}\n\n\tprivate async run(\n\t\tref: string | number,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tconst start = Number(this.start.header.chainLength);\n\t\tif (typeof ref === \"number\" && ref < start)\n\t\t\treturn this.runBelow(ref, undefined, out);\n\t\tlet header: StacksHeader;\n\t\tif (typeof ref === \"string\") {\n\t\t\tconst id = ref.replace(/^0x/, \"\").toLowerCase();\n\t\t\theader = await this.header(id, \"block\");\n\t\t\tconst height = Number(header.chainLength);\n\t\t\tif (height < start) return this.runBelow(height, id, out);\n\t\t\tif (isEpoch2Header(header))\n\t\t\t\tfail({\n\t\t\t\t\tstep: \"block\",\n\t\t\t\t\tcode: \"invalid-header\",\n\t\t\t\t\tmessage: `epoch 2.x block ${id} claims height ${height}, at or above the checkpoint`,\n\t\t\t\t});\n\t\t} else {\n\t\t\tconst raw = await fetchFor(\"block\", `block ${ref}`, () =>\n\t\t\t\tthis.source.getBlock(ref),\n\t\t\t);\n\t\t\theader = parseHeader(raw, \"block\");\n\t\t}\n\t\tconst id = hex(blockId(header));\n\t\tconst height = Number(header.chainLength);\n\t\tif (typeof ref === \"number\" && height !== ref)\n\t\t\tfail({\n\t\t\t\tstep: \"block\",\n\t\t\t\tcode: \"height-mismatch\",\n\t\t\t\tmessage: `source returned height ${height} for ${ref}`,\n\t\t\t});\n\t\tawait this.runForward(header as NakamotoHeader, id, out);\n\t}\n\n\t/** At or above the checkpoint: Bitcoin, burn binding, signer set, signatures, state. */\n\tprivate async runForward(\n\t\theader: NakamotoHeader,\n\t\tid: string,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tconst height = Number(header.chainLength);\n\t\tout.height = height;\n\t\tout.blockId = id;\n\t\tout.stateRoot = hex(header.stateIndexRoot);\n\n\t\tconst burn = await this.bindBurn(header, \"burn\");\n\t\tconst cycle = rewardCycle(burn.burnHeight);\n\t\tout.burnHeight = burn.burnHeight;\n\t\tout.bitcoinBlockHash = burn.hash;\n\t\tout.cycle = cycle;\n\n\t\tconst set = await this.signerSet(cycle, {\n\t\t\theight,\n\t\t\tburn: burn.burnHeight,\n\t\t});\n\t\tconst sig = verifySignerSignatures(header, set);\n\t\tout.signerWeight = sig.signedWeight;\n\t\tout.totalWeight = sig.totalWeight;\n\t\tout.threshold = sig.threshold;\n\t\tif (!sig.valid) fail(signatureFailure(sig, \"signatures\", cycle));\n\t\tawait this.verifyState(header, id, out);\n\t}\n\n\t/**\n\t * Below the checkpoint: prove the checkpoint chain's id at `height` (and\n\t * that it is `claimed`, when the caller asked by id), then the header that\n\t * hashes to it, then its state. Signatures add nothing to a header pinned\n\t * by hash from a trusted descendant.\n\t */\n\tprivate async runBelow(\n\t\theight: number,\n\t\tclaimed: string | undefined,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tout.height = height;\n\t\tconst { id, ancestry } = await this.ancestor(height);\n\t\tout.ancestry = ancestry;\n\t\tif (claimed !== undefined && claimed !== id)\n\t\t\tfail({\n\t\t\t\tstep: \"ancestry\",\n\t\t\t\tcode: \"not-ancestor\",\n\t\t\t\tmessage: `block ${claimed} is not on the checkpoint's chain: its block at height ${height} is ${id}`,\n\t\t\t\tblockId: claimed,\n\t\t\t});\n\t\tconst header = await this.header(id, \"block\");\n\t\tif (Number(header.chainLength) !== height)\n\t\t\tfail({\n\t\t\t\tstep: \"block\",\n\t\t\t\tcode: \"height-mismatch\",\n\t\t\t\tmessage: `block ${id} claims height ${header.chainLength}, proven at ${height}`,\n\t\t\t});\n\t\tout.blockId = id;\n\t\tout.stateRoot = hex(header.stateIndexRoot);\n\t\tawait this.bindBurnBelow(header, out);\n\t\tawait this.verifyState(header, id, out);\n\t}\n\n\t/**\n\t * The checkpoint chain's block id at `height`, from the nearest trusted\n\t * block above it: parent links when within MAX_WALK, else one MARF proof.\n\t */\n\tprivate async ancestor(\n\t\theight: number,\n\t): Promise<{ id: string; ancestry: Ancestry }> {\n\t\tconst known = this.below.get(height);\n\t\tif (known) return known;\n\t\tconst from = this.nearestAbove(height);\n\t\tif (from.height - height <= MAX_WALK) {\n\t\t\tconst walked = await this.walk(from, height);\n\t\t\tif (walked) return walked;\n\t\t}\n\t\treturn this.jump(this.nearestAbove(height), height);\n\t}\n\n\t/** The lowest trusted block above `height`: the checkpoint or one proven below it. */\n\tprivate nearestAbove(height: number): { height: number; id: string } {\n\t\tlet best = {\n\t\t\theight: Number(this.start.header.chainLength),\n\t\t\tid: this.start.id,\n\t\t};\n\t\tfor (const [h, { id }] of this.below)\n\t\t\tif (h > height && h < best.height) best = { height: h, id };\n\t\treturn best;\n\t}\n\n\t/**\n\t * Follow parent ids down from `from`: each parent header must hash to the\n\t * id its child committed to. Null when a 2.x header stops the walk: it\n\t * commits to its parent's block hash, not the parent's id.\n\t */\n\tprivate async walk(\n\t\tfrom: { height: number; id: string },\n\t\theight: number,\n\t): Promise<{ id: string; ancestry: Ancestry } | null> {\n\t\tconst ancestry: Ancestry = {\n\t\t\tfromHeight: from.height,\n\t\t\tfromBlockId: from.id,\n\t\t\tvia: \"parents\",\n\t\t};\n\t\tlet child = await this.header(from.id, \"ancestry\");\n\t\tfor (let h = from.height - 1; h >= height; h--) {\n\t\t\tif (isEpoch2Header(child)) return null;\n\t\t\tconst id = hex(child.parentBlockId);\n\t\t\tconst parent = await this.header(id, \"ancestry\", { blockId: id });\n\t\t\tif (Number(parent.chainLength) !== h)\n\t\t\t\tfail({\n\t\t\t\t\tstep: \"ancestry\",\n\t\t\t\t\tcode: \"height-mismatch\",\n\t\t\t\t\tmessage: `parent ${id} claims height ${parent.chainLength}, expected ${h}`,\n\t\t\t\t\tblockId: id,\n\t\t\t\t});\n\t\t\tthis.below.set(h, { id, ancestry });\n\t\t\tchild = parent;\n\t\t}\n\t\treturn this.below.get(height) ?? null;\n\t}\n\n\t/**\n\t * Read the id at `height` from `from`'s state: block `height + 1` wrote it\n\t * to `__MARF_BLOCK_HEIGHT_TO_HASH::<height>`, and the proof must recompute\n\t * `from`'s state root through the header of every trie it crosses.\n\t */\n\tprivate async jump(\n\t\tfrom: { height: number; id: string },\n\t\theight: number,\n\t): Promise<{ id: string; ancestry: Ancestry }> {\n\t\tconst at = { blockId: from.id };\n\t\tconst tip = await this.header(from.id, \"ancestry\", at);\n\t\tconst key = heightToHashKey(height);\n\t\tconst path = marfPath(key);\n\t\tconst answer = await fetchFor(\n\t\t\t\"ancestry\",\n\t\t\t`${key} at ${from.id}`,\n\t\t\t() => this.source.getMarfProof(hex(path), from.id),\n\t\t\tat,\n\t\t);\n\t\tif (!answer)\n\t\t\treturn fail({\n\t\t\t\tstep: \"ancestry\",\n\t\t\t\tcode: \"unavailable\",\n\t\t\t\tmessage: `source has no MARF proof of ${key} at block ${from.height}, ${from.height - height} blocks up; parent links reach ${MAX_WALK}`,\n\t\t\t\t...at,\n\t\t\t});\n\t\t// A block id fills the first 32 bytes of the MARFValue; the tail is zero.\n\t\tconst value = marfProofValue(answer.proof) ?? new Uint8Array();\n\t\tconst proven =\n\t\t\tvalue.length === MARF_VALUE_SIZE &&\n\t\t\tvalue.subarray(32).every((b) => b === 0) &&\n\t\t\t(await this.proveAt(tip, path, value, answer.proof, \"ancestry\", at));\n\t\tif (!proven)\n\t\t\treturn fail({\n\t\t\t\tstep: \"ancestry\",\n\t\t\t\tcode: \"ancestry-proof-invalid\",\n\t\t\t\tmessage: `${key} is not proven in block ${from.height}'s state`,\n\t\t\t\t...at,\n\t\t\t});\n\t\tconst ancestry: Ancestry = {\n\t\t\tfromHeight: from.height,\n\t\t\tfromBlockId: from.id,\n\t\t\tvia: \"marf\",\n\t\t};\n\t\tconst found = { id: hex(value.subarray(0, 32)), ancestry };\n\t\tthis.below.set(height, found);\n\t\treturn found;\n\t}\n\n\t/**\n\t * Below the checkpoint the hash chain already pins the block; still bind\n\t * its burn block when the Bitcoin checkpoint reaches it. The burn height\n\t * here is the source's hint, so a low one only skips this extra check.\n\t */\n\tprivate async bindBurnBelow(\n\t\theader: StacksHeader,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tlet hint: number;\n\t\ttry {\n\t\t\thint = await this.burnHint(header);\n\t\t} catch (err) {\n\t\t\tout.notes.push(`burn block not checked: ${(err as Error).message}`);\n\t\t\treturn;\n\t\t}\n\t\tif (hint < this.chain.checkpointHeight) {\n\t\t\tout.notes.push(\n\t\t\t\t`burn block not checked: its height ${hint} is below the Bitcoin checkpoint ${this.chain.checkpointHeight}`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst burn = await this.bindBurn(header, \"burn\");\n\t\tout.burnHeight = burn.burnHeight;\n\t\tout.bitcoinBlockHash = burn.hash;\n\t}\n\n\t/** Witness against the authenticated header's root, then the named diff and rows. */\n\tprivate async verifyState(\n\t\theader: StacksHeader,\n\t\tid: string,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tconst src = this.source;\n\t\tconst height = Number(header.chainLength);\n\t\tconst witness = await fetchFor(\"witness\", `witness ${id}`, () =>\n\t\t\tsrc.getWitness(id),\n\t\t);\n\t\tconst { getStateWrites, getVmEvents }: Partial<ProofSource> = this.rows\n\t\t\t? src\n\t\t\t: {};\n\t\tconst writes = getStateWrites\n\t\t\t? await fetchFor(\"names\", `state_writes ${height}`, () =>\n\t\t\t\t\tgetStateWrites.call(src, height),\n\t\t\t\t)\n\t\t\t: null;\n\t\tconst rows = getVmEvents\n\t\t\t? await fetchFor(\"rows\", `vm_events ${height}`, () =>\n\t\t\t\t\tgetVmEvents.call(src, height),\n\t\t\t\t)\n\t\t\t: undefined;\n\t\tconst parent = isEpoch2Header(header)\n\t\t\t? epoch2ParentId(witness, header)\n\t\t\t: header.parentBlockId;\n\t\tconst parentId = parent && hex(parent);\n\t\tconst state = await verifyBlockState({\n\t\t\theight,\n\t\t\t// Null only when the witness fails its root check, which fails the block.\n\t\t\tparentBlockId: parent ?? new Uint8Array(32),\n\t\t\tstateRoot: header.stateIndexRoot,\n\t\t\twitness,\n\t\t\twrites,\n\t\t\trows,\n\t\t\tparentLeaves: parentId\n\t\t\t\t? await this.parentLeaves(parentId, out.notes)\n\t\t\t\t: undefined,\n\t\t\tparentHolds: async (leaf) =>\n\t\t\t\tparentId ? this.parentHolds(parentId, leaf) : false,\n\t\t});\n\t\tout.diff = state.diff;\n\t\tif (rows) out.rowsChecked = state.rowsChecked;\n\t\tout.notes.push(...state.notes);\n\t\tout.failures.push(...state.failures);\n\t}\n\n\t/** Header by id, from the cache or the source; it must hash to `id`. */\n\tprivate async header(\n\t\tid: string,\n\t\tstep: VerifyStep,\n\t\textra: Partial<VerifyFailure> = {},\n\t): Promise<StacksHeader> {\n\t\tconst known = this.headers.get(id);\n\t\tif (known) return known;\n\t\tconst header = await this.fetchHeader(id, step, extra);\n\t\tif (hex(blockId(header)) !== id)\n\t\t\tfail({\n\t\t\t\tstep,\n\t\t\t\tcode: \"id-mismatch\",\n\t\t\t\tmessage: `source returned another block for ${id}`,\n\t\t\t\tblockId: id,\n\t\t\t\t...extra,\n\t\t\t});\n\t\tthis.headers.set(id, header);\n\t\treturn header;\n\t}\n\n\t/**\n\t * A Nakamoto block by id, or when the source has none (epoch 2.x blocks are\n\t * not served as Nakamoto blocks) its epoch 2.x header.\n\t */\n\tprivate async fetchHeader(\n\t\tid: string,\n\t\tstep: VerifyStep,\n\t\textra: Partial<VerifyFailure>,\n\t): Promise<StacksHeader> {\n\t\tconst src = this.source;\n\t\tlet raw: Bytes;\n\t\ttry {\n\t\t\traw = await src.getBlock(id);\n\t\t} catch (err) {\n\t\t\tconst reason = `block ${id}: ${(err as Error).message}`;\n\t\t\tconst { getEpoch2Header } = src;\n\t\t\tif (!getEpoch2Header)\n\t\t\t\treturn fail({ step, code: \"unavailable\", message: reason, ...extra });\n\t\t\tconst e2 = await fetchFor(\n\t\t\t\tstep,\n\t\t\t\t`${reason}; epoch 2.x header`,\n\t\t\t\t() => getEpoch2Header.call(src, id),\n\t\t\t\textra,\n\t\t\t);\n\t\t\ttry {\n\t\t\t\treturn parseEpoch2Header(e2.header, e2.consensusHash);\n\t\t\t} catch (parseErr) {\n\t\t\t\treturn fail({\n\t\t\t\t\tstep,\n\t\t\t\t\tcode: \"invalid-header\",\n\t\t\t\t\tmessage: `epoch 2.x header ${id} does not parse: ${(parseErr as Error).message}`,\n\t\t\t\t\t...extra,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn parseHeader(raw, step);\n\t}\n\n\t/**\n\t * Prove `value` at `path` in `tip`'s state, fetching the header of every\n\t * ancestor trie the proof crosses.\n\t */\n\tprivate async proveAt(\n\t\ttip: StacksHeader,\n\t\tpath: Bytes,\n\t\tvalue: Bytes,\n\t\tproof: Bytes,\n\t\tstep: VerifyStep,\n\t\textra: Partial<VerifyFailure> = {},\n\t): Promise<boolean> {\n\t\tconst headers = [tip];\n\t\tfor (const id of marfProofAncestors(proof))\n\t\t\theaders.push(await this.header(id, step, extra));\n\t\treturn verifyMarfProof({\n\t\t\tproof,\n\t\t\tpath,\n\t\t\tvalue,\n\t\t\troot: tip.stateIndexRoot,\n\t\t\theaders,\n\t\t});\n\t}\n\n\t/**\n\t * The parent's own trie leaves, from its witness checked against the\n\t * parent header. Optional evidence: when the source cannot serve it,\n\t * carried leaves fall back to per-leaf proofs (named) or stay unlabeled.\n\t */\n\tprivate async parentLeaves(\n\t\tparentId: string,\n\t\tnotes: string[],\n\t): Promise<WitnessLeaf[] | undefined> {\n\t\ttry {\n\t\t\tconst parent = await this.header(parentId, \"names\");\n\t\t\tconst w = parseWitness(await this.source.getWitness(parentId));\n\t\t\tif (bytesEqual(w.root, parent.stateIndexRoot)) return w.leaves;\n\t\t\tnotes.push(`parent witness ${parentId} root does not match its header`);\n\t\t} catch (err) {\n\t\t\tnotes.push(\n\t\t\t\t`parent witness ${parentId} unavailable: ${(err as Error).message}`,\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * A carried leaf holds the parent's value. The parent header is\n\t * authenticated by hash: its id is committed in the authenticated child\n\t * (its header, or for 2.x its own trie).\n\t */\n\tprivate async parentHolds(\n\t\tparentId: string,\n\t\tleaf: WitnessLeaf,\n\t): Promise<boolean> {\n\t\tconst parent = await this.header(parentId, \"names\");\n\t\tconst pathHex = hex(leaf.path);\n\t\tconst answer = await fetchFor(\"names\", `MARF ${pathHex} at parent`, () =>\n\t\t\tthis.source.getMarfProof(pathHex, parentId),\n\t\t);\n\t\tif (!answer) return false;\n\t\tconst value = new Uint8Array(MARF_VALUE_SIZE);\n\t\tvalue.set(leaf.valueHash);\n\t\treturn this.proveAt(parent, leaf.path, value, answer.proof, \"names\");\n\t}\n\n\t/** Consensus hash -> PoW-verified burn block, via the sortition preimage. */\n\tprivate async bindBurn(\n\t\theader: StacksHeader,\n\t\tstep: VerifyStep,\n\t\textra: Partial<VerifyFailure> = {},\n\t): Promise<{ burnHeight: number; hash: string }> {\n\t\tconst ch = hex(header.consensusHash);\n\t\tconst known = this.burns.get(ch);\n\t\tif (known) return known;\n\t\tconst bp = await fetchFor(\n\t\t\tstep,\n\t\t\t`burn preimage ${ch}`,\n\t\t\t() => this.preimage(ch),\n\t\t\textra,\n\t\t);\n\t\tconst hash = verifyConsensusPreimage(header.consensusHash, bp.preimage);\n\t\tif (!hash)\n\t\t\treturn fail({\n\t\t\t\tstep,\n\t\t\t\tcode: \"preimage-mismatch\",\n\t\t\t\tmessage: `preimage does not hash to consensus hash ${ch}`,\n\t\t\t\t...extra,\n\t\t\t});\n\t\tif (bp.burnHeight < this.chain.checkpointHeight)\n\t\t\tfail({\n\t\t\t\tstep,\n\t\t\t\tcode: \"before-checkpoint\",\n\t\t\t\tmessage: `burn height ${bp.burnHeight} is below the Bitcoin checkpoint ${this.chain.checkpointHeight}`,\n\t\t\t\t...extra,\n\t\t\t});\n\t\tawait this.syncBitcoin(bp.burnHeight);\n\t\tconst burnHeight = this.chain.heightOf(hash);\n\t\tif (burnHeight === undefined)\n\t\t\treturn fail({\n\t\t\t\tstep,\n\t\t\t\tcode: \"burn-not-in-chain\",\n\t\t\t\tmessage: `burn block ${hash} is not in the verified Bitcoin chain (synced ${this.chain.checkpointHeight}..${this.chain.tip.height})`,\n\t\t\t\t...extra,\n\t\t\t});\n\t\tconst bound = { burnHeight, hash };\n\t\tthis.burns.set(ch, bound);\n\t\treturn bound;\n\t}\n\n\t/** Extend the Bitcoin chain to `height`, validating PoW, retarget and MTP. */\n\tprivate async syncBitcoin(height: number): Promise<void> {\n\t\twhile (this.chain.tip.height < height) {\n\t\t\tconst from = this.chain.tip.height + 1;\n\t\t\tconst count = Math.min(BITCOIN_BATCH, height - from + 1);\n\t\t\tconst headers = await fetchFor(\"bitcoin\", `bitcoin headers ${from}`, () =>\n\t\t\t\tthis.source.getBitcoinHeaders(from, count),\n\t\t\t);\n\t\t\tif (headers.length === 0)\n\t\t\t\tfail({\n\t\t\t\t\tstep: \"bitcoin\",\n\t\t\t\t\tcode: \"unavailable\",\n\t\t\t\t\tmessage: `source has no Bitcoin headers from ${from}`,\n\t\t\t\t});\n\t\t\ttry {\n\t\t\t\tthis.chain.append(headers);\n\t\t\t} catch (err) {\n\t\t\t\tif (!(err instanceof HeaderValidationError)) throw err;\n\t\t\t\tfail({ step: \"bitcoin\", code: \"invalid-header\", message: err.message });\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The proven signer set for `cycle`. Walks forward from the checkpoint:\n\t * set c+1 is read from an anchor block in c+1's prepare phase, whose\n\t * header set c signed.\n\t */\n\tprivate async signerSet(\n\t\tcycle: number,\n\t\ttarget: SearchPoint,\n\t): Promise<SignerSet> {\n\t\tconst known = this.sets.get(cycle);\n\t\tif (known) return known;\n\t\tconst first = this.checkpoint.stacks.cycle;\n\t\tif (cycle < first)\n\t\t\tfail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"before-checkpoint\",\n\t\t\t\tmessage: `cycle ${cycle} precedes the checkpoint's cycle ${first}`,\n\t\t\t\tcycle,\n\t\t\t});\n\t\tlet lo = await this.startPoint();\n\t\tfor (let c = first; c < cycle; c++) {\n\t\t\tconst next = this.sets.get(c + 1);\n\t\t\tif (next) {\n\t\t\t\tlo = this.anchors.get(c + 1) ?? lo;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst anchor = await this.locateAnchor(c + 1, lo, target);\n\t\t\tthis.sets.set(c + 1, await this.proveNextSet(c + 1, anchor));\n\t\t\tthis.anchors.set(c + 1, anchor);\n\t\t\tlo = anchor;\n\t\t}\n\t\treturn this.sets.get(cycle) as SignerSet;\n\t}\n\n\t/** The checkpoint block as a search bound; its burn height is a source hint. */\n\tprivate async startPoint(): Promise<SearchPoint> {\n\t\tconst { header } = this.start;\n\t\tconst height = Number(header.chainLength);\n\t\ttry {\n\t\t\treturn { height, burn: await this.burnHint(header) };\n\t\t} catch {\n\t\t\treturn { height };\n\t\t}\n\t}\n\n\tprivate async burnHint(header: StacksHeader): Promise<number> {\n\t\tconst ch = hex(header.consensusHash);\n\t\treturn (\n\t\t\tthis.burns.get(ch)?.burnHeight ?? (await this.preimage(ch)).burnHeight\n\t\t);\n\t}\n\n\tprivate async preimage(ch: string): Promise<BurnPreimage> {\n\t\tlet bp = this.preimages.get(ch);\n\t\tif (!bp) {\n\t\t\tbp = await this.source.getBurnPreimage(ch);\n\t\t\tthis.preimages.set(ch, bp);\n\t\t}\n\t\treturn bp;\n\t}\n\n\tprivate async locateAnchor(\n\t\tcycle: number,\n\t\tlo: SearchPoint,\n\t\thi: SearchPoint,\n\t): Promise<Probe> {\n\t\tconst start = cycleStart(cycle);\n\t\tconst window = [start - MAINNET_PREPARE_LENGTH, start] as const;\n\t\tconst probe = async (h: number): Promise<Probe> => {\n\t\t\tconst raw = await fetchFor(\n\t\t\t\t\"signer-set\",\n\t\t\t\t`block at height ${h}`,\n\t\t\t\t() => this.source.getBlock(h),\n\t\t\t\t{ cycle },\n\t\t\t);\n\t\t\tconst header = parseHeader(raw, \"signer-set\");\n\t\t\tconst id = hex(blockId(header));\n\t\t\tthis.headers.set(id, header);\n\t\t\tconst burn = await fetchFor(\n\t\t\t\t\"signer-set\",\n\t\t\t\t`burn hint for block ${id}`,\n\t\t\t\t() => this.burnHint(header),\n\t\t\t\t{ cycle, blockId: id },\n\t\t\t);\n\t\t\treturn { height: Number(header.chainLength), burn, header, id };\n\t\t};\n\t\tconst anchor = await findAnchor(lo, hi, window, probe);\n\t\tif (!anchor)\n\t\t\treturn fail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"anchor-not-found\",\n\t\t\t\tmessage: `no block with a burn height in ${window[0]}..${window[1] - 1} (cycle ${cycle} prepare phase) between heights ${lo.height} and ${hi.height}`,\n\t\t\t\tcycle,\n\t\t\t});\n\t\treturn anchor;\n\t}\n\n\t/**\n\t * Set `cycle` from `anchor`: the anchor must be bound to a burn block in\n\t * `cycle`'s prepare phase, be signed by the set of the cycle that burn\n\t * height dictates (`cycle - 1`), and hold set `cycle` in its state (MARF\n\t * proof). Adjacent sets overlap enough that one block can clear both, so\n\t * the set is always chosen by proven burn height, never by which passes.\n\t */\n\tprivate async proveNextSet(cycle: number, anchor: Probe): Promise<SignerSet> {\n\t\tconst at = { cycle, blockId: anchor.id };\n\t\tconst { burnHeight } = await this.bindBurn(anchor.header, \"signer-set\", at);\n\t\tconst start = cycleStart(cycle);\n\t\tif (burnHeight < start - MAINNET_PREPARE_LENGTH || burnHeight >= start)\n\t\t\tfail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"anchor-outside-window\",\n\t\t\t\tmessage: `anchor burn height ${burnHeight} is outside cycle ${cycle}'s prepare phase ${start - MAINNET_PREPARE_LENGTH}..${start - 1}`,\n\t\t\t\t...at,\n\t\t\t});\n\t\tconst signing = rewardCycle(burnHeight);\n\t\tconst sig = verifySignerSignatures(\n\t\t\tanchor.header,\n\t\t\tthis.sets.get(signing) as SignerSet,\n\t\t);\n\t\tif (!sig.valid)\n\t\t\tfail({\n\t\t\t\t...signatureFailure(sig, \"signer-set\", signing),\n\t\t\t\t...at,\n\t\t\t\tcode: \"anchor-unsigned\",\n\t\t\t});\n\n\t\tconst path = marfPath(\n\t\t\tmapEntryKey(SIGNERS_CONTRACT, \"cycle-signer-set\", uintCV(cycle)),\n\t\t);\n\t\tconst answer = await fetchFor(\n\t\t\t\"signer-set\",\n\t\t\t`signer set ${cycle} at ${anchor.id}`,\n\t\t\t() => this.source.getMarfProof(hex(path), anchor.id),\n\t\t\tat,\n\t\t);\n\t\tconst value = answer?.data.replace(/^0x/, \"\") ?? \"\";\n\t\tconst proven =\n\t\t\tanswer !== null &&\n\t\t\t(await this.proveAt(\n\t\t\t\tanchor.header,\n\t\t\t\tpath,\n\t\t\t\tmarfValue(value),\n\t\t\t\tanswer.proof,\n\t\t\t\t\"signer-set\",\n\t\t\t\tat,\n\t\t\t));\n\t\tif (!proven)\n\t\t\tfail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"set-proof-invalid\",\n\t\t\t\tmessage: `signer set ${cycle} is not proven in anchor ${anchor.id}'s state`,\n\t\t\t\t...at,\n\t\t\t});\n\t\tlet set: SignerSet;\n\t\ttry {\n\t\t\tset = decodeSignerSet(value);\n\t\t} catch (err) {\n\t\t\treturn fail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"set-proof-invalid\",\n\t\t\t\tmessage: `signer set ${cycle}: ${(err as Error).message}`,\n\t\t\t\t...at,\n\t\t\t});\n\t\t}\n\t\treturn set;\n\t}\n}\n\nfunction parseHeader(raw: Bytes, step: VerifyStep): NakamotoHeader {\n\ttry {\n\t\treturn parseNakamotoHeader(raw);\n\t} catch (err) {\n\t\treturn fail({\n\t\t\tstep,\n\t\t\tcode: \"invalid-header\",\n\t\t\tmessage: `block bytes do not parse: ${(err as Error).message}`,\n\t\t});\n\t}\n}\n\n/**\n * A 2.x header commits only to its parent's block hash; the parent's id is in\n * the block's own trie at `__MARF_BLOCK_HEIGHT_TO_HASH::<height - 1>`. Read\n * from a witness whose root matches the header, else null.\n */\nfunction epoch2ParentId(witness: Bytes, header: Epoch2Header): Bytes | null {\n\tconst height = Number(header.chainLength);\n\tif (height === 0) return null;\n\ttry {\n\t\tconst w = parseWitness(witness);\n\t\tif (!bytesEqual(w.root, header.stateIndexRoot)) return null;\n\t\tconst path = marfPath(heightToHashKey(height - 1));\n\t\treturn w.leaves.find((l) => bytesEqual(l.path, path))?.valueHash ?? null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction signatureFailure(\n\tsig: ReturnType<typeof verifySignerSignatures>,\n\tstep: VerifyStep,\n\tcycle: number,\n): VerifyFailure {\n\tconst weight = `${sig.signedWeight}/${sig.totalWeight} signed, threshold ${sig.threshold}`;\n\tif (sig.unknown.length)\n\t\treturn {\n\t\t\tstep,\n\t\t\tcode: \"unknown-signer\",\n\t\t\tmessage: `${sig.unknown.length} signer(s) not in cycle ${cycle}'s set (${weight})`,\n\t\t\tcycle,\n\t\t};\n\tif (sig.duplicates.length)\n\t\treturn {\n\t\t\tstep,\n\t\t\tcode: \"duplicate-signer\",\n\t\t\tmessage: `${sig.duplicates.length} duplicate signature(s) (${weight})`,\n\t\t\tcycle,\n\t\t};\n\tif (sig.invalid)\n\t\treturn {\n\t\t\tstep,\n\t\t\tcode: \"bad-signature\",\n\t\t\tmessage: `${sig.invalid} signature(s) do not recover (${weight})`,\n\t\t\tcycle,\n\t\t};\n\treturn {\n\t\tstep,\n\t\tcode: \"below-threshold\",\n\t\tmessage: `cycle ${cycle} signers: ${weight}`,\n\t\tcycle,\n\t};\n}\n\n/** One-shot: verify a block from a checkpoint (MAINNET_CHECKPOINT by default). */\nexport const verifyBlock = (\n\tref: string | number,\n\topts: VerifyOptions,\n): Promise<BlockVerification> => new BlockVerifier(opts).verify(ref);\n"
|
|
16
|
+
"// Proof data sources. Everything a source returns is untrusted: verifyBlock\n// checks every byte against the checkpoint, so a lying source can make a\n// check fail but never pass.\nimport { type Bytes, unhex } from \"./bytes.ts\";\n\n/** Sortition preimage behind a consensus hash. */\nexport interface BurnPreimage {\n\tpreimage: Bytes;\n\t/** The source's claimed burn height: a hint for how far to sync Bitcoin headers, never trusted. */\n\tburnHeight: number;\n}\n\n/** Node RPC `/v2/clarity/marf/<path>?proof=1` answer. */\nexport interface MarfProofResponse {\n\t/** Value string as Clarity stored it (hex for Clarity values), 0x prefix tolerated. */\n\tdata: string;\n\t/** Consensus-serialized TrieMerkleProof. */\n\tproof: Bytes;\n}\n\n/** One storage-layer MARF write (`state_writes` row), in block write order. */\nexport interface StateWrite {\n\t/** Null for block-level writes outside any transaction. */\n\ttx_index: number | null;\n\tordinal: number;\n\t/** Full MARF key, e.g. `vm::<contract>::0::<map>::<key hex>`. */\n\tkey: string;\n\t/** Hex of the stored value string's UTF-8 bytes. */\n\tvalue_hex: string;\n}\n\n/** A `vm_events` write row, as the Index API serves it. */\nexport interface VmEventRow {\n\tevent_type: \"var_set\" | \"map_set\" | \"map_insert\" | \"map_delete\";\n\t/** The row's ordinal within the block. */\n\tevent_index: number;\n\ttx_id?: string;\n\ttx_index?: number;\n\tcontract_id: string;\n\tvar_name?: string | null;\n\tmap?: string | null;\n\traw_key?: string | null;\n\traw_value?: string | null;\n}\n\n/** An epoch 2.x header and the consensus hash its index block hash commits to. */\nexport interface Epoch2HeaderResponse {\n\t/** Consensus-serialized StacksBlockHeader. */\n\theader: Bytes;\n\tconsensusHash: Bytes;\n}\n\nexport interface ProofSource {\n\t/** Raw Nakamoto block bytes (header first), by block id or height. */\n\tgetBlock(ref: string | number): Promise<Bytes>;\n\t/**\n\t * Epoch 2.x block header by index block hash: blocks below the checkpoint\n\t * from before Nakamoto. Without it only Nakamoto blocks verify.\n\t */\n\tgetEpoch2Header?(blockId: string): Promise<Epoch2HeaderResponse>;\n\t/**\n\t * MARF inclusion proof for a 32-byte path at `tipId`; null when the key is\n\t * absent. Blocks below the checkpoint also ask for\n\t * `__MARF_BLOCK_HEIGHT_TO_HASH::<height>`, whose value is no stored string:\n\t * only `proof` is read for it.\n\t */\n\tgetMarfProof(\n\t\tpathHex: string,\n\t\ttipId: string,\n\t): Promise<MarfProofResponse | null>;\n\t/** State witness (wire v3) for a block. */\n\tgetWitness(blockId: string): Promise<Bytes>;\n\tgetBurnPreimage(consensusHash: string): Promise<BurnPreimage>;\n\t/** Raw 80-byte Bitcoin headers (hex or bytes) from height `from`. */\n\tgetBitcoinHeaders(from: number, count: number): Promise<(string | Bytes)[]>;\n\t/**\n\t * Every MARF write of the block, in ordinal order; null (or empty) when\n\t * the source has none for it. Names the block's diff.\n\t */\n\tgetStateWrites?(height: number): Promise<StateWrite[] | null>;\n\t/** Indexed vm_events write rows of the block, checked against its proven diff. */\n\tgetVmEvents?(height: number): Promise<VmEventRow[]>;\n}\n\nexport class SourceError extends Error {\n\toverride readonly name = \"SourceError\";\n\tconstructor(\n\t\treadonly url: string,\n\t\treadonly status: number | null,\n\t\tdetail: string,\n\t) {\n\t\tsuper(`${url}: ${detail}`);\n\t}\n}\n\ntype Fetch = (url: string, init?: RequestInit) => Promise<Response>;\n\ninterface HttpOptions {\n\theaders?: Record<string, string>;\n\tfetch?: Fetch;\n}\n\nconst MAX_ATTEMPTS = 3;\nconst MAX_RETRY_SECONDS = 10;\n\n/** GET with retries on 429 and 503 (honoring retry-after); null on 404. */\nasync function get(\n\turl: string,\n\topts: HttpOptions,\n\tattempt = 1,\n): Promise<Response | null> {\n\tconst doFetch = opts.fetch ?? fetch;\n\tlet res: Response;\n\ttry {\n\t\tres = await doFetch(url, { headers: opts.headers });\n\t} catch (err) {\n\t\tthrow new SourceError(url, null, (err as Error).message);\n\t}\n\tif (res.status === 404) return null;\n\tif ((res.status === 503 || res.status === 429) && attempt < MAX_ATTEMPTS) {\n\t\tconst header = res.headers.get(\"retry-after\");\n\t\tconst seconds = header === null ? 1 : Number(header);\n\t\tconst wait = Number.isFinite(seconds)\n\t\t\t? Math.min(Math.max(seconds, 0), MAX_RETRY_SECONDS)\n\t\t\t: 1;\n\t\tawait new Promise((r) => setTimeout(r, wait * 1000));\n\t\treturn get(url, opts, attempt + 1);\n\t}\n\tif (!res.ok) throw new SourceError(url, res.status, `HTTP ${res.status}`);\n\treturn res;\n}\n\nasync function getJson<T>(url: string, opts: HttpOptions): Promise<T | null> {\n\tconst res = await get(url, opts);\n\treturn res ? ((await res.json()) as T) : null;\n}\n\nasync function getBytes(url: string, opts: HttpOptions): Promise<Bytes | null> {\n\tconst res = await get(url, opts);\n\treturn res ? new Uint8Array(await res.arrayBuffer()) : null;\n}\n\nconst required = <T>(url: string, v: T | null): T => {\n\tif (v === null) throw new SourceError(url, 404, \"not found\");\n\treturn v;\n};\n\nconst trimSlash = (s: string) => s.replace(/\\/+$/, \"\");\n\ntype MarfJson = { data: string; proof?: string; marf_proof?: string };\n\ntype HeadersJson = { header?: unknown; consensus_hash?: unknown }[];\n\n/** The first entry of a node `/v2/headers/1?tip=<id>` answer: the tip itself. */\nconst toEpoch2 = (url: string, j: HeadersJson | null): Epoch2HeaderResponse => {\n\tconst tip = required(url, j)[0];\n\tif (typeof tip?.header !== \"string\" || typeof tip.consensus_hash !== \"string\")\n\t\tthrow new SourceError(url, 200, \"answer needs header and consensus_hash\");\n\treturn {\n\t\theader: unhex(tip.header),\n\t\tconsensusHash: unhex(tip.consensus_hash),\n\t};\n};\n\nconst toMarf = (url: string, j: MarfJson | null): MarfProofResponse | null => {\n\tif (j === null) return null;\n\tconst proof = j.proof ?? j.marf_proof;\n\tif (typeof proof !== \"string\" || typeof j.data !== \"string\")\n\t\tthrow new SourceError(url, 200, \"MARF answer needs data and proof\");\n\treturn { data: j.data, proof: unhex(proof) };\n};\n\n/** The hosted API. */\nexport const DEFAULT_API_URL = \"https://api.secondlayer.tools\";\n\nexport interface SecondlayerSourceOptions {\n\t/** API origin. Defaults to {@link DEFAULT_API_URL}. */\n\tbaseUrl?: string;\n\t/**\n\t * Optional. Proofs are keyless; a key raises the rate limit. Required for\n\t * `rows: true` (metered Index reads). Sent as `Authorization: Bearer`.\n\t */\n\tapiKey?: string;\n\tfetch?: Fetch;\n}\n\nconst VM_WRITE_TYPES = [\n\t\"var_set\",\n\t\"map_set\",\n\t\"map_insert\",\n\t\"map_delete\",\n] as const;\nconst PAGE = 1000;\n\n/** Follow `next_cursor` until a page comes back empty. Null when the first page 404s. */\nasync function pages<T>(\n\tfield: string,\n\turl: string,\n\thttp: HttpOptions,\n): Promise<T[] | null> {\n\tconst out: T[] = [];\n\tlet cursor: string | null = null;\n\tfor (;;) {\n\t\tconst page: string = cursor\n\t\t\t? `${url}&cursor=${encodeURIComponent(cursor)}`\n\t\t\t: url;\n\t\tconst j = await getJson<Record<string, unknown>>(page, http);\n\t\tif (j === null) return cursor === null ? null : out;\n\t\tconst rows = j[field];\n\t\tif (!Array.isArray(rows))\n\t\t\tthrow new SourceError(page, 200, `answer has no ${field} array`);\n\t\tout.push(...(rows as T[]));\n\t\tconst next = j.next_cursor;\n\t\tif (rows.length < PAGE || typeof next !== \"string\" || next === cursor)\n\t\t\treturn out;\n\t\tcursor = next;\n\t}\n}\n\n// Both sources keep their origin and account key in constructor closures, not\n// fields: nothing leaks through a spread, a log or JSON.stringify.\n\n/**\n * Every proof input from the Secondlayer API: `/v1/proofs/*` (free, rate\n * limited) for blocks, epoch 2.x headers, MARF proofs, witnesses, burn\n * preimages, Bitcoin headers and each block's state writes; the Index API\n * (metered rows) for vm_events, read only when verifyBlock gets `rows: true`.\n * Methods are own properties, so a partial source spreads over it:\n * `{ ...new SecondlayerProofSource(o), ...new NodeRpcProofSource(n) }`.\n */\nexport class SecondlayerProofSource implements ProofSource {\n\tgetBlock: (ref: string | number) => Promise<Bytes>;\n\tgetEpoch2Header: (blockId: string) => Promise<Epoch2HeaderResponse>;\n\tgetMarfProof: (\n\t\tpathHex: string,\n\t\ttipId: string,\n\t) => Promise<MarfProofResponse | null>;\n\tgetWitness: (blockId: string) => Promise<Bytes>;\n\tgetBurnPreimage: (consensusHash: string) => Promise<BurnPreimage>;\n\tgetBitcoinHeaders: (from: number, count: number) => Promise<string[]>;\n\tgetStateWrites: (height: number) => Promise<StateWrite[] | null>;\n\tgetVmEvents: (height: number) => Promise<VmEventRow[]>;\n\n\tconstructor(opts: SecondlayerSourceOptions = {}) {\n\t\tconst base = trimSlash(opts.baseUrl ?? DEFAULT_API_URL);\n\t\tconst http: HttpOptions = {\n\t\t\theaders: opts.apiKey ? { authorization: `Bearer ${opts.apiKey}` } : {},\n\t\t\tfetch: opts.fetch,\n\t\t};\n\n\t\tthis.getBlock = async (ref) => {\n\t\t\tconst url =\n\t\t\t\ttypeof ref === \"number\"\n\t\t\t\t\t? `${base}/v1/proofs/block/height/${ref}`\n\t\t\t\t\t: `${base}/v1/proofs/block/${ref}`;\n\t\t\treturn required(url, await getBytes(url, http));\n\t\t};\n\n\t\tthis.getEpoch2Header = async (blockId) => {\n\t\t\tconst url = `${base}/v1/proofs/epoch2-header/${blockId}`;\n\t\t\treturn toEpoch2(url, await getJson<HeadersJson>(url, http));\n\t\t};\n\n\t\tthis.getMarfProof = async (pathHex, tipId) => {\n\t\t\tconst url = `${base}/v1/proofs/marf/${pathHex}?tip=${tipId}`;\n\t\t\treturn toMarf(url, await getJson<MarfJson>(url, http));\n\t\t};\n\n\t\tthis.getWitness = async (blockId) => {\n\t\t\tconst url = `${base}/v1/proofs/witness/${blockId}`;\n\t\t\treturn required(url, await getBytes(url, http));\n\t\t};\n\n\t\tthis.getBurnPreimage = async (consensusHash) => {\n\t\t\tconst url = `${base}/v1/proofs/burn/${consensusHash}`;\n\t\t\tconst j = required(\n\t\t\t\turl,\n\t\t\t\tawait getJson<{ burn_height: number; preimage: string }>(url, http),\n\t\t\t);\n\t\t\treturn { preimage: unhex(j.preimage), burnHeight: j.burn_height };\n\t\t};\n\n\t\tthis.getBitcoinHeaders = async (from, count) => {\n\t\t\tconst url = `${base}/v1/proofs/bitcoin-headers?from=${from}&count=${count}`;\n\t\t\tconst j = required(\n\t\t\t\turl,\n\t\t\t\tawait getJson<{ from: number; headers: string[] }>(url, http),\n\t\t\t);\n\t\t\tif (j.from !== from)\n\t\t\t\tthrow new SourceError(url, 200, `headers start at ${j.from}`);\n\t\t\treturn j.headers;\n\t\t};\n\n\t\tthis.getStateWrites = async (height) => {\n\t\t\tconst url = `${base}/v1/proofs/writes/${height}`;\n\t\t\tconst j = await getJson<{ state_writes?: unknown }>(url, http);\n\t\t\tif (j === null) return null;\n\t\t\tif (!Array.isArray(j.state_writes))\n\t\t\t\tthrow new SourceError(url, 200, \"answer has no state_writes array\");\n\t\t\treturn j.state_writes as StateWrite[];\n\t\t};\n\n\t\tthis.getVmEvents = async (height) => {\n\t\t\tconst eventsUrl = (type: string) =>\n\t\t\t\t`${base}/v1/index/events?event_type=${type}&from_height=${height}&to_height=${height}&limit=${PAGE}`;\n\t\t\tif (!opts.apiKey)\n\t\t\t\tthrow new SourceError(\n\t\t\t\t\teventsUrl(VM_WRITE_TYPES[0]),\n\t\t\t\t\t401,\n\t\t\t\t\t\"rows: true reads metered Index events and needs an apiKey\",\n\t\t\t\t);\n\t\t\tconst out: VmEventRow[] = [];\n\t\t\tfor (const type of VM_WRITE_TYPES) {\n\t\t\t\tconst url = eventsUrl(type);\n\t\t\t\tout.push(...((await pages<VmEventRow>(\"events\", url, http)) ?? []));\n\t\t\t}\n\t\t\treturn out.sort((a, b) => a.event_index - b.event_index);\n\t\t};\n\t}\n}\n\nexport interface NodeRpcSourceOptions {\n\t/** Stacks node RPC origin, e.g. `http://localhost:20443`. */\n\tnodeUrl: string;\n\tfetch?: Fetch;\n}\n\n/**\n * Blocks, epoch 2.x headers and MARF proofs straight from a Stacks node's RPC.\n * Witnesses, burn preimages and Bitcoin headers need another source: spread\n * this over one.\n */\nexport class NodeRpcProofSource\n\timplements Pick<ProofSource, \"getBlock\" | \"getEpoch2Header\" | \"getMarfProof\">\n{\n\tgetBlock: (ref: string | number) => Promise<Bytes>;\n\tgetEpoch2Header: (blockId: string) => Promise<Epoch2HeaderResponse>;\n\tgetMarfProof: (\n\t\tpathHex: string,\n\t\ttipId: string,\n\t) => Promise<MarfProofResponse | null>;\n\n\tconstructor(opts: NodeRpcSourceOptions) {\n\t\tconst base = trimSlash(opts.nodeUrl);\n\t\tconst http: HttpOptions = { fetch: opts.fetch };\n\n\t\tthis.getBlock = async (ref) => {\n\t\t\tconst url =\n\t\t\t\ttypeof ref === \"number\"\n\t\t\t\t\t? `${base}/v3/blocks/height/${ref}`\n\t\t\t\t\t: `${base}/v3/blocks/${ref}`;\n\t\t\treturn required(url, await getBytes(url, http));\n\t\t};\n\n\t\tthis.getEpoch2Header = async (blockId) => {\n\t\t\tconst url = `${base}/v2/headers/1?tip=${blockId}`;\n\t\t\treturn toEpoch2(url, await getJson<HeadersJson>(url, http));\n\t\t};\n\n\t\tthis.getMarfProof = async (pathHex, tipId) => {\n\t\t\tconst url = `${base}/v2/clarity/marf/${pathHex}?tip=${tipId}&proof=1`;\n\t\t\treturn toMarf(url, await getJson<MarfJson>(url, http));\n\t\t};\n\t}\n}\n",
|
|
17
|
+
"// Steps 6-8 of verifyBlock: a block's state witness against its authenticated\n// header root, every leaf of its trie named, and indexed rows against the diff.\nimport { type Bytes, bytesEqual, hex, unhex } from \"./bytes.ts\";\nimport { dataVarKey } from \"./keys.ts\";\nimport {\n\tMARF_VALUE_SIZE,\n\theightToHashKey,\n\tmarfPath,\n\tmarfValue,\n} from \"./marf.ts\";\nimport type { StateWrite, VmEventRow } from \"./source.ts\";\nimport {\n\ttype WitnessLeaf,\n\tclassifyBlockDiff,\n\tparseWitness,\n} from \"./witness.ts\";\n\nexport interface DiffWrite {\n\t/** MARF key, when a state_writes row names the leaf. */\n\tkey?: string;\n\t/** Leaf path, hex. */\n\tpath: string;\n\t/** sha512/256 of the stored value string, hex. */\n\tvalueHash: string;\n\t/** Transaction of the last write; null for block-level writes. */\n\ttxIndex?: number | null;\n\t/** The stored value string (hex of a Clarity value) the leaf holds; named writes only. */\n\tvalue?: string;\n\t/** False when the source had no state_writes: the leaf may also be a carried copy. */\n\tnamed: boolean;\n}\n\nexport interface DiffLeaf {\n\tkey?: string;\n\tpath: string;\n\tvalueHash: string;\n}\n\nexport interface ProvenDiff {\n\t/** Every leaf is named (state_writes served) and classified. */\n\tnamed: boolean;\n\twrites: DiffWrite[];\n\t/** Unchanged values copied forward from the parent (proven at the parent). */\n\tcarried: DiffLeaf[];\n\t/** `__MARF_BLOCK_*` bookkeeping. */\n\tinternal: DiffLeaf[];\n}\n\nexport type StateFailureCode =\n\t| \"malformed\"\n\t| \"root-mismatch\"\n\t| \"bad-write\"\n\t| \"hidden-write\"\n\t| \"missing-write\"\n\t| \"key-not-written\"\n\t| \"value-mismatch\"\n\t| \"bad-row\";\n\nexport interface StateFailure {\n\tstep: \"witness\" | \"names\" | \"rows\";\n\tcode: StateFailureCode;\n\tmessage: string;\n\tkey?: string;\n\tpath?: string;\n\tordinal?: number;\n}\n\nexport interface BlockStateInput {\n\t/** MARF height of the block (its Stacks chain length). */\n\theight: number;\n\t/** Parent block id from the authenticated header. */\n\tparentBlockId: Bytes;\n\t/** state_index_root from the authenticated header. */\n\tstateRoot: Bytes;\n\twitness: Bytes;\n\t/** The block's state_writes; null when the source has none (names unavailable). */\n\twrites: StateWrite[] | null;\n\t/** Indexed rows to prove against the diff. */\n\trows?: VmEventRow[];\n\t/**\n\t * Leaves of the parent's own trie, from a parent witness whose root the\n\t * caller checked against the parent header: each is the parent state's\n\t * value at its path. Resolves carried leaves without a proof per leaf.\n\t */\n\tparentLeaves?: WitnessLeaf[];\n\t/**\n\t * True iff the leaf's value is stored at its path in the parent's state\n\t * (proven by the caller). Asked only with state_writes, for leaves the\n\t * parent's own trie does not explain.\n\t */\n\tparentHolds?: (leaf: WitnessLeaf) => Promise<boolean>;\n}\n\nexport interface BlockStateResult {\n\tdiff?: ProvenDiff;\n\trowsChecked: number;\n\tnotes: string[];\n\tfailures: StateFailure[];\n}\n\nconst INTERNAL = {\n\tself: \"__MARF_BLOCK_HEIGHT_SELF\",\n\thashToHeight: \"__MARF_BLOCK_HASH_TO_HEIGHT\",\n} as const;\n\n/** MARFValue of a u32 height: little-endian in the first 4 bytes. */\nconst heightValue = (h: number): string => {\n\tconst v = new Uint8Array(MARF_VALUE_SIZE);\n\tnew DataView(v.buffer).setUint32(0, h, true);\n\treturn hex(v);\n};\n/** 40-byte MARFValue hex of a 32-byte hash or block id (zero tail). */\nconst padded = (b32: Bytes): string => `${hex(b32)}${\"00\".repeat(8)}`;\n\n/**\n * The `__MARF_BLOCK_*` entries block `height` writes (stacks-core index/marf.rs).\n * The parent's are fixed by the header. The block's own id is not known while\n * its trie is built, so `HEIGHT_TO_HASH::{height}` holds a temporary hash; its\n * value is taken from the witness and must map back to `height`.\n */\nfunction internalEntries(\n\theight: number,\n\tparentBlockId: Bytes,\n\tleaves: WitnessLeaf[],\n): [key: string, valueHex: string][] {\n\tconst out: [string, string][] = [[INTERNAL.self, heightValue(height)]];\n\tconst ownKey = heightToHashKey(height);\n\tconst ownPath = marfPath(ownKey);\n\tconst own = leaves.find((l) => bytesEqual(l.path, ownPath));\n\tif (own) {\n\t\tout.push([ownKey, padded(own.valueHash)]);\n\t\tout.push([\n\t\t\t`${INTERNAL.hashToHeight}::${hex(own.valueHash)}`,\n\t\t\theightValue(height),\n\t\t]);\n\t}\n\tif (height > 0) {\n\t\tout.push([heightToHashKey(height - 1), padded(parentBlockId)]);\n\t\tout.push([\n\t\t\t`${INTERNAL.hashToHeight}::${hex(parentBlockId)}`,\n\t\t\theightValue(height - 1),\n\t\t]);\n\t}\n\treturn out;\n}\n\nconst utf8 = new TextDecoder(\"utf-8\", { fatal: true });\nconst strip0x = (s: string) => (s.startsWith(\"0x\") ? s.slice(2) : s);\nconst leafHex = (l: WitnessLeaf): DiffLeaf => ({\n\tpath: hex(l.path),\n\tvalueHash: hex(l.valueHash),\n});\n\n/** Last write per key, in ordinal order, with its value as the stored string. */\nfunction lastWrites(\n\twrites: StateWrite[],\n\tfailures: StateFailure[],\n): Map<string, { value: string; txIndex: number | null }> {\n\tconst out = new Map<string, { value: string; txIndex: number | null }>();\n\tfor (const w of [...writes].sort((a, b) => a.ordinal - b.ordinal)) {\n\t\ttry {\n\t\t\tout.set(w.key, {\n\t\t\t\tvalue: utf8.decode(unhex(strip0x(w.value_hex))),\n\t\t\t\ttxIndex: w.tx_index,\n\t\t\t});\n\t\t} catch {\n\t\t\tfailures.push({\n\t\t\t\tstep: \"names\",\n\t\t\t\tcode: \"bad-write\",\n\t\t\t\tmessage: `state write ${w.ordinal} value is not UTF-8 hex`,\n\t\t\t\tkey: w.key,\n\t\t\t\tordinal: w.ordinal,\n\t\t\t});\n\t\t}\n\t}\n\treturn out;\n}\n\n/** The MARF key and stored value string a vm_events row writes (mirrors clarity_db.rs). */\nfunction rowWrite(row: VmEventRow): [key: string, value: string] {\n\tconst need = (v: string | null | undefined, name: string): string => {\n\t\tif (!v) throw new Error(`${row.event_type} row has no ${name}`);\n\t\treturn v;\n\t};\n\tif (row.event_type === \"var_set\")\n\t\treturn [\n\t\t\tdataVarKey(row.contract_id, need(row.var_name, \"var_name\")),\n\t\t\tstrip0x(need(row.raw_value, \"raw_value\")).toLowerCase(),\n\t\t];\n\tconst key = `vm::${row.contract_id}::0::${need(row.map, \"map\")}::${strip0x(need(row.raw_key, \"raw_key\")).toLowerCase()}`;\n\tif (row.event_type === \"map_delete\") return [key, \"09\"];\n\t// put_value stores map entries as (some value).\n\treturn [key, `0a${strip0x(need(row.raw_value, \"raw_value\")).toLowerCase()}`];\n}\n\n/**\n * Rows against the block's leaves: every row's key must be a leaf, and the\n * last row per key must carry the leaf's value.\n */\nfunction checkRows(\n\trows: VmEventRow[],\n\tleaves: WitnessLeaf[],\n\tfailures: StateFailure[],\n): number {\n\tconst byPath = new Map(leaves.map((l) => [hex(l.path), l]));\n\tconst named: { row: VmEventRow; key: string; path: string; value: string }[] =\n\t\t[];\n\tfor (const row of [...rows].sort((a, b) => a.event_index - b.event_index)) {\n\t\ttry {\n\t\t\tconst [key, value] = rowWrite(row);\n\t\t\tnamed.push({ row, key, path: hex(marfPath(key)), value });\n\t\t} catch (err) {\n\t\t\tfailures.push({\n\t\t\t\tstep: \"rows\",\n\t\t\t\tcode: \"bad-row\",\n\t\t\t\tmessage: (err as Error).message,\n\t\t\t\tordinal: row.event_index,\n\t\t\t});\n\t\t}\n\t}\n\tconst last = new Map(named.map((n, i) => [n.path, i]));\n\tnamed.forEach((n, i) => {\n\t\tconst leaf = byPath.get(n.path);\n\t\tconst at = { key: n.key, path: n.path, ordinal: n.row.event_index };\n\t\tif (!leaf)\n\t\t\tfailures.push({\n\t\t\t\tstep: \"rows\",\n\t\t\t\tcode: \"key-not-written\",\n\t\t\t\tmessage: `${n.row.event_type} row ${n.row.event_index} names a key the block did not write`,\n\t\t\t\t...at,\n\t\t\t});\n\t\telse if (\n\t\t\tlast.get(n.path) === i &&\n\t\t\tpadded(leaf.valueHash) !== hex(marfValue(n.value))\n\t\t)\n\t\t\tfailures.push({\n\t\t\t\tstep: \"rows\",\n\t\t\t\tcode: \"value-mismatch\",\n\t\t\t\tmessage: `${n.row.event_type} row ${n.row.event_index} value differs from the block's leaf`,\n\t\t\t\t...at,\n\t\t\t});\n\t});\n\treturn named.length;\n}\n\n/**\n * Verify block state against an authenticated header: the witness must\n * recompute `stateRoot`, then every leaf is classified. With state_writes,\n * any leaf that is not a named write, a carried parent value or MARF\n * bookkeeping is a hidden write. Without them the diff is still proven\n * (every leaf is in the block): carried leaves are told apart only through\n * `parentLeaves`, and the remaining writes come back unnamed.\n */\nexport async function verifyBlockState(\n\tinput: BlockStateInput,\n): Promise<BlockStateResult> {\n\tconst out: BlockStateResult = { rowsChecked: 0, notes: [], failures: [] };\n\tlet witness: ReturnType<typeof parseWitness>;\n\ttry {\n\t\twitness = parseWitness(input.witness);\n\t} catch (err) {\n\t\tout.failures.push({\n\t\t\tstep: \"witness\",\n\t\t\tcode: \"malformed\",\n\t\t\tmessage: (err as Error).message,\n\t\t});\n\t\treturn out;\n\t}\n\tif (!bytesEqual(witness.root, input.stateRoot)) {\n\t\tout.failures.push({\n\t\t\tstep: \"witness\",\n\t\t\tcode: \"root-mismatch\",\n\t\t\tmessage: `witness root ${hex(witness.root)} != header state_index_root ${hex(input.stateRoot)}`,\n\t\t});\n\t\treturn out;\n\t}\n\tconst { leaves } = witness;\n\tconst internal = internalEntries(input.height, input.parentBlockId, leaves);\n\tconst named = input.writes !== null;\n\tconst last = lastWrites(input.writes ?? [], out.failures);\n\tconst writes = [...last].map(([k, w]): [string, string] => [k, w.value]);\n\t// First pass with no parent values finds the leaves that need one.\n\tconst first = classifyBlockDiff({\n\t\tleaves,\n\t\twrites,\n\t\tinternal,\n\t\tparentValue: () => undefined,\n\t});\n\tconst inParent = new Map(\n\t\t(input.parentLeaves ?? []).map((l) => [hex(l.path), hex(l.valueHash)]),\n\t);\n\tconst carried = new Map<string, string>();\n\tfor (const leaf of first.hidden) {\n\t\tconst pathHex = hex(leaf.path);\n\t\tif (\n\t\t\tinParent.get(pathHex) === hex(leaf.valueHash) ||\n\t\t\t(named && (await input.parentHolds?.(leaf)))\n\t\t)\n\t\t\tcarried.set(pathHex, padded(leaf.valueHash));\n\t}\n\tconst d = classifyBlockDiff({\n\t\tleaves,\n\t\twrites,\n\t\tinternal,\n\t\tparentValue: (p) => carried.get(p),\n\t});\n\tout.diff = {\n\t\tnamed,\n\t\twrites: named\n\t\t\t? d.writes.map((l) => ({\n\t\t\t\t\t...leafHex(l),\n\t\t\t\t\tkey: l.key,\n\t\t\t\t\ttxIndex: last.get(l.key)?.txIndex ?? null,\n\t\t\t\t\tvalue: last.get(l.key)?.value,\n\t\t\t\t\tnamed: true,\n\t\t\t\t}))\n\t\t\t: // Without names every unexplained leaf is a write we cannot label.\n\t\t\t\td.hidden.map((l) => ({ ...leafHex(l), named: false })),\n\t\tcarried: d.carried.map(leafHex),\n\t\tinternal: d.internal.map((l) => ({ ...leafHex(l), key: l.key })),\n\t};\n\tif (!named)\n\t\tout.notes.push(\n\t\t\t`source has no state_writes for block ${input.height}: ${d.hidden.length} written leaves are proven in the block but unnamed`,\n\t\t);\n\telse {\n\t\tfor (const l of d.hidden)\n\t\t\tout.failures.push({\n\t\t\t\tstep: \"names\",\n\t\t\t\tcode: \"hidden-write\",\n\t\t\t\tmessage: `leaf ${hex(l.path)} is not a named write, a carried parent value or MARF bookkeeping`,\n\t\t\t\tpath: hex(l.path),\n\t\t\t});\n\t\tfor (const key of d.missing)\n\t\t\tout.failures.push({\n\t\t\t\tstep: \"names\",\n\t\t\t\tcode: \"missing-write\",\n\t\t\t\tmessage: `state write ${key} has no leaf holding its value`,\n\t\t\t\tkey,\n\t\t\t\tpath: hex(marfPath(key)),\n\t\t\t});\n\t}\n\tif (input.rows) out.rowsChecked = checkRows(input.rows, leaves, out.failures);\n\treturn out;\n}\n",
|
|
18
|
+
"// A Nakamoto block's transactions against its header's tx_merkle_root\n// (stacks-common util/hash.rs MerkleTree, MerkleHashFunc = Sha512Trunc256Sum).\nimport { sha512_256 } from \"@noble/hashes/sha2.js\";\nimport { splitTransactions } from \"@secondlayer/stacks/transactions\";\nimport { type Bytes, bytesEqual, concat, hex } from \"./bytes.ts\";\nimport type { NakamotoHeader } from \"./header.ts\";\n\nexport interface BlockTransaction {\n\t/** sha512/256 of the transaction bytes, hex. */\n\ttxid: string;\n\t/** The consensus-serialized transaction. */\n\traw: Bytes;\n}\n\nconst LEAF_TAG = new Uint8Array([0x00]);\nconst NODE_TAG = new Uint8Array([0x01]);\n\n/**\n * tx_merkle_root over txids: leaf = H(0x00 ‖ txid), node = H(0x01 ‖ l ‖ r),\n * an odd level duplicates its last node, and a lone leaf is still paired with\n * itself (one-tx blocks hash H(0x01 ‖ leaf ‖ leaf)).\n */\nexport function txMerkleRoot(txids: Bytes[]): Bytes {\n\tif (txids.length === 0) throw new Error(\"no transactions\");\n\tlet level = txids.map((t) => sha512_256(concat([LEAF_TAG, t])));\n\tdo {\n\t\tif (level.length % 2 === 1) level.push(level[level.length - 1] as Bytes);\n\t\tconst next: Bytes[] = [];\n\t\tfor (let i = 0; i < level.length; i += 2) {\n\t\t\tnext.push(\n\t\t\t\tsha512_256(\n\t\t\t\t\tconcat([NODE_TAG, level[i] as Bytes, level[i + 1] as Bytes]),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tlevel = next;\n\t} while (level.length > 1);\n\treturn level[0] as Bytes;\n}\n\nexport class TransactionsError extends Error {\n\tconstructor(\n\t\treadonly code: \"malformed\" | \"tx-root-mismatch\",\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t}\n}\n\n/**\n * The block's transactions, each hashed to its txid, checked against the\n * header's tx_merkle_root. The body after `header.byteLength` is a u32 count\n * then the transactions back to back. Null when the bytes are the header\n * alone (a source that serves headers only): nothing to check. Throws\n * {@link TransactionsError} on a malformed body, trailing bytes or a root\n * mismatch.\n */\nexport function blockTransactions(\n\traw: Bytes,\n\theader: NakamotoHeader,\n): BlockTransaction[] | null {\n\tconst body = raw.subarray(header.byteLength);\n\tif (body.length === 0) return null;\n\tif (body.length < 4)\n\t\tthrow new TransactionsError(\"malformed\", \"block body has no tx count\");\n\tconst count = new DataView(\n\t\tbody.buffer,\n\t\tbody.byteOffset,\n\t\tbody.byteLength,\n\t).getUint32(0);\n\tif (count === 0)\n\t\tthrow new TransactionsError(\"malformed\", \"block has no transactions\");\n\tlet txs: Bytes[];\n\ttry {\n\t\ttxs = splitTransactions(body.subarray(4), count);\n\t} catch (err) {\n\t\tthrow new TransactionsError(\n\t\t\t\"malformed\",\n\t\t\t`transactions do not parse: ${(err as Error).message}`,\n\t\t);\n\t}\n\tconst used = txs.reduce((n, t) => n + t.length, 4);\n\tif (used !== body.length)\n\t\tthrow new TransactionsError(\n\t\t\t\"malformed\",\n\t\t\t`${body.length - used} bytes after the block's ${count} transactions`,\n\t\t);\n\tconst ids = txs.map((t) => sha512_256(t));\n\tconst root = txMerkleRoot(ids);\n\tif (!bytesEqual(root, header.txMerkleRoot))\n\t\tthrow new TransactionsError(\n\t\t\t\"tx-root-mismatch\",\n\t\t\t`transactions hash to ${hex(root)}, header tx_merkle_root is ${hex(header.txMerkleRoot)}`,\n\t\t);\n\treturn txs.map((t, i) => ({ txid: hex(ids[i] as Bytes), raw: t }));\n}\n",
|
|
19
|
+
"// verifyBlock: the end-to-end trustless check for one Stacks block.\n//\n// At or above the checkpoint, forward:\n// checkpoint ─▶ bitcoin headers (PoW) ─▶ burn height ─▶ cycle ─▶ signer set[cycle] (MARF-proven)\n// ─▶ header N (signatures ≥ 70%) ─▶ txs N (tx merkle root) ─▶ witness N (root)\n// ─▶ named diff ─▶ indexed rows\n//\n// Below it, backward: a trusted descendant's id commits to every ancestor by\n// hash, so no signatures are needed:\n// checkpoint ─▶ id N (parent links, or one MARF proof of __MARF_BLOCK_HEIGHT_TO_HASH::N)\n// ─▶ header N (hashes to id N) ─▶ txs N ─▶ witness N (root) ─▶ named diff ─▶ indexed rows\n//\n// Every input comes from an untrusted ProofSource; only the checkpoint is trusted.\nimport { uintCV } from \"@secondlayer/stacks/clarity\";\nimport { HeaderChain, HeaderValidationError } from \"./bitcoin/chain.ts\";\nimport {\n\tMAINNET_PREPARE_LENGTH,\n\tcycleStart,\n\trewardCycle,\n\tverifyConsensusPreimage,\n} from \"./burn.ts\";\nimport { type Bytes, bytesEqual, hex, unhex } from \"./bytes.ts\";\nimport { MAINNET_CHECKPOINT, type VerifyCheckpoint } from \"./checkpoint.ts\";\nimport {\n\ttype Epoch2Header,\n\ttype NakamotoHeader,\n\ttype StacksHeader,\n\tblockId,\n\tisEpoch2Header,\n\tparseEpoch2Header,\n\tparseNakamotoHeader,\n\tsignerSignatureHash,\n} from \"./header.ts\";\nimport { mapEntryKey } from \"./keys.ts\";\nimport {\n\tMARF_VALUE_SIZE,\n\theightToHashKey,\n\tmarfPath,\n\tmarfProofAncestors,\n\tmarfProofValue,\n\tmarfValue,\n\tverifyMarfProof,\n} from \"./marf.ts\";\nimport {\n\tSIGNERS_CONTRACT,\n\ttype SignerSet,\n\tdecodeSignerSet,\n\tverifySignerSignatures,\n} from \"./signers.ts\";\nimport type { BurnPreimage, ProofSource, StateWrite } from \"./source.ts\";\nimport {\n\ttype ProvenDiff,\n\ttype StateFailureCode,\n\tverifyBlockState,\n} from \"./state.ts\";\nimport {\n\ttype BlockTransaction,\n\tTransactionsError,\n\tblockTransactions,\n} from \"./txs.ts\";\nimport { type WitnessLeaf, parseWitness } from \"./witness.ts\";\n\nexport type VerifyStep =\n\t| \"ancestry\"\n\t| \"block\"\n\t| \"bitcoin\"\n\t| \"burn\"\n\t| \"signer-set\"\n\t| \"signatures\"\n\t| \"txs\"\n\t| \"witness\"\n\t| \"names\"\n\t| \"rows\";\n\nexport type VerifyFailureCode =\n\t| StateFailureCode\n\t/** The source could not serve something the step needs. */\n\t| \"unavailable\"\n\t| \"id-mismatch\"\n\t/** The block's transactions do not hash to its header's tx_merkle_root. */\n\t| \"tx-root-mismatch\"\n\t| \"height-mismatch\"\n\t| \"invalid-header\"\n\t| \"preimage-mismatch\"\n\t| \"burn-not-in-chain\"\n\t| \"before-checkpoint\"\n\t/** The block is not the checkpoint chain's block at its height. */\n\t| \"not-ancestor\"\n\t| \"ancestry-proof-invalid\"\n\t| \"anchor-not-found\"\n\t| \"anchor-outside-window\"\n\t| \"anchor-unsigned\"\n\t| \"set-proof-invalid\"\n\t| \"below-threshold\"\n\t| \"unknown-signer\"\n\t| \"duplicate-signer\"\n\t| \"bad-signature\";\n\nexport interface VerifyFailure {\n\tstep: VerifyStep;\n\tcode: VerifyFailureCode;\n\tmessage: string;\n\t/** Reward cycle being proven (signer-set step). */\n\tcycle?: number;\n\t/** Block the failure is about, when not the target. */\n\tblockId?: string;\n\tkey?: string;\n\tpath?: string;\n\tordinal?: number;\n}\n\n/** How a block below the checkpoint was tied to it. */\nexport interface Ancestry {\n\t/** Trusted descendant it was proven from: the checkpoint, or a block proven below it earlier. */\n\tfromHeight: number;\n\tfromBlockId: string;\n\t/**\n\t * `parents`: each header hashes to the parent id its child commits to.\n\t * `marf`: one MARF proof of `__MARF_BLOCK_HEIGHT_TO_HASH::<height>` against\n\t * the descendant's state root.\n\t */\n\tvia: \"parents\" | \"marf\";\n}\n\nexport interface BlockVerification {\n\t/**\n\t * Every step passed. At or above the checkpoint: header, burn binding,\n\t * signatures, state root, names and rows. Below it: ancestry, header,\n\t * state root, names and rows (and the burn binding when Bitcoin reaches it).\n\t */\n\tok: boolean;\n\theight?: number;\n\tblockId?: string;\n\t/** Nakamoto block hash (the header's signer sighash), hex. Absent for epoch 2.x. */\n\tblockHash?: string;\n\t/** The header's consensus hash, hex. */\n\tconsensusHash?: string;\n\t/** Nakamoto header timestamp, Unix seconds. Absent for epoch 2.x. */\n\ttimestamp?: number;\n\t/** The header's state_index_root, hex: what the witness must hash to. */\n\tstateRoot?: string;\n\t/** Set for blocks below the checkpoint, which need no signatures. */\n\tancestry?: Ancestry;\n\tcycle?: number;\n\tburnHeight?: number;\n\t/** Display-order hex. */\n\tbitcoinBlockHash?: string;\n\tsignerWeight?: bigint;\n\ttotalWeight?: bigint;\n\tthreshold?: bigint;\n\t/**\n\t * The block's transactions, checked against the header's tx_merkle_root.\n\t * Absent for epoch 2.x blocks and when the source served the header only.\n\t */\n\ttransactions?: BlockTransaction[];\n\tdiff?: ProvenDiff;\n\t/** Every state_writes row the names step checked, in ordinal order. */\n\twrites?: StateWrite[];\n\t/** vm_events rows proven against the diff. */\n\trowsChecked?: number;\n\tnotes: string[];\n\t/** Empty when ok. The first entry is the first broken link. */\n\tfailures: VerifyFailure[];\n}\n\nexport interface VerifyOptions {\n\tsource: ProofSource;\n\t/** Defaults to MAINNET_CHECKPOINT. */\n\tcheckpoint?: VerifyCheckpoint;\n\t/**\n\t * Also prove the block's indexed vm_events rows against its diff: reads\n\t * the source's `getVmEvents`, which bill as Index rows on the Secondlayer\n\t * API. Off by default. Naming the diff's writes (`getStateWrites`, free on\n\t * `/v1/proofs`) is always on when the source has them.\n\t */\n\trows?: boolean;\n}\n\nclass Broken extends Error {\n\tconstructor(readonly failure: VerifyFailure) {\n\t\tsuper(failure.message);\n\t}\n}\n\nconst fail = (f: VerifyFailure): never => {\n\tthrow new Broken(f);\n};\n\n/** Run a source call; a throw becomes an `unavailable` failure of `step`. */\nasync function fetchFor<T>(\n\tstep: VerifyStep,\n\twhat: string,\n\tcall: () => Promise<T>,\n\textra: Partial<VerifyFailure> = {},\n): Promise<T> {\n\ttry {\n\t\treturn await call();\n\t} catch (err) {\n\t\tif (err instanceof Broken) throw err;\n\t\treturn fail({\n\t\t\tstep,\n\t\t\tcode: \"unavailable\",\n\t\t\tmessage: `${what}: ${(err as Error).message}`,\n\t\t\t...extra,\n\t\t});\n\t}\n}\n\nconst BITCOIN_BATCH = 2016;\n/**\n * Below the checkpoint, ancestors this close to a trusted block are reached by\n * parent links (one block fetch each); farther ones by one MARF proof, which\n * costs the proof plus a header per ancestor trie it crosses.\n */\nconst MAX_WALK = 16;\n\n/** A block position for the anchor search; `burn` is a source hint. */\nexport interface SearchPoint {\n\theight: number;\n\tburn?: number;\n}\n\n/**\n * Find a block whose burn height lies in `[window[0], window[1])`, between\n * `lo` and `hi` (exclusive). Interpolates on burn height, falling back to\n * bisection whenever a probe fails to halve the bracket. Burn heights here\n * are unproven hints: the caller authenticates whatever this returns.\n */\nexport async function findAnchor<T extends SearchPoint & { burn: number }>(\n\tlow: SearchPoint,\n\thigh: SearchPoint,\n\twindow: readonly [number, number],\n\tprobe: (height: number) => Promise<T>,\n\tmaxProbes = 32,\n): Promise<T | null> {\n\tlet [lo, hi] = [low, high];\n\tconst target = (window[0] + window[1]) / 2;\n\tlet bisect = false;\n\tfor (let i = 0; i < maxProbes; i++) {\n\t\tconst span = hi.height - lo.height;\n\t\tif (span <= 1) return null;\n\t\tlet h = Math.floor((lo.height + hi.height) / 2);\n\t\tif (\n\t\t\t!bisect &&\n\t\t\tlo.burn !== undefined &&\n\t\t\thi.burn !== undefined &&\n\t\t\thi.burn > lo.burn\n\t\t)\n\t\t\th =\n\t\t\t\tlo.height +\n\t\t\t\tMath.round(((target - lo.burn) * span) / (hi.burn - lo.burn));\n\t\th = Math.min(Math.max(h, lo.height + 1), hi.height - 1);\n\t\tconst p = await probe(h);\n\t\tif (p.height <= lo.height || p.height >= hi.height) return null;\n\t\tif (p.burn >= window[0] && p.burn < window[1]) return p;\n\t\tif (p.burn < window[0]) lo = p;\n\t\telse hi = p;\n\t\tbisect = hi.height - lo.height > span / 2;\n\t}\n\treturn null;\n}\n\ninterface Probe extends SearchPoint {\n\tburn: number;\n\theader: NakamotoHeader;\n\tid: string;\n}\n\n/**\n * Verifies blocks from one checkpoint against one source, caching the Bitcoin\n * header chain, proven signer sets and fetched headers across calls.\n */\nexport class BlockVerifier {\n\tprivate readonly source: ProofSource;\n\tprivate readonly checkpoint: VerifyCheckpoint;\n\tprivate readonly rows: boolean;\n\tprivate readonly chain: HeaderChain;\n\t/** Proven signer sets by cycle. */\n\tprivate readonly sets = new Map<number, SignerSet>();\n\t/** Where each proven set was anchored: the lower bound for the next search. */\n\tprivate readonly anchors = new Map<number, SearchPoint>();\n\t/** Headers fetched by id, each checked to hash to it. */\n\tprivate readonly headers = new Map<string, StacksHeader>();\n\t/** Blocks proven on the checkpoint's chain below it, by height. */\n\tprivate readonly below = new Map<\n\t\tnumber,\n\t\t{ id: string; ancestry: Ancestry }\n\t>();\n\tprivate readonly burns = new Map<\n\t\tstring,\n\t\t{ burnHeight: number; hash: string }\n\t>();\n\t/** Unverified source answers by consensus hash. */\n\tprivate readonly preimages = new Map<string, BurnPreimage>();\n\t/** Raw bytes of the last few blocks fetched, so the txs step reuses the\n\t * block an ancestry walk just read. Bounded: blocks can be megabytes. */\n\tprivate readonly raws = new Map<string, Bytes>();\n\tprivate readonly start: { header: NakamotoHeader; id: string };\n\n\tconstructor(opts: VerifyOptions) {\n\t\tthis.source = opts.source;\n\t\tthis.checkpoint = opts.checkpoint ?? MAINNET_CHECKPOINT;\n\t\tthis.rows = opts.rows ?? false;\n\t\tconst { stacks } = this.checkpoint;\n\t\tconst header = parseNakamotoHeader(unhex(stacks.header));\n\t\tthis.start = { header, id: hex(blockId(header)) };\n\t\tthis.headers.set(this.start.id, header);\n\t\tthis.sets.set(stacks.cycle, decodeSignerSet(stacks.signerSet));\n\t\tthis.chain = HeaderChain.fromCheckpoint(this.checkpoint.bitcoin);\n\t}\n\n\t/** Verify one block by id (hex) or height. Never throws for bad source data. */\n\tasync verify(ref: string | number): Promise<BlockVerification> {\n\t\tconst out: BlockVerification = { ok: false, notes: [], failures: [] };\n\t\ttry {\n\t\t\tawait this.run(ref, out);\n\t\t} catch (err) {\n\t\t\tif (!(err instanceof Broken)) throw err;\n\t\t\tout.failures.unshift(err.failure);\n\t\t}\n\t\tout.ok = out.failures.length === 0;\n\t\treturn out;\n\t}\n\n\tprivate async run(\n\t\tref: string | number,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tconst start = Number(this.start.header.chainLength);\n\t\tif (typeof ref === \"number\" && ref < start)\n\t\t\treturn this.runBelow(ref, undefined, out);\n\t\tlet header: StacksHeader;\n\t\tif (typeof ref === \"string\") {\n\t\t\tconst id = ref.replace(/^0x/, \"\").toLowerCase();\n\t\t\theader = await this.header(id, \"block\");\n\t\t\tconst height = Number(header.chainLength);\n\t\t\tif (height < start) return this.runBelow(height, id, out);\n\t\t\tif (isEpoch2Header(header))\n\t\t\t\tfail({\n\t\t\t\t\tstep: \"block\",\n\t\t\t\t\tcode: \"invalid-header\",\n\t\t\t\t\tmessage: `epoch 2.x block ${id} claims height ${height}, at or above the checkpoint`,\n\t\t\t\t});\n\t\t} else {\n\t\t\tconst raw = await fetchFor(\"block\", `block ${ref}`, () =>\n\t\t\t\tthis.source.getBlock(ref),\n\t\t\t);\n\t\t\theader = parseHeader(raw, \"block\");\n\t\t\tthis.rememberRaw(hex(blockId(header)), raw);\n\t\t}\n\t\tconst id = hex(blockId(header));\n\t\tconst height = Number(header.chainLength);\n\t\tif (typeof ref === \"number\" && height !== ref)\n\t\t\tfail({\n\t\t\t\tstep: \"block\",\n\t\t\t\tcode: \"height-mismatch\",\n\t\t\t\tmessage: `source returned height ${height} for ${ref}`,\n\t\t\t});\n\t\tawait this.runForward(header as NakamotoHeader, id, out);\n\t}\n\n\t/** At or above the checkpoint: Bitcoin, burn binding, signer set, signatures, state. */\n\tprivate async runForward(\n\t\theader: NakamotoHeader,\n\t\tid: string,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tconst height = Number(header.chainLength);\n\t\tout.height = height;\n\t\tout.blockId = id;\n\t\tdescribeHeader(header, out);\n\n\t\tconst burn = await this.bindBurn(header, \"burn\");\n\t\tconst cycle = rewardCycle(burn.burnHeight);\n\t\tout.burnHeight = burn.burnHeight;\n\t\tout.bitcoinBlockHash = burn.hash;\n\t\tout.cycle = cycle;\n\n\t\tconst set = await this.signerSet(cycle, {\n\t\t\theight,\n\t\t\tburn: burn.burnHeight,\n\t\t});\n\t\tconst sig = verifySignerSignatures(header, set);\n\t\tout.signerWeight = sig.signedWeight;\n\t\tout.totalWeight = sig.totalWeight;\n\t\tout.threshold = sig.threshold;\n\t\tif (!sig.valid) fail(signatureFailure(sig, \"signatures\", cycle));\n\t\tawait this.checkTransactions(header, id, out);\n\t\tawait this.verifyState(header, id, out);\n\t}\n\n\t/**\n\t * Below the checkpoint: prove the checkpoint chain's id at `height` (and\n\t * that it is `claimed`, when the caller asked by id), then the header that\n\t * hashes to it, then its state. Signatures add nothing to a header pinned\n\t * by hash from a trusted descendant.\n\t */\n\tprivate async runBelow(\n\t\theight: number,\n\t\tclaimed: string | undefined,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tout.height = height;\n\t\tconst { id, ancestry } = await this.ancestor(height);\n\t\tout.ancestry = ancestry;\n\t\tif (claimed !== undefined && claimed !== id)\n\t\t\tfail({\n\t\t\t\tstep: \"ancestry\",\n\t\t\t\tcode: \"not-ancestor\",\n\t\t\t\tmessage: `block ${claimed} is not on the checkpoint's chain: its block at height ${height} is ${id}`,\n\t\t\t\tblockId: claimed,\n\t\t\t});\n\t\tconst header = await this.header(id, \"block\");\n\t\tif (Number(header.chainLength) !== height)\n\t\t\tfail({\n\t\t\t\tstep: \"block\",\n\t\t\t\tcode: \"height-mismatch\",\n\t\t\t\tmessage: `block ${id} claims height ${header.chainLength}, proven at ${height}`,\n\t\t\t});\n\t\tout.blockId = id;\n\t\tdescribeHeader(header, out);\n\t\tawait this.bindBurnBelow(header, out);\n\t\tawait this.checkTransactions(header, id, out);\n\t\tawait this.verifyState(header, id, out);\n\t}\n\n\tprivate rememberRaw(id: string, raw: Bytes): void {\n\t\tthis.raws.delete(id);\n\t\tthis.raws.set(id, raw);\n\t\twhile (this.raws.size > 4) {\n\t\t\tconst oldest = this.raws.keys().next().value as string;\n\t\t\tthis.raws.delete(oldest);\n\t\t}\n\t}\n\n\t/**\n\t * The block's transactions against the authenticated header's\n\t * tx_merkle_root: binds every txid, sender, type and call target to the\n\t * signed (or hash-linked) header.\n\t */\n\tprivate async checkTransactions(\n\t\theader: StacksHeader,\n\t\tid: string,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tif (isEpoch2Header(header)) {\n\t\t\tout.notes.push(\"epoch 2.x: transactions not checked\");\n\t\t\treturn;\n\t\t}\n\t\tconst raw =\n\t\t\tthis.raws.get(id) ??\n\t\t\t(await fetchFor(\"txs\", `block ${id}`, () => this.source.getBlock(id)));\n\t\tlet txs: BlockTransaction[] | null;\n\t\ttry {\n\t\t\ttxs = blockTransactions(raw, header);\n\t\t} catch (err) {\n\t\t\tif (!(err instanceof TransactionsError)) throw err;\n\t\t\treturn fail({ step: \"txs\", code: err.code, message: err.message });\n\t\t}\n\t\tif (txs === null) {\n\t\t\tout.notes.push(\n\t\t\t\t`transactions not checked: the source served block ${id}'s header only`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tout.transactions = txs;\n\t}\n\n\t/**\n\t * The checkpoint chain's block id at `height`, from the nearest trusted\n\t * block above it: parent links when within MAX_WALK, else one MARF proof.\n\t */\n\tprivate async ancestor(\n\t\theight: number,\n\t): Promise<{ id: string; ancestry: Ancestry }> {\n\t\tconst known = this.below.get(height);\n\t\tif (known) return known;\n\t\tconst from = this.nearestAbove(height);\n\t\tif (from.height - height <= MAX_WALK) {\n\t\t\tconst walked = await this.walk(from, height);\n\t\t\tif (walked) return walked;\n\t\t}\n\t\treturn this.jump(this.nearestAbove(height), height);\n\t}\n\n\t/** The lowest trusted block above `height`: the checkpoint or one proven below it. */\n\tprivate nearestAbove(height: number): { height: number; id: string } {\n\t\tlet best = {\n\t\t\theight: Number(this.start.header.chainLength),\n\t\t\tid: this.start.id,\n\t\t};\n\t\tfor (const [h, { id }] of this.below)\n\t\t\tif (h > height && h < best.height) best = { height: h, id };\n\t\treturn best;\n\t}\n\n\t/**\n\t * Follow parent ids down from `from`: each parent header must hash to the\n\t * id its child committed to. Null when a 2.x header stops the walk: it\n\t * commits to its parent's block hash, not the parent's id.\n\t */\n\tprivate async walk(\n\t\tfrom: { height: number; id: string },\n\t\theight: number,\n\t): Promise<{ id: string; ancestry: Ancestry } | null> {\n\t\tconst ancestry: Ancestry = {\n\t\t\tfromHeight: from.height,\n\t\t\tfromBlockId: from.id,\n\t\t\tvia: \"parents\",\n\t\t};\n\t\tlet child = await this.header(from.id, \"ancestry\");\n\t\tfor (let h = from.height - 1; h >= height; h--) {\n\t\t\tif (isEpoch2Header(child)) return null;\n\t\t\tconst id = hex(child.parentBlockId);\n\t\t\tconst parent = await this.header(id, \"ancestry\", { blockId: id });\n\t\t\tif (Number(parent.chainLength) !== h)\n\t\t\t\tfail({\n\t\t\t\t\tstep: \"ancestry\",\n\t\t\t\t\tcode: \"height-mismatch\",\n\t\t\t\t\tmessage: `parent ${id} claims height ${parent.chainLength}, expected ${h}`,\n\t\t\t\t\tblockId: id,\n\t\t\t\t});\n\t\t\tthis.below.set(h, { id, ancestry });\n\t\t\tchild = parent;\n\t\t}\n\t\treturn this.below.get(height) ?? null;\n\t}\n\n\t/**\n\t * Read the id at `height` from `from`'s state: block `height + 1` wrote it\n\t * to `__MARF_BLOCK_HEIGHT_TO_HASH::<height>`, and the proof must recompute\n\t * `from`'s state root through the header of every trie it crosses.\n\t */\n\tprivate async jump(\n\t\tfrom: { height: number; id: string },\n\t\theight: number,\n\t): Promise<{ id: string; ancestry: Ancestry }> {\n\t\tconst at = { blockId: from.id };\n\t\tconst tip = await this.header(from.id, \"ancestry\", at);\n\t\tconst key = heightToHashKey(height);\n\t\tconst path = marfPath(key);\n\t\tconst answer = await fetchFor(\n\t\t\t\"ancestry\",\n\t\t\t`${key} at ${from.id}`,\n\t\t\t() => this.source.getMarfProof(hex(path), from.id),\n\t\t\tat,\n\t\t);\n\t\tif (!answer)\n\t\t\treturn fail({\n\t\t\t\tstep: \"ancestry\",\n\t\t\t\tcode: \"unavailable\",\n\t\t\t\tmessage: `source has no MARF proof of ${key} at block ${from.height}, ${from.height - height} blocks up; parent links reach ${MAX_WALK}`,\n\t\t\t\t...at,\n\t\t\t});\n\t\t// A block id fills the first 32 bytes of the MARFValue; the tail is zero.\n\t\tconst value = marfProofValue(answer.proof) ?? new Uint8Array();\n\t\tconst proven =\n\t\t\tvalue.length === MARF_VALUE_SIZE &&\n\t\t\tvalue.subarray(32).every((b) => b === 0) &&\n\t\t\t(await this.proveAt(tip, path, value, answer.proof, \"ancestry\", at));\n\t\tif (!proven)\n\t\t\treturn fail({\n\t\t\t\tstep: \"ancestry\",\n\t\t\t\tcode: \"ancestry-proof-invalid\",\n\t\t\t\tmessage: `${key} is not proven in block ${from.height}'s state`,\n\t\t\t\t...at,\n\t\t\t});\n\t\tconst ancestry: Ancestry = {\n\t\t\tfromHeight: from.height,\n\t\t\tfromBlockId: from.id,\n\t\t\tvia: \"marf\",\n\t\t};\n\t\tconst found = { id: hex(value.subarray(0, 32)), ancestry };\n\t\tthis.below.set(height, found);\n\t\treturn found;\n\t}\n\n\t/**\n\t * Below the checkpoint the hash chain already pins the block; still bind\n\t * its burn block when the Bitcoin checkpoint reaches it. The burn height\n\t * here is the source's hint, so a low one only skips this extra check.\n\t */\n\tprivate async bindBurnBelow(\n\t\theader: StacksHeader,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tlet hint: number;\n\t\ttry {\n\t\t\thint = await this.burnHint(header);\n\t\t} catch (err) {\n\t\t\tout.notes.push(`burn block not checked: ${(err as Error).message}`);\n\t\t\treturn;\n\t\t}\n\t\tif (hint < this.chain.checkpointHeight) {\n\t\t\tout.notes.push(\n\t\t\t\t`burn block not checked: its height ${hint} is below the Bitcoin checkpoint ${this.chain.checkpointHeight}`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst burn = await this.bindBurn(header, \"burn\");\n\t\tout.burnHeight = burn.burnHeight;\n\t\tout.bitcoinBlockHash = burn.hash;\n\t}\n\n\t/** Witness against the authenticated header's root, then the named diff and rows. */\n\tprivate async verifyState(\n\t\theader: StacksHeader,\n\t\tid: string,\n\t\tout: BlockVerification,\n\t): Promise<void> {\n\t\tconst src = this.source;\n\t\tconst height = Number(header.chainLength);\n\t\tconst witness = await fetchFor(\"witness\", `witness ${id}`, () =>\n\t\t\tsrc.getWitness(id),\n\t\t);\n\t\tconst writes = await this.stateWrites(height, out.notes);\n\t\tif (writes) out.writes = writes;\n\t\tconst { getVmEvents }: Partial<ProofSource> = this.rows ? src : {};\n\t\tconst rows = getVmEvents\n\t\t\t? await fetchFor(\"rows\", `vm_events ${height}`, () =>\n\t\t\t\t\tgetVmEvents.call(src, height),\n\t\t\t\t)\n\t\t\t: undefined;\n\t\tconst parent = isEpoch2Header(header)\n\t\t\t? epoch2ParentId(witness, header)\n\t\t\t: header.parentBlockId;\n\t\tconst parentId = parent && hex(parent);\n\t\tconst state = await verifyBlockState({\n\t\t\theight,\n\t\t\t// Null only when the witness fails its root check, which fails the block.\n\t\t\tparentBlockId: parent ?? new Uint8Array(32),\n\t\t\tstateRoot: header.stateIndexRoot,\n\t\t\twitness,\n\t\t\twrites,\n\t\t\trows,\n\t\t\tparentLeaves: parentId\n\t\t\t\t? await this.parentLeaves(parentId, out.notes)\n\t\t\t\t: undefined,\n\t\t\tparentHolds: async (leaf) =>\n\t\t\t\tparentId ? this.parentHolds(parentId, leaf) : false,\n\t\t});\n\t\tout.diff = state.diff;\n\t\tif (rows) out.rowsChecked = state.rowsChecked;\n\t\tout.notes.push(...state.notes);\n\t\tout.failures.push(...state.failures);\n\t}\n\n\t/**\n\t * The block's state writes, to name its diff. Optional evidence: a source\n\t * with none for the block (404, empty) or that fails leaves the diff\n\t * proven but unnamed, with a note, never a failure.\n\t */\n\tprivate async stateWrites(\n\t\theight: number,\n\t\tnotes: string[],\n\t): Promise<StateWrite[] | null> {\n\t\tconst { getStateWrites } = this.source;\n\t\tif (!getStateWrites) return null;\n\t\ttry {\n\t\t\tconst writes = await getStateWrites.call(this.source, height);\n\t\t\treturn writes?.length ? writes : null;\n\t\t} catch (err) {\n\t\t\tnotes.push(\n\t\t\t\t`state writes for block ${height} unavailable: ${(err as Error).message}`,\n\t\t\t);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/** Header by id, from the cache or the source; it must hash to `id`. */\n\tprivate async header(\n\t\tid: string,\n\t\tstep: VerifyStep,\n\t\textra: Partial<VerifyFailure> = {},\n\t): Promise<StacksHeader> {\n\t\tconst known = this.headers.get(id);\n\t\tif (known) return known;\n\t\tconst header = await this.fetchHeader(id, step, extra);\n\t\tif (hex(blockId(header)) !== id)\n\t\t\tfail({\n\t\t\t\tstep,\n\t\t\t\tcode: \"id-mismatch\",\n\t\t\t\tmessage: `source returned another block for ${id}`,\n\t\t\t\tblockId: id,\n\t\t\t\t...extra,\n\t\t\t});\n\t\tthis.headers.set(id, header);\n\t\treturn header;\n\t}\n\n\t/**\n\t * A Nakamoto block by id, or when the source has none (epoch 2.x blocks are\n\t * not served as Nakamoto blocks) its epoch 2.x header.\n\t */\n\tprivate async fetchHeader(\n\t\tid: string,\n\t\tstep: VerifyStep,\n\t\textra: Partial<VerifyFailure>,\n\t): Promise<StacksHeader> {\n\t\tconst src = this.source;\n\t\tlet raw: Bytes;\n\t\ttry {\n\t\t\traw = await src.getBlock(id);\n\t\t\tthis.rememberRaw(id, raw);\n\t\t} catch (err) {\n\t\t\tconst reason = `block ${id}: ${(err as Error).message}`;\n\t\t\tconst { getEpoch2Header } = src;\n\t\t\tif (!getEpoch2Header)\n\t\t\t\treturn fail({ step, code: \"unavailable\", message: reason, ...extra });\n\t\t\tconst e2 = await fetchFor(\n\t\t\t\tstep,\n\t\t\t\t`${reason}; epoch 2.x header`,\n\t\t\t\t() => getEpoch2Header.call(src, id),\n\t\t\t\textra,\n\t\t\t);\n\t\t\ttry {\n\t\t\t\treturn parseEpoch2Header(e2.header, e2.consensusHash);\n\t\t\t} catch (parseErr) {\n\t\t\t\treturn fail({\n\t\t\t\t\tstep,\n\t\t\t\t\tcode: \"invalid-header\",\n\t\t\t\t\tmessage: `epoch 2.x header ${id} does not parse: ${(parseErr as Error).message}`,\n\t\t\t\t\t...extra,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn parseHeader(raw, step);\n\t}\n\n\t/**\n\t * Prove `value` at `path` in `tip`'s state, fetching the header of every\n\t * ancestor trie the proof crosses.\n\t */\n\tprivate async proveAt(\n\t\ttip: StacksHeader,\n\t\tpath: Bytes,\n\t\tvalue: Bytes,\n\t\tproof: Bytes,\n\t\tstep: VerifyStep,\n\t\textra: Partial<VerifyFailure> = {},\n\t): Promise<boolean> {\n\t\tconst headers = [tip];\n\t\tfor (const id of marfProofAncestors(proof))\n\t\t\theaders.push(await this.header(id, step, extra));\n\t\treturn verifyMarfProof({\n\t\t\tproof,\n\t\t\tpath,\n\t\t\tvalue,\n\t\t\troot: tip.stateIndexRoot,\n\t\t\theaders,\n\t\t});\n\t}\n\n\t/**\n\t * The parent's own trie leaves, from its witness checked against the\n\t * parent header. Optional evidence: when the source cannot serve it,\n\t * carried leaves fall back to per-leaf proofs (named) or stay unlabeled.\n\t */\n\tprivate async parentLeaves(\n\t\tparentId: string,\n\t\tnotes: string[],\n\t): Promise<WitnessLeaf[] | undefined> {\n\t\ttry {\n\t\t\tconst parent = await this.header(parentId, \"names\");\n\t\t\tconst w = parseWitness(await this.source.getWitness(parentId));\n\t\t\tif (bytesEqual(w.root, parent.stateIndexRoot)) return w.leaves;\n\t\t\tnotes.push(`parent witness ${parentId} root does not match its header`);\n\t\t} catch (err) {\n\t\t\tnotes.push(\n\t\t\t\t`parent witness ${parentId} unavailable: ${(err as Error).message}`,\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * A carried leaf holds the parent's value. The parent header is\n\t * authenticated by hash: its id is committed in the authenticated child\n\t * (its header, or for 2.x its own trie).\n\t */\n\tprivate async parentHolds(\n\t\tparentId: string,\n\t\tleaf: WitnessLeaf,\n\t): Promise<boolean> {\n\t\tconst parent = await this.header(parentId, \"names\");\n\t\tconst pathHex = hex(leaf.path);\n\t\tconst answer = await fetchFor(\"names\", `MARF ${pathHex} at parent`, () =>\n\t\t\tthis.source.getMarfProof(pathHex, parentId),\n\t\t);\n\t\tif (!answer) return false;\n\t\tconst value = new Uint8Array(MARF_VALUE_SIZE);\n\t\tvalue.set(leaf.valueHash);\n\t\treturn this.proveAt(parent, leaf.path, value, answer.proof, \"names\");\n\t}\n\n\t/** Consensus hash -> PoW-verified burn block, via the sortition preimage. */\n\tprivate async bindBurn(\n\t\theader: StacksHeader,\n\t\tstep: VerifyStep,\n\t\textra: Partial<VerifyFailure> = {},\n\t): Promise<{ burnHeight: number; hash: string }> {\n\t\tconst ch = hex(header.consensusHash);\n\t\tconst known = this.burns.get(ch);\n\t\tif (known) return known;\n\t\tconst bp = await fetchFor(\n\t\t\tstep,\n\t\t\t`burn preimage ${ch}`,\n\t\t\t() => this.preimage(ch),\n\t\t\textra,\n\t\t);\n\t\tconst hash = verifyConsensusPreimage(header.consensusHash, bp.preimage);\n\t\tif (!hash)\n\t\t\treturn fail({\n\t\t\t\tstep,\n\t\t\t\tcode: \"preimage-mismatch\",\n\t\t\t\tmessage: `preimage does not hash to consensus hash ${ch}`,\n\t\t\t\t...extra,\n\t\t\t});\n\t\tif (bp.burnHeight < this.chain.checkpointHeight)\n\t\t\tfail({\n\t\t\t\tstep,\n\t\t\t\tcode: \"before-checkpoint\",\n\t\t\t\tmessage: `burn height ${bp.burnHeight} is below the Bitcoin checkpoint ${this.chain.checkpointHeight}`,\n\t\t\t\t...extra,\n\t\t\t});\n\t\tawait this.syncBitcoin(bp.burnHeight);\n\t\tconst burnHeight = this.chain.heightOf(hash);\n\t\tif (burnHeight === undefined)\n\t\t\treturn fail({\n\t\t\t\tstep,\n\t\t\t\tcode: \"burn-not-in-chain\",\n\t\t\t\tmessage: `burn block ${hash} is not in the verified Bitcoin chain (synced ${this.chain.checkpointHeight}..${this.chain.tip.height})`,\n\t\t\t\t...extra,\n\t\t\t});\n\t\tconst bound = { burnHeight, hash };\n\t\tthis.burns.set(ch, bound);\n\t\treturn bound;\n\t}\n\n\t/** Extend the Bitcoin chain to `height`, validating PoW, retarget and MTP. */\n\tprivate async syncBitcoin(height: number): Promise<void> {\n\t\twhile (this.chain.tip.height < height) {\n\t\t\tconst from = this.chain.tip.height + 1;\n\t\t\tconst count = Math.min(BITCOIN_BATCH, height - from + 1);\n\t\t\tconst headers = await fetchFor(\"bitcoin\", `bitcoin headers ${from}`, () =>\n\t\t\t\tthis.source.getBitcoinHeaders(from, count),\n\t\t\t);\n\t\t\tif (headers.length === 0)\n\t\t\t\tfail({\n\t\t\t\t\tstep: \"bitcoin\",\n\t\t\t\t\tcode: \"unavailable\",\n\t\t\t\t\tmessage: `source has no Bitcoin headers from ${from}`,\n\t\t\t\t});\n\t\t\ttry {\n\t\t\t\tthis.chain.append(headers);\n\t\t\t} catch (err) {\n\t\t\t\tif (!(err instanceof HeaderValidationError)) throw err;\n\t\t\t\tfail({ step: \"bitcoin\", code: \"invalid-header\", message: err.message });\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The proven signer set for `cycle`. Walks forward from the checkpoint:\n\t * set c+1 is read from an anchor block in c+1's prepare phase, whose\n\t * header set c signed.\n\t */\n\tprivate async signerSet(\n\t\tcycle: number,\n\t\ttarget: SearchPoint,\n\t): Promise<SignerSet> {\n\t\tconst known = this.sets.get(cycle);\n\t\tif (known) return known;\n\t\tconst first = this.checkpoint.stacks.cycle;\n\t\tif (cycle < first)\n\t\t\tfail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"before-checkpoint\",\n\t\t\t\tmessage: `cycle ${cycle} precedes the checkpoint's cycle ${first}`,\n\t\t\t\tcycle,\n\t\t\t});\n\t\tlet lo = await this.startPoint();\n\t\tfor (let c = first; c < cycle; c++) {\n\t\t\tconst next = this.sets.get(c + 1);\n\t\t\tif (next) {\n\t\t\t\tlo = this.anchors.get(c + 1) ?? lo;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst anchor = await this.locateAnchor(c + 1, lo, target);\n\t\t\tthis.sets.set(c + 1, await this.proveNextSet(c + 1, anchor));\n\t\t\tthis.anchors.set(c + 1, anchor);\n\t\t\tlo = anchor;\n\t\t}\n\t\treturn this.sets.get(cycle) as SignerSet;\n\t}\n\n\t/** The checkpoint block as a search bound; its burn height is a source hint. */\n\tprivate async startPoint(): Promise<SearchPoint> {\n\t\tconst { header } = this.start;\n\t\tconst height = Number(header.chainLength);\n\t\ttry {\n\t\t\treturn { height, burn: await this.burnHint(header) };\n\t\t} catch {\n\t\t\treturn { height };\n\t\t}\n\t}\n\n\tprivate async burnHint(header: StacksHeader): Promise<number> {\n\t\tconst ch = hex(header.consensusHash);\n\t\treturn (\n\t\t\tthis.burns.get(ch)?.burnHeight ?? (await this.preimage(ch)).burnHeight\n\t\t);\n\t}\n\n\tprivate async preimage(ch: string): Promise<BurnPreimage> {\n\t\tlet bp = this.preimages.get(ch);\n\t\tif (!bp) {\n\t\t\tbp = await this.source.getBurnPreimage(ch);\n\t\t\tthis.preimages.set(ch, bp);\n\t\t}\n\t\treturn bp;\n\t}\n\n\tprivate async locateAnchor(\n\t\tcycle: number,\n\t\tlo: SearchPoint,\n\t\thi: SearchPoint,\n\t): Promise<Probe> {\n\t\tconst start = cycleStart(cycle);\n\t\tconst window = [start - MAINNET_PREPARE_LENGTH, start] as const;\n\t\tconst probe = async (h: number): Promise<Probe> => {\n\t\t\tconst raw = await fetchFor(\n\t\t\t\t\"signer-set\",\n\t\t\t\t`block at height ${h}`,\n\t\t\t\t() => this.source.getBlock(h),\n\t\t\t\t{ cycle },\n\t\t\t);\n\t\t\tconst header = parseHeader(raw, \"signer-set\");\n\t\t\tconst id = hex(blockId(header));\n\t\t\tthis.headers.set(id, header);\n\t\t\tconst burn = await fetchFor(\n\t\t\t\t\"signer-set\",\n\t\t\t\t`burn hint for block ${id}`,\n\t\t\t\t() => this.burnHint(header),\n\t\t\t\t{ cycle, blockId: id },\n\t\t\t);\n\t\t\treturn { height: Number(header.chainLength), burn, header, id };\n\t\t};\n\t\tconst anchor = await findAnchor(lo, hi, window, probe);\n\t\tif (!anchor)\n\t\t\treturn fail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"anchor-not-found\",\n\t\t\t\tmessage: `no block with a burn height in ${window[0]}..${window[1] - 1} (cycle ${cycle} prepare phase) between heights ${lo.height} and ${hi.height}`,\n\t\t\t\tcycle,\n\t\t\t});\n\t\treturn anchor;\n\t}\n\n\t/**\n\t * Set `cycle` from `anchor`: the anchor must be bound to a burn block in\n\t * `cycle`'s prepare phase, be signed by the set of the cycle that burn\n\t * height dictates (`cycle - 1`), and hold set `cycle` in its state (MARF\n\t * proof). Adjacent sets overlap enough that one block can clear both, so\n\t * the set is always chosen by proven burn height, never by which passes.\n\t */\n\tprivate async proveNextSet(cycle: number, anchor: Probe): Promise<SignerSet> {\n\t\tconst at = { cycle, blockId: anchor.id };\n\t\tconst { burnHeight } = await this.bindBurn(anchor.header, \"signer-set\", at);\n\t\tconst start = cycleStart(cycle);\n\t\tif (burnHeight < start - MAINNET_PREPARE_LENGTH || burnHeight >= start)\n\t\t\tfail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"anchor-outside-window\",\n\t\t\t\tmessage: `anchor burn height ${burnHeight} is outside cycle ${cycle}'s prepare phase ${start - MAINNET_PREPARE_LENGTH}..${start - 1}`,\n\t\t\t\t...at,\n\t\t\t});\n\t\tconst signing = rewardCycle(burnHeight);\n\t\tconst sig = verifySignerSignatures(\n\t\t\tanchor.header,\n\t\t\tthis.sets.get(signing) as SignerSet,\n\t\t);\n\t\tif (!sig.valid)\n\t\t\tfail({\n\t\t\t\t...signatureFailure(sig, \"signer-set\", signing),\n\t\t\t\t...at,\n\t\t\t\tcode: \"anchor-unsigned\",\n\t\t\t});\n\n\t\tconst path = marfPath(\n\t\t\tmapEntryKey(SIGNERS_CONTRACT, \"cycle-signer-set\", uintCV(cycle)),\n\t\t);\n\t\tconst answer = await fetchFor(\n\t\t\t\"signer-set\",\n\t\t\t`signer set ${cycle} at ${anchor.id}`,\n\t\t\t() => this.source.getMarfProof(hex(path), anchor.id),\n\t\t\tat,\n\t\t);\n\t\tconst value = answer?.data.replace(/^0x/, \"\") ?? \"\";\n\t\tconst proven =\n\t\t\tanswer !== null &&\n\t\t\t(await this.proveAt(\n\t\t\t\tanchor.header,\n\t\t\t\tpath,\n\t\t\t\tmarfValue(value),\n\t\t\t\tanswer.proof,\n\t\t\t\t\"signer-set\",\n\t\t\t\tat,\n\t\t\t));\n\t\tif (!proven)\n\t\t\tfail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"set-proof-invalid\",\n\t\t\t\tmessage: `signer set ${cycle} is not proven in anchor ${anchor.id}'s state`,\n\t\t\t\t...at,\n\t\t\t});\n\t\tlet set: SignerSet;\n\t\ttry {\n\t\t\tset = decodeSignerSet(value);\n\t\t} catch (err) {\n\t\t\treturn fail({\n\t\t\t\tstep: \"signer-set\",\n\t\t\t\tcode: \"set-proof-invalid\",\n\t\t\t\tmessage: `signer set ${cycle}: ${(err as Error).message}`,\n\t\t\t\t...at,\n\t\t\t});\n\t\t}\n\t\treturn set;\n\t}\n}\n\n/** The authenticated header's identity fields, for callers that rebuild the block. */\nfunction describeHeader(header: StacksHeader, out: BlockVerification): void {\n\tout.stateRoot = hex(header.stateIndexRoot);\n\tout.consensusHash = hex(header.consensusHash);\n\tif (!isEpoch2Header(header)) {\n\t\tout.blockHash = hex(signerSignatureHash(header));\n\t\tout.timestamp = Number(header.timestamp);\n\t}\n}\n\nfunction parseHeader(raw: Bytes, step: VerifyStep): NakamotoHeader {\n\ttry {\n\t\treturn parseNakamotoHeader(raw);\n\t} catch (err) {\n\t\treturn fail({\n\t\t\tstep,\n\t\t\tcode: \"invalid-header\",\n\t\t\tmessage: `block bytes do not parse: ${(err as Error).message}`,\n\t\t});\n\t}\n}\n\n/**\n * A 2.x header commits only to its parent's block hash; the parent's id is in\n * the block's own trie at `__MARF_BLOCK_HEIGHT_TO_HASH::<height - 1>`. Read\n * from a witness whose root matches the header, else null.\n */\nfunction epoch2ParentId(witness: Bytes, header: Epoch2Header): Bytes | null {\n\tconst height = Number(header.chainLength);\n\tif (height === 0) return null;\n\ttry {\n\t\tconst w = parseWitness(witness);\n\t\tif (!bytesEqual(w.root, header.stateIndexRoot)) return null;\n\t\tconst path = marfPath(heightToHashKey(height - 1));\n\t\treturn w.leaves.find((l) => bytesEqual(l.path, path))?.valueHash ?? null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction signatureFailure(\n\tsig: ReturnType<typeof verifySignerSignatures>,\n\tstep: VerifyStep,\n\tcycle: number,\n): VerifyFailure {\n\tconst weight = `${sig.signedWeight}/${sig.totalWeight} signed, threshold ${sig.threshold}`;\n\tif (sig.unknown.length)\n\t\treturn {\n\t\t\tstep,\n\t\t\tcode: \"unknown-signer\",\n\t\t\tmessage: `${sig.unknown.length} signer(s) not in cycle ${cycle}'s set (${weight})`,\n\t\t\tcycle,\n\t\t};\n\tif (sig.duplicates.length)\n\t\treturn {\n\t\t\tstep,\n\t\t\tcode: \"duplicate-signer\",\n\t\t\tmessage: `${sig.duplicates.length} duplicate signature(s) (${weight})`,\n\t\t\tcycle,\n\t\t};\n\tif (sig.invalid)\n\t\treturn {\n\t\t\tstep,\n\t\t\tcode: \"bad-signature\",\n\t\t\tmessage: `${sig.invalid} signature(s) do not recover (${weight})`,\n\t\t\tcycle,\n\t\t};\n\treturn {\n\t\tstep,\n\t\tcode: \"below-threshold\",\n\t\tmessage: `cycle ${cycle} signers: ${weight}`,\n\t\tcycle,\n\t};\n}\n\n/** One-shot: verify a block from a checkpoint (MAINNET_CHECKPOINT by default). */\nexport const verif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AAM;AAAA,MACN,SAAS,GAAG,IAAI,wCAAwC;AAAA,MACxD;AAAA,IACD;AAAA,EACD,OAAO;AAAA,IACN;AAAA,IACA,MAAM;AAAA,IACN,SAAS,SAAS,kBAAkB;AAAA,IACpC;AAAA,EACD;AAAA;AAIM,IAAM,cAAc,CAC1B,KACA,SACgC,IAAI,cAAc,IAAI,EAAE,OAAO,GAAG;",
|
|
22
|
+
"debugId": "14EE5CF6A37C9A0B64756E2164756E21",
|
|
22
23
|
"names": []
|
|
23
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secondlayer/verify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Check a Stacks block yourself: Bitcoin headers, signer signatures and MARF state proofs, from one trusted checkpoint.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@noble/curves": "2.0.1",
|
|
31
31
|
"@noble/hashes": "2.0.1",
|
|
32
|
-
"@secondlayer/stacks": "^6.
|
|
32
|
+
"@secondlayer/stacks": "^6.2.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/bun": "latest",
|