feat: Update to capella fork

This commit is contained in:
Derrick Hammer 2023-06-18 03:19:54 -04:00
parent 5a03605ac8
commit e62eadd436
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
5 changed files with 644 additions and 649 deletions

View File

@ -1,68 +1,64 @@
{
"name": "@lumeweb/kernel-eth",
"version": "0.1.0",
"license": "MIT",
"type": "module",
"scripts": {
"build-script": "tsc --project tsconfig.build.json && mv dist-build/build.js dist-build/build.mjs",
"compile": "npm run build-script && rimraf node_modules/@lumeweb/dht-rpc-client/node_modules node_modules/@lumeweb/kernel-dht-client/node_modules/libkmodule && node build.js",
"build": "npm run compile && node ./dist-build/build.mjs dev"
},
"dependencies": {
"@chainsafe/as-sha256": "^0.3.1",
"@chainsafe/bls": "git+https://git.lumeweb.com/LumeWeb/chainsafe-bls.git",
"@chainsafe/blst": "^0.2.8",
"@chainsafe/ssz": "^0.10.2",
"@ethereumjs/block": "^4.2.1",
"@ethereumjs/blockchain": "^6.2.1",
"@ethereumjs/common": "^3.1.1",
"@ethereumjs/trie": "^5.0.4",
"@ethereumjs/tx": "^4.1.1",
"@ethereumjs/util": "^8.0.5",
"@ethereumjs/vm": "^6.4.1",
"@lodestar/api": "^1.7.2",
"@lodestar/config": "^1.7.2",
"@lodestar/light-client": "^1.7.2",
"@lodestar/types": "^1.7.2",
"@lumeweb/kernel-rpc-client": "git+https://git.lumeweb.com/LumeWeb/kernel-rpc-client.git",
"decimal.js": "^10.4.3",
"ethers": "^6.3.0",
"json-rpc-2.0": "^1.5.1",
"libkmodule": "^0.2.53",
"lodash": "^4.17.21",
"path-browserify": "^1.0.1",
"rlp": "^3.0.0",
"stream-browserify": "^3.0.0",
"web3-core": "^1.9.0",
"web3-core-method": "^1.9.0",
"web3-eth": "^1.9.0",
"yaml": "^2.2.1"
},
"devDependencies": {
"@lumeweb/interface-relay": "git+https://git.lumeweb.com/LumeWeb/interface-relay.git",
"@scure/bip39": "^1.2.0",
"@skynetlabs/skynet-nodejs": "^2.9.0",
"@types/lodash": "^4.14.194",
"@types/node": "^18.15.11",
"@types/read": "^0.0.29",
"buffer": "^6.0.3",
"cli-progress": "^3.12.0",
"crypto-browserify": "^3.12.0",
"esbuild": "^0.17.17",
"esbuild-plugin-wasm": "^1.0.0",
"prettier": "^2.8.7",
"process": "^0.11.10",
"read": "^2.1.0",
"typescript": "^5.0.4"
},
"browser": {
"crypto": "crypto-browserify",
"stream": "stream-browserify",
"path": "path-browserify"
},
"pnpm": {
"overrides": {
"@chainsafe/bls": "git+https://git.lumeweb.com/LumeWeb/chainsafe-bls.git"
"name": "@lumeweb/kernel-eth",
"version": "0.1.0",
"license": "MIT",
"type": "module",
"scripts": {
"build-script": "tsc --project tsconfig.build.json && mv dist-build/build.js dist-build/build.mjs",
"compile": "npm run build-script && rimraf node_modules/@lumeweb/dht-rpc-client/node_modules node_modules/@lumeweb/kernel-dht-client/node_modules/libkmodule && node build.js",
"build": "npm run compile && node ./dist-build/build.mjs dev"
},
"dependencies": {
"@chainsafe/as-sha256": "0.4.1",
"@chainsafe/bls": "git+https://git.lumeweb.com/LumeWeb/chainsafe-bls.git",
"@chainsafe/blst": "^0.2.8",
"@chainsafe/ssz": "0.11.1",
"@ethereumjs/block": "^4.2.1",
"@ethereumjs/blockchain": "^6.2.1",
"@ethereumjs/common": "^3.1.1",
"@ethereumjs/trie": "^5.0.4",
"@ethereumjs/tx": "^4.1.1",
"@ethereumjs/util": "^8.0.5",
"@ethereumjs/vm": "^6.4.1",
"@lodestar/api": "1.7.2",
"@lodestar/config": "1.7.2",
"@lodestar/light-client": "^1.7.2",
"@lodestar/params": "^1.8.0",
"@lodestar/types": "^1.7.2",
"@lumeweb/kernel-rpc-client": "git+https://git.lumeweb.com/LumeWeb/kernel-rpc-client.git",
"decimal.js": "^10.4.3",
"ethers": "^6.3.0",
"json-rpc-2.0": "^1.5.1",
"libkmodule": "^0.2.53",
"lodash": "^4.17.21",
"path-browserify": "^1.0.1",
"rlp": "^3.0.0",
"stream-browserify": "^3.0.0",
"web3-core": "^1.9.0",
"web3-core-method": "^1.9.0",
"web3-eth": "^1.9.0",
"yaml": "^2.2.1"
},
"devDependencies": {
"@lumeweb/interface-relay": "git+https://git.lumeweb.com/LumeWeb/interface-relay.git",
"@scure/bip39": "^1.2.0",
"@skynetlabs/skynet-nodejs": "^2.9.0",
"@types/lodash": "^4.14.194",
"@types/node": "^18.15.11",
"@types/read": "^0.0.29",
"buffer": "^6.0.3",
"cli-progress": "^3.12.0",
"crypto-browserify": "^3.12.0",
"esbuild": "^0.17.17",
"esbuild-plugin-wasm": "^1.0.0",
"prettier": "^2.8.7",
"process": "^0.11.10",
"read": "^2.1.0",
"typescript": "^5.0.4"
},
"browser": {
"crypto": "crypto-browserify",
"stream": "stream-browserify",
"path": "path-browserify"
}
}
}

View File

@ -1,8 +1,6 @@
import {
Bytes32,
ClientConfig,
ExecutionInfo,
LightClientUpdate,
OptimisticUpdate,
VerifyWithReason,
} from "./types.js";
@ -20,21 +18,23 @@ import {
import {
computeSyncPeriodAtSlot,
getCurrentSlot,
isValidMerkleBranch,
} from "@lodestar/light-client/utils";
import {
assertValidLightClientUpdate,
assertValidSignedHeader,
} from "@lodestar/light-client/validation";
import { assertValidSignedHeader } from "@lodestar/light-client/validation";
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 { fromHexString, toHexString } from "@chainsafe/ssz";
import * as altair from "@lodestar/types/altair";
import { fromHexString } from "@chainsafe/ssz";
import * as capella from "@lodestar/types/capella";
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 { 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 {
latestCommittee?: Uint8Array[];
@ -117,29 +117,56 @@ export default class Client {
committee: Uint8Array[],
update: OptimisticUpdate
): Promise<VerifyWithReason> {
const { attestedHeader: header, syncAggregate } = update;
const headerBlockRoot = phase0.ssz.BeaconBlockHeader.hashTreeRoot(
header.beacon
);
const committeeFast = this.deserializeSyncCommittee(committee);
try {
await assertValidSignedHeader(
this.config.chainConfig,
committeeFast,
syncAggregate,
headerBlockRoot,
header.beacon.slot
const { attestedHeader: header, syncAggregate } = update;
const headerBlockRoot = phase0.ssz.BeaconBlockHeader.hashTreeRoot(
header.beacon
);
} catch (e) {
return { correct: false, reason: "invalid signatures" };
}
const committeeFast = this.deserializeSyncCommittee(committee);
try {
assertValidSignedHeader(
this.config.chainConfig,
committeeFast,
syncAggregate,
headerBlockRoot,
header.beacon.slot
);
} catch (e) {
return { correct: false, reason: "invalid signatures" };
}
const participation =
syncAggregate.syncCommitteeBits.getTrueBitIndexes().length;
if (participation < BEACON_SYNC_SUPER_MAJORITY) {
return { correct: false, reason: "insufficient signatures" };
const participation =
syncAggregate.syncCommitteeBits.getTrueBitIndexes().length;
if (participation < BEACON_SYNC_SUPER_MAJORITY) {
return { correct: false, reason: "insufficient signatures" };
}
if (!this.isValidLightClientHeader(this.config.chainConfig, header)) {
return { correct: false, reason: "invalid header" };
}
return { correct: true };
} catch (e) {
console.error(e);
return { correct: false, reason: (e as Error).message };
}
return { correct: true };
}
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(
@ -247,33 +274,9 @@ export default class Client {
console.log(
`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 {
blockhash: blockJSON.execution_payload.block_hash,
blockNumber: blockJSON.execution_payload.block_number,
blockhash: updateJSON.attested_header.execution.block_hash,
blockNumber: updateJSON.attested_header.execution.block_number,
};
}
@ -294,6 +297,6 @@ export default class Client {
return digest(concatUint8Array(committee));
}
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

View File

@ -1,25 +1,22 @@
import {
ContainerType,
VectorCompositeType,
ByteVectorType,
BooleanType,
UintNumberType,
ListCompositeType,
} from '@chainsafe/ssz';
import * as altair from '@lodestar/types/altair';
import { BEACON_SYNC_COMMITTEE_SIZE } from './constants.js';
VectorCompositeType,
} from "@chainsafe/ssz";
import * as capella from "@lodestar/types/capella";
import { BEACON_SYNC_COMMITTEE_SIZE } from "./constants.js";
const MAX_BATCHSIZE = 10000;
export const LightClientUpdateSSZ = altair.ssz.LightClientUpdate;
export const LightClientUpdateSSZ = capella.ssz.LightClientUpdate;
export const LightClientUpdatesSSZ = new ListCompositeType(
LightClientUpdateSSZ as any,
MAX_BATCHSIZE,
MAX_BATCHSIZE
);
export const CommitteeSSZ = new VectorCompositeType(
new ByteVectorType(48),
BEACON_SYNC_COMMITTEE_SIZE,
BEACON_SYNC_COMMITTEE_SIZE
);
const HashSSZ = new ByteVectorType(32);

View File

@ -1,13 +1,12 @@
import { routes } from "@lodestar/api";
import * as capella from "@lodestar/types/capella";
import { BeaconConfig } from "@lodestar/config";
import * as altair from "@lodestar/types/altair";
export type PubKeyString = string;
export type Slot = number;
export type Bytes32 = string;
export type OptimisticUpdate = altair.LightClientOptimisticUpdate;
export type LightClientUpdate = altair.LightClientUpdate;
export type OptimisticUpdate = capella.LightClientOptimisticUpdate;
export type LightClientUpdate = capella.LightClientUpdate;
export type GenesisData = {
committee: PubKeyString[];