Skip to content

Commit

Permalink
Add types
Browse files Browse the repository at this point in the history
Update state transition

Fix tests

Add fork to LC tests

rebase fixes

get the types to match current kaustinen network

insert verge between capella and deneb

add payload to execution witness

working local build with kaunstinen v2 geth build

use electra in config

few corrections

fix build

integrated ssz with optional

deep log witness

fix serialization for new payload

rename verge to electra and fix upgrade issues and transition banner

fix type issues

add parent stateroot to witness

rebase fixes

rename electra to verkle
  • Loading branch information
g11tech committed Sep 7, 2024
1 parent b05c93e commit 090f48d
Show file tree
Hide file tree
Showing 33 changed files with 634 additions and 48 deletions.
20 changes: 20 additions & 0 deletions packages/beacon-node/src/chain/blocks/utils/elephantWithWings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const VERKLE_ELEPHANTWITHWINGS_BANNER = String.raw`
:~~.
:!:^::^^!!^
:!^^ !:J.
.!!:! .^7^
.?7~: ^#! !!!^!~.
:!^ GP~..^^?^ ^!:
!^ Y5 #7:
.:^^~7~. ! ~~6800~~^ ^6800^ ~~6800 68 00 68~~ 00~ ||
.~! 55J ~~6800~~ :! !^ .YP :JP 7B. ^7#
^7 :: 5 #:::^::~~6800~~^^?!?.~:: :! !^ 6800 .^PJ JG ~!B
:G ^7 ^ !^68 00^ ~~6800~~ :! !: .&~ ^#! ^!55~~~6800~~7G~ !7B
7G ~!5J ^? !.----. ~! ~~6800~~ .7#: 6800 ~
?G :^?G. ...... ^?^.!G. ?G :^?G. ...... ^?^.!G. !
~! ~~6800~~ .7#: 6800 G~ 7G ~!5J ^? !.----. ::
:! !: .&~ ^#! ^!55~~~6800~~7G~ !7B :G ^7 ^ !^68 00^ ~~6800~~ ::
:! !^ 6800 .^PJ JG ~!B ^7 :: 5 ^^ !!!! #:::^::~~6800~~^^?!?.~
:! !^ .YP :JP 7B. ^7# .~!~ ~~6800 ^6800^ ~~6800~~
6800 68 00 68~~ 00~ 6800
`;
6 changes: 6 additions & 0 deletions packages/beacon-node/src/chain/blocks/verifyBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {BlockInput, ImportBlockOpts, BlockInputType} from "./types.js";
import {POS_PANDA_MERGE_TRANSITION_BANNER} from "./utils/pandaMergeTransitionBanner.js";
import {CAPELLA_OWL_BANNER} from "./utils/ownBanner.js";
import {DENEB_BLOWFISH_BANNER} from "./utils/blowfishBanner.js";
import {VERKLE_ELEPHANTWITHWINGS_BANNER} from "./utils/elephantWithWings.js";
import {verifyBlocksStateTransitionOnly} from "./verifyBlocksStateTransitionOnly.js";
import {verifyBlocksSignatures} from "./verifyBlocksSignatures.js";
import {verifyBlocksExecutionPayload, SegmentExecStatus} from "./verifyBlocksExecutionPayloads.js";
Expand Down Expand Up @@ -152,6 +153,11 @@ export async function verifyBlocksInEpoch(
this.logger.info("Activating withdrawals", {epoch: this.config.CAPELLA_FORK_EPOCH});
break;

case ForkName.verkle:
this.logger.info(VERKLE_ELEPHANTWITHWINGS_BANNER);
this.logger.info("Activating verkle", {epoch: this.config.VERKLE_FORK_EPOCH});
break;

case ForkName.deneb:
this.logger.info(DENEB_BLOWFISH_BANNER);
this.logger.info("Activating blobs", {epoch: this.config.DENEB_FORK_EPOCH});
Expand Down
26 changes: 25 additions & 1 deletion packages/beacon-node/src/execution/engine/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {capella, deneb, electra, Wei, bellatrix, Root, ExecutionPayload} from "@lodestar/types";
import {capella, deneb, Wei, bellatrix, Root, verkle, electra, ExecutionPayload, ssz} from "@lodestar/types";
import {
BYTES_PER_LOGS_BLOOM,
FIELD_ELEMENTS_PER_BLOB,
Expand Down Expand Up @@ -166,6 +166,7 @@ export type ExecutionPayloadRpc = {
depositRequests?: DepositRequestRpc[]; // ELECTRA
withdrawalRequests?: WithdrawalRequestRpc[]; // ELECTRA
consolidationRequests?: ConsolidationRequestRpc[]; // ELECTRA
executionWitness?: Record<string, unknown>; // DENEB
};

export type WithdrawalRpc = {
Expand Down Expand Up @@ -234,6 +235,20 @@ export function serializeExecutionPayload(fork: ForkName, data: ExecutionPayload
payload.withdrawals = withdrawals.map(serializeWithdrawal);
}

// VERKLE adds executionWitness to the ExecutionPayload
if (ForkSeq[fork] >= ForkSeq.verkle) {
const {executionWitness} = data as verkle.ExecutionPayload;
// right now the caseMap of ssz ExecutionWitness is camel cased and can
// directly be used to serialize tojson
payload.executionWitness = ssz.verkle.ExecutionWitness.toJson(executionWitness);
// serialization with ssz serialize suffix diff's suffix to a string while geth expects num
(payload.executionWitness as verkle.ExecutionWitness).stateDiff.forEach((sDiff) => {
sDiff.suffixDiffs.forEach((sfDiff) => {
sfDiff.suffix = Number(sfDiff.suffix);
});
});
}

// DENEB adds blobGasUsed & excessBlobGas to the ExecutionPayload
if (ForkSeq[fork] >= ForkSeq.deneb) {
const {blobGasUsed, excessBlobGas} = data as deneb.ExecutionPayload;
Expand Down Expand Up @@ -315,6 +330,15 @@ export function parseExecutionPayload(
(executionPayload as capella.ExecutionPayload).withdrawals = withdrawals.map((w) => deserializeWithdrawal(w));
}

// VERKLE adds execution witness to the payload
if (ForkSeq[fork] >= ForkSeq.verkle) {
// right now the casing of executionWitness is camel case in the ssz caseMap
// we can directly use fromJson to read the serialized data from payload
const {executionWitness} = data;
(executionPayload as verkle.ExecutionPayload).executionWitness =
ssz.verkle.ExecutionWitness.fromJson(executionWitness);
}

// DENEB adds excessBlobGas to the ExecutionPayload
if (ForkSeq[fork] >= ForkSeq.deneb) {
const {blobGasUsed, excessBlobGas} = data;
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/test/sim/electra-interop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ describe("executionEngine / ExecutionEngineHttp", function () {
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
VERKLE_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: electraEpoch,
TERMINAL_TOTAL_DIFFICULTY: ttd,
Expand Down
5 changes: 4 additions & 1 deletion packages/beacon-node/test/spec/presets/fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CachedBeaconStateAltair,
CachedBeaconStatePhase0,
CachedBeaconStateCapella,
CachedBeaconStateVerkle,
CachedBeaconStateDeneb,
} from "@lodestar/state-transition";
import * as slotFns from "@lodestar/state-transition/slot";
Expand Down Expand Up @@ -34,8 +35,10 @@ const fork: TestRunnerFn<ForkStateCase, BeaconStateAllForks> = (forkNext) => {
return slotFns.upgradeStateToBellatrix(preState as CachedBeaconStateAltair);
case ForkName.capella:
return slotFns.upgradeStateToCapella(preState as CachedBeaconStateBellatrix);
case ForkName.verkle:
return slotFns.upgradeStateToVerkle(preState as CachedBeaconStateCapella);
case ForkName.deneb:
return slotFns.upgradeStateToDeneb(preState as CachedBeaconStateCapella);
return slotFns.upgradeStateToDeneb(preState as CachedBeaconStateVerkle);
case ForkName.electra:
return slotFns.upgradeStateToElectra(preState as CachedBeaconStateDeneb);
}
Expand Down
17 changes: 16 additions & 1 deletion packages/beacon-node/test/spec/presets/transition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,28 @@ function getTransitionConfig(fork: ForkName, forkEpoch: number): Partial<ChainCo
return {ALTAIR_FORK_EPOCH: 0, BELLATRIX_FORK_EPOCH: forkEpoch};
case ForkName.capella:
return {ALTAIR_FORK_EPOCH: 0, BELLATRIX_FORK_EPOCH: 0, CAPELLA_FORK_EPOCH: forkEpoch};
case ForkName.verkle:
return {
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
VERKLE_FORK_EPOCH: forkEpoch,
};
case ForkName.deneb:
return {ALTAIR_FORK_EPOCH: 0, BELLATRIX_FORK_EPOCH: 0, CAPELLA_FORK_EPOCH: 0, DENEB_FORK_EPOCH: forkEpoch};
return {
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
VERKLE_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: forkEpoch,
};

case ForkName.electra:
return {
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
VERKLE_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: forkEpoch,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ describe("UpgradeLightClientHeader", function () {
ALTAIR_FORK_EPOCH: 1,
BELLATRIX_FORK_EPOCH: 2,
CAPELLA_FORK_EPOCH: 3,
DENEB_FORK_EPOCH: 4,
ELECTRA_FORK_EPOCH: 5,
VERKLE_FORK_EPOCH: 4,
DENEB_FORK_EPOCH: 5,
ELECTRA_FORK_EPOCH: 6,
});

const genesisValidatorsRoot = Buffer.alloc(32, 0xaa);
Expand All @@ -27,6 +28,7 @@ describe("UpgradeLightClientHeader", function () {
altair: ssz.altair.LightClientHeader.defaultValue(),
capella: ssz.capella.LightClientHeader.defaultValue(),
bellatrix: ssz.altair.LightClientHeader.defaultValue(),
verkle: ssz.verkle.LightClientHeader.defaultValue(),
deneb: ssz.deneb.LightClientHeader.defaultValue(),
electra: ssz.electra.LightClientHeader.defaultValue(),
};
Expand All @@ -36,8 +38,9 @@ describe("UpgradeLightClientHeader", function () {
altair: 10,
bellatrix: 17,
capella: 25,
deneb: 33,
electra: 41,
verkle: 33,
deneb: 41,
electra: 49,
};
});

Expand Down
23 changes: 17 additions & 6 deletions packages/beacon-node/test/unit/network/fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ function getForkConfig({
altair,
bellatrix,
capella,
verkle,
deneb,
electra,
}: {
phase0: number;
altair: number;
bellatrix: number;
capella: number;
verkle: number;
deneb: number;
electra: number;
}): BeaconConfig {
Expand Down Expand Up @@ -51,20 +53,28 @@ function getForkConfig({
prevVersion: Buffer.from([0, 0, 0, 2]),
prevForkName: ForkName.bellatrix,
},
verkle: {
name: ForkName.verkle,
seq: ForkSeq.verkle,
epoch: verkle,
version: Buffer.from([0, 0, 0, 4]),
prevVersion: Buffer.from([0, 0, 0, 3]),
prevForkName: ForkName.capella,
},
deneb: {
name: ForkName.deneb,
seq: ForkSeq.deneb,
epoch: deneb,
version: Buffer.from([0, 0, 0, 4]),
prevVersion: Buffer.from([0, 0, 0, 3]),
prevForkName: ForkName.capella,
version: Buffer.from([0, 0, 0, 5]),
prevVersion: Buffer.from([0, 0, 0, 4]),
prevForkName: ForkName.verkle,
},
electra: {
name: ForkName.electra,
seq: ForkSeq.electra,
epoch: electra,
version: Buffer.from([0, 0, 0, 5]),
prevVersion: Buffer.from([0, 0, 0, 4]),
version: Buffer.from([0, 0, 0, 6]),
prevVersion: Buffer.from([0, 0, 0, 5]),
prevForkName: ForkName.deneb,
},
};
Expand Down Expand Up @@ -142,11 +152,12 @@ const testScenarios = [

for (const testScenario of testScenarios) {
const {phase0, altair, bellatrix, capella, testCases} = testScenario;
const verkle = Infinity;
const deneb = Infinity;
const electra = Infinity;

describe(`network / fork: phase0: ${phase0}, altair: ${altair}, bellatrix: ${bellatrix} capella: ${capella}`, () => {
const forkConfig = getForkConfig({phase0, altair, bellatrix, capella, deneb, electra});
const forkConfig = getForkConfig({phase0, altair, bellatrix, capella, verkle, deneb, electra});
const forks = forkConfig.forks;
for (const testCase of testCases) {
const {epoch, currentFork, nextFork, activeForks} = testCase;
Expand Down
9 changes: 9 additions & 0 deletions packages/beacon-node/test/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,27 @@ export function getConfig(fork: ForkName, forkEpoch = 0): ChainForkConfig {
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: forkEpoch,
});
case ForkName.verkle:
return createChainForkConfig({
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
VERKLE_FORK_EPOCH: forkEpoch,
});
case ForkName.deneb:
return createChainForkConfig({
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
VERKLE_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: forkEpoch,
});
case ForkName.electra:
return createChainForkConfig({
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
VERKLE_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: forkEpoch,
});
Expand Down
10 changes: 7 additions & 3 deletions packages/config/src/chainConfig/configs/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ export const chainConfig: ChainConfig = {
CAPELLA_FORK_VERSION: b("0x03000000"),
CAPELLA_FORK_EPOCH: 194048, // April 12 (epoch: 194048 slot: 6209536 UTC: 4/12/2023, 10:27:35 PM)

// VERKLE
VERKLE_FORK_VERSION: b("0x04000000"),
VERKLE_FORK_EPOCH: Infinity,

// Deneb
DENEB_FORK_VERSION: b("0x04000000"),
DENEB_FORK_EPOCH: 269568, // March 13, 2024, 01:55:35pm UTC
DENEB_FORK_VERSION: b("0x05000000"),
DENEB_FORK_EPOCH: Infinity,

// ELECTRA
ELECTRA_FORK_VERSION: b("0x05000000"),
ELECTRA_FORK_VERSION: b("0x06000000"),
ELECTRA_FORK_EPOCH: Infinity,

// Time parameters
Expand Down
7 changes: 5 additions & 2 deletions packages/config/src/chainConfig/configs/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ export const chainConfig: ChainConfig = {
// Capella
CAPELLA_FORK_VERSION: b("0x03000001"),
CAPELLA_FORK_EPOCH: Infinity,
// Verkle
VERKLE_FORK_VERSION: b("0x04000001"),
VERKLE_FORK_EPOCH: Infinity,
// Deneb
DENEB_FORK_VERSION: b("0x04000001"),
DENEB_FORK_VERSION: b("0x05000001"),
DENEB_FORK_EPOCH: Infinity,
// ELECTRA
ELECTRA_FORK_VERSION: b("0x05000001"),
ELECTRA_FORK_VERSION: b("0x06000001"),
ELECTRA_FORK_EPOCH: Infinity,

// Time parameters
Expand Down
6 changes: 6 additions & 0 deletions packages/config/src/chainConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export type ChainConfig = {
// Capella
CAPELLA_FORK_VERSION: Uint8Array;
CAPELLA_FORK_EPOCH: number;
// VERKLE
VERKLE_FORK_VERSION: Uint8Array;
VERKLE_FORK_EPOCH: number;
// DENEB
DENEB_FORK_VERSION: Uint8Array;
DENEB_FORK_EPOCH: number;
Expand Down Expand Up @@ -101,6 +104,9 @@ export const chainConfigTypes: SpecTypes<ChainConfig> = {
// Capella
CAPELLA_FORK_VERSION: "bytes",
CAPELLA_FORK_EPOCH: "number",
// VERKLE
VERKLE_FORK_VERSION: "bytes",
VERKLE_FORK_EPOCH: "number",
// DENEB
DENEB_FORK_VERSION: "bytes",
DENEB_FORK_EPOCH: "number",
Expand Down
14 changes: 11 additions & 3 deletions packages/config/src/forkConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,21 @@ export function createForkConfig(config: ChainConfig): ForkConfig {
prevVersion: config.BELLATRIX_FORK_VERSION,
prevForkName: ForkName.bellatrix,
};
const verkle: ForkInfo = {
name: ForkName.verkle,
seq: ForkSeq.verkle,
epoch: config.VERKLE_FORK_EPOCH,
version: config.VERKLE_FORK_VERSION,
prevVersion: config.CAPELLA_FORK_VERSION,
prevForkName: ForkName.capella,
};
const deneb: ForkInfo = {
name: ForkName.deneb,
seq: ForkSeq.deneb,
epoch: config.DENEB_FORK_EPOCH,
version: config.DENEB_FORK_VERSION,
prevVersion: config.CAPELLA_FORK_VERSION,
prevForkName: ForkName.capella,
prevVersion: config.VERKLE_FORK_VERSION,
prevForkName: ForkName.verkle,
};
const electra: ForkInfo = {
name: ForkName.electra,
Expand All @@ -70,7 +78,7 @@ export function createForkConfig(config: ChainConfig): ForkConfig {

/** Forks in order order of occurence, `phase0` first */
// Note: Downstream code relies on proper ordering.
const forks = {phase0, altair, bellatrix, capella, deneb, electra};
const forks = {phase0, altair, bellatrix, capella, verkle, deneb, electra};

// Prevents allocating an array on every getForkInfo() call
const forksAscendingEpochOrder = Object.values(forks);
Expand Down
Loading

0 comments on commit 090f48d

Please sign in to comment.