feat: Update to capella fork
This commit is contained in:
parent
5a03605ac8
commit
e62eadd436
14
package.json
14
package.json
|
@ -9,10 +9,10 @@
|
||||||
"build": "npm run compile && node ./dist-build/build.mjs dev"
|
"build": "npm run compile && node ./dist-build/build.mjs dev"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@chainsafe/as-sha256": "^0.3.1",
|
"@chainsafe/as-sha256": "0.4.1",
|
||||||
"@chainsafe/bls": "git+https://git.lumeweb.com/LumeWeb/chainsafe-bls.git",
|
"@chainsafe/bls": "git+https://git.lumeweb.com/LumeWeb/chainsafe-bls.git",
|
||||||
"@chainsafe/blst": "^0.2.8",
|
"@chainsafe/blst": "^0.2.8",
|
||||||
"@chainsafe/ssz": "^0.10.2",
|
"@chainsafe/ssz": "0.11.1",
|
||||||
"@ethereumjs/block": "^4.2.1",
|
"@ethereumjs/block": "^4.2.1",
|
||||||
"@ethereumjs/blockchain": "^6.2.1",
|
"@ethereumjs/blockchain": "^6.2.1",
|
||||||
"@ethereumjs/common": "^3.1.1",
|
"@ethereumjs/common": "^3.1.1",
|
||||||
|
@ -20,9 +20,10 @@
|
||||||
"@ethereumjs/tx": "^4.1.1",
|
"@ethereumjs/tx": "^4.1.1",
|
||||||
"@ethereumjs/util": "^8.0.5",
|
"@ethereumjs/util": "^8.0.5",
|
||||||
"@ethereumjs/vm": "^6.4.1",
|
"@ethereumjs/vm": "^6.4.1",
|
||||||
"@lodestar/api": "^1.7.2",
|
"@lodestar/api": "1.7.2",
|
||||||
"@lodestar/config": "^1.7.2",
|
"@lodestar/config": "1.7.2",
|
||||||
"@lodestar/light-client": "^1.7.2",
|
"@lodestar/light-client": "^1.7.2",
|
||||||
|
"@lodestar/params": "^1.8.0",
|
||||||
"@lodestar/types": "^1.7.2",
|
"@lodestar/types": "^1.7.2",
|
||||||
"@lumeweb/kernel-rpc-client": "git+https://git.lumeweb.com/LumeWeb/kernel-rpc-client.git",
|
"@lumeweb/kernel-rpc-client": "git+https://git.lumeweb.com/LumeWeb/kernel-rpc-client.git",
|
||||||
"decimal.js": "^10.4.3",
|
"decimal.js": "^10.4.3",
|
||||||
|
@ -59,10 +60,5 @@
|
||||||
"crypto": "crypto-browserify",
|
"crypto": "crypto-browserify",
|
||||||
"stream": "stream-browserify",
|
"stream": "stream-browserify",
|
||||||
"path": "path-browserify"
|
"path": "path-browserify"
|
||||||
},
|
|
||||||
"pnpm": {
|
|
||||||
"overrides": {
|
|
||||||
"@chainsafe/bls": "git+https://git.lumeweb.com/LumeWeb/chainsafe-bls.git"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import {
|
import {
|
||||||
Bytes32,
|
|
||||||
ClientConfig,
|
ClientConfig,
|
||||||
ExecutionInfo,
|
ExecutionInfo,
|
||||||
LightClientUpdate,
|
|
||||||
OptimisticUpdate,
|
OptimisticUpdate,
|
||||||
VerifyWithReason,
|
VerifyWithReason,
|
||||||
} from "./types.js";
|
} from "./types.js";
|
||||||
|
@ -20,21 +18,23 @@ import {
|
||||||
import {
|
import {
|
||||||
computeSyncPeriodAtSlot,
|
computeSyncPeriodAtSlot,
|
||||||
getCurrentSlot,
|
getCurrentSlot,
|
||||||
|
isValidMerkleBranch,
|
||||||
} from "@lodestar/light-client/utils";
|
} from "@lodestar/light-client/utils";
|
||||||
import {
|
import { assertValidSignedHeader } from "@lodestar/light-client/validation";
|
||||||
assertValidLightClientUpdate,
|
|
||||||
assertValidSignedHeader,
|
|
||||||
} from "@lodestar/light-client/validation";
|
|
||||||
import { SyncCommitteeFast } from "@lodestar/light-client";
|
import { SyncCommitteeFast } from "@lodestar/light-client";
|
||||||
import bls from "@chainsafe/bls/switchable";
|
import bls, { init } from "@chainsafe/bls/switchable";
|
||||||
import { PublicKey } from "@chainsafe/bls/types.js";
|
import { PublicKey } from "@chainsafe/bls/types.js";
|
||||||
import { fromHexString, toHexString } from "@chainsafe/ssz";
|
import { fromHexString } from "@chainsafe/ssz";
|
||||||
import * as altair from "@lodestar/types/altair";
|
import * as capella from "@lodestar/types/capella";
|
||||||
import * as phase0 from "@lodestar/types/phase0";
|
import * as phase0 from "@lodestar/types/phase0";
|
||||||
import * as bellatrix from "@lodestar/types/bellatrix";
|
|
||||||
import { init } from "@chainsafe/bls/switchable";
|
|
||||||
import { VerifyingProvider } from "./rpc/provider.js";
|
import { VerifyingProvider } from "./rpc/provider.js";
|
||||||
import { digest } from "@chainsafe/as-sha256";
|
import { digest } from "@chainsafe/as-sha256";
|
||||||
|
import { ChainForkConfig } from "@lodestar/config";
|
||||||
|
import { allForks } from "@lodestar/types";
|
||||||
|
import {
|
||||||
|
BLOCK_BODY_EXECUTION_PAYLOAD_DEPTH as EXECUTION_PAYLOAD_DEPTH,
|
||||||
|
BLOCK_BODY_EXECUTION_PAYLOAD_INDEX as EXECUTION_PAYLOAD_INDEX,
|
||||||
|
} from "@lodestar/params";
|
||||||
|
|
||||||
export default class Client {
|
export default class Client {
|
||||||
latestCommittee?: Uint8Array[];
|
latestCommittee?: Uint8Array[];
|
||||||
|
@ -117,13 +117,14 @@ export default class Client {
|
||||||
committee: Uint8Array[],
|
committee: Uint8Array[],
|
||||||
update: OptimisticUpdate
|
update: OptimisticUpdate
|
||||||
): Promise<VerifyWithReason> {
|
): Promise<VerifyWithReason> {
|
||||||
|
try {
|
||||||
const { attestedHeader: header, syncAggregate } = update;
|
const { attestedHeader: header, syncAggregate } = update;
|
||||||
const headerBlockRoot = phase0.ssz.BeaconBlockHeader.hashTreeRoot(
|
const headerBlockRoot = phase0.ssz.BeaconBlockHeader.hashTreeRoot(
|
||||||
header.beacon
|
header.beacon
|
||||||
);
|
);
|
||||||
const committeeFast = this.deserializeSyncCommittee(committee);
|
const committeeFast = this.deserializeSyncCommittee(committee);
|
||||||
try {
|
try {
|
||||||
await assertValidSignedHeader(
|
assertValidSignedHeader(
|
||||||
this.config.chainConfig,
|
this.config.chainConfig,
|
||||||
committeeFast,
|
committeeFast,
|
||||||
syncAggregate,
|
syncAggregate,
|
||||||
|
@ -139,7 +140,33 @@ export default class Client {
|
||||||
if (participation < BEACON_SYNC_SUPER_MAJORITY) {
|
if (participation < BEACON_SYNC_SUPER_MAJORITY) {
|
||||||
return { correct: false, reason: "insufficient signatures" };
|
return { correct: false, reason: "insufficient signatures" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.isValidLightClientHeader(this.config.chainConfig, header)) {
|
||||||
|
return { correct: false, reason: "invalid header" };
|
||||||
|
}
|
||||||
|
|
||||||
return { correct: true };
|
return { correct: true };
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return { correct: false, reason: (e as Error).message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private isValidLightClientHeader(
|
||||||
|
config: ChainForkConfig,
|
||||||
|
header: allForks.LightClientHeader
|
||||||
|
): boolean {
|
||||||
|
return isValidMerkleBranch(
|
||||||
|
config
|
||||||
|
.getExecutionForkTypes(header.beacon.slot)
|
||||||
|
.ExecutionPayloadHeader.hashTreeRoot(
|
||||||
|
(header as capella.LightClientHeader).execution
|
||||||
|
),
|
||||||
|
(header as capella.LightClientHeader).executionBranch,
|
||||||
|
EXECUTION_PAYLOAD_DEPTH,
|
||||||
|
EXECUTION_PAYLOAD_INDEX,
|
||||||
|
header.beacon.bodyRoot
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getNextValidExecutionInfo(
|
public async getNextValidExecutionInfo(
|
||||||
|
@ -247,33 +274,9 @@ export default class Client {
|
||||||
console.log(
|
console.log(
|
||||||
`Optimistic update verified for slot ${updateJSON.attested_header.beacon.slot}`
|
`Optimistic update verified for slot ${updateJSON.attested_header.beacon.slot}`
|
||||||
);
|
);
|
||||||
return this.getExecutionFromBlockRoot(
|
|
||||||
updateJSON.attested_header.beacon.slot,
|
|
||||||
updateJSON.attested_header.beacon.body_root
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getExecutionFromBlockRoot(
|
|
||||||
slot: bigint,
|
|
||||||
expectedBlockRoot: Bytes32
|
|
||||||
): Promise<ExecutionInfo> {
|
|
||||||
const res = await this.prover.callback("consensus_block", {
|
|
||||||
block: slot,
|
|
||||||
});
|
|
||||||
const blockJSON = res.message.body;
|
|
||||||
const block = bellatrix.ssz.BeaconBlockBody.fromJson(blockJSON);
|
|
||||||
const blockRoot = toHexString(
|
|
||||||
bellatrix.ssz.BeaconBlockBody.hashTreeRoot(block)
|
|
||||||
);
|
|
||||||
if (blockRoot !== expectedBlockRoot) {
|
|
||||||
throw Error(
|
|
||||||
`block provided by the beacon chain api doesn't match the expected block root`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
blockhash: blockJSON.execution_payload.block_hash,
|
blockhash: updateJSON.attested_header.execution.block_hash,
|
||||||
blockNumber: blockJSON.execution_payload.block_number,
|
blockNumber: updateJSON.attested_header.execution.block_number,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,6 +297,6 @@ export default class Client {
|
||||||
return digest(concatUint8Array(committee));
|
return digest(concatUint8Array(committee));
|
||||||
}
|
}
|
||||||
private optimisticUpdateFromJSON(update: any): OptimisticUpdate {
|
private optimisticUpdateFromJSON(update: any): OptimisticUpdate {
|
||||||
return altair.ssz.LightClientOptimisticUpdate.fromJson(update);
|
return capella.ssz.LightClientOptimisticUpdate.fromJson(update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,25 +1,22 @@
|
||||||
import {
|
import {
|
||||||
ContainerType,
|
|
||||||
VectorCompositeType,
|
|
||||||
ByteVectorType,
|
ByteVectorType,
|
||||||
BooleanType,
|
|
||||||
UintNumberType,
|
|
||||||
ListCompositeType,
|
ListCompositeType,
|
||||||
} from '@chainsafe/ssz';
|
VectorCompositeType,
|
||||||
import * as altair from '@lodestar/types/altair';
|
} from "@chainsafe/ssz";
|
||||||
import { BEACON_SYNC_COMMITTEE_SIZE } from './constants.js';
|
import * as capella from "@lodestar/types/capella";
|
||||||
|
import { BEACON_SYNC_COMMITTEE_SIZE } from "./constants.js";
|
||||||
|
|
||||||
const MAX_BATCHSIZE = 10000;
|
const MAX_BATCHSIZE = 10000;
|
||||||
|
|
||||||
export const LightClientUpdateSSZ = altair.ssz.LightClientUpdate;
|
export const LightClientUpdateSSZ = capella.ssz.LightClientUpdate;
|
||||||
export const LightClientUpdatesSSZ = new ListCompositeType(
|
export const LightClientUpdatesSSZ = new ListCompositeType(
|
||||||
LightClientUpdateSSZ as any,
|
LightClientUpdateSSZ as any,
|
||||||
MAX_BATCHSIZE,
|
MAX_BATCHSIZE
|
||||||
);
|
);
|
||||||
|
|
||||||
export const CommitteeSSZ = new VectorCompositeType(
|
export const CommitteeSSZ = new VectorCompositeType(
|
||||||
new ByteVectorType(48),
|
new ByteVectorType(48),
|
||||||
BEACON_SYNC_COMMITTEE_SIZE,
|
BEACON_SYNC_COMMITTEE_SIZE
|
||||||
);
|
);
|
||||||
|
|
||||||
const HashSSZ = new ByteVectorType(32);
|
const HashSSZ = new ByteVectorType(32);
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import { routes } from "@lodestar/api";
|
import * as capella from "@lodestar/types/capella";
|
||||||
import { BeaconConfig } from "@lodestar/config";
|
import { BeaconConfig } from "@lodestar/config";
|
||||||
import * as altair from "@lodestar/types/altair";
|
|
||||||
|
|
||||||
export type PubKeyString = string;
|
export type PubKeyString = string;
|
||||||
export type Slot = number;
|
export type Slot = number;
|
||||||
export type Bytes32 = string;
|
export type Bytes32 = string;
|
||||||
|
|
||||||
export type OptimisticUpdate = altair.LightClientOptimisticUpdate;
|
export type OptimisticUpdate = capella.LightClientOptimisticUpdate;
|
||||||
export type LightClientUpdate = altair.LightClientUpdate;
|
export type LightClientUpdate = capella.LightClientUpdate;
|
||||||
|
|
||||||
export type GenesisData = {
|
export type GenesisData = {
|
||||||
committee: PubKeyString[];
|
committee: PubKeyString[];
|
||||||
|
|
Loading…
Reference in New Issue