-
-
Notifications
You must be signed in to change notification settings - Fork 457
Expand file tree
/
Copy pathvalidateLightClientBootstrap.ts
More file actions
41 lines (36 loc) · 1.59 KB
/
validateLightClientBootstrap.ts
File metadata and controls
41 lines (36 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {byteArrayEquals} from "@chainsafe/ssz";
import {LightClientBootstrap, Root, ssz} from "@lodestar/types";
import {ChainForkConfig} from "@lodestar/config";
import {toHex} from "@lodestar/utils";
import {isForkPostElectra} from "@lodestar/params";
import {isValidMerkleBranch} from "../utils/verifyMerkleBranch.js";
import {isValidLightClientHeader} from "./utils.js";
const CURRENT_SYNC_COMMITTEE_INDEX = 22;
const CURRENT_SYNC_COMMITTEE_DEPTH = 5;
const CURRENT_SYNC_COMMITTEE_INDEX_ELECTRA = 22;
const CURRENT_SYNC_COMMITTEE_DEPTH_ELECTRA = 6;
export function validateLightClientBootstrap(
config: ChainForkConfig,
trustedBlockRoot: Root,
bootstrap: LightClientBootstrap
): void {
const headerRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(bootstrap.header.beacon);
const fork = config.getForkName(bootstrap.header.beacon.slot);
if (!isValidLightClientHeader(config, bootstrap.header)) {
throw Error("Bootstrap Header is not Valid Light Client Header");
}
if (!byteArrayEquals(headerRoot, trustedBlockRoot)) {
throw Error(`bootstrap header root ${toHex(headerRoot)} != trusted root ${toHex(trustedBlockRoot)}`);
}
if (
!isValidMerkleBranch(
ssz.altair.SyncCommittee.hashTreeRoot(bootstrap.currentSyncCommittee),
bootstrap.currentSyncCommitteeBranch,
isForkPostElectra(fork) ? CURRENT_SYNC_COMMITTEE_DEPTH_ELECTRA : CURRENT_SYNC_COMMITTEE_DEPTH,
isForkPostElectra(fork) ? CURRENT_SYNC_COMMITTEE_INDEX_ELECTRA : CURRENT_SYNC_COMMITTEE_INDEX,
bootstrap.header.beacon.stateRoot
)
) {
throw Error("Invalid currentSyncCommittee merkle branch");
}
}