From 0d60dd0f944837f148e44869916e222d8265a3c5 Mon Sep 17 00:00:00 2001 From: tuyennhv Date: Wed, 13 Sep 2023 16:47:34 +0700 Subject: [PATCH] chore: copy latest ssz types from lodestar (#333) * chore: copy latest lodestarTypes * chore: spec test v1.4.0-beta.1 * fix: add missing types --- .../ssz/test/lodestarTypes/allForks/index.ts | 1 + .../test/lodestarTypes/allForks/sszTypes.ts | 131 ++++++- .../ssz/test/lodestarTypes/allForks/types.ts | 242 +++++++++++- .../ssz/test/lodestarTypes/altair/index.ts | 1 + .../ssz/test/lodestarTypes/altair/sszTypes.ts | 81 ++-- .../ssz/test/lodestarTypes/altair/types.ts | 7 +- .../ssz/test/lodestarTypes/bellatrix/index.ts | 1 + .../test/lodestarTypes/bellatrix/sszTypes.ts | 148 ++++++-- .../ssz/test/lodestarTypes/bellatrix/types.ts | 13 + .../ssz/test/lodestarTypes/capella/index.ts | 3 + .../test/lodestarTypes/capella/sszTypes.ts | 279 ++++++++++++++ .../ssz/test/lodestarTypes/capella/types.ts | 33 ++ .../ssz/test/lodestarTypes/deneb/index.ts | 3 + .../ssz/test/lodestarTypes/deneb/sszTypes.ts | 352 ++++++++++++++++++ .../ssz/test/lodestarTypes/deneb/types.ts | 52 +++ packages/ssz/test/lodestarTypes/index.ts | 4 + packages/ssz/test/lodestarTypes/params.ts | 83 +++-- .../ssz/test/lodestarTypes/phase0/index.ts | 1 + .../ssz/test/lodestarTypes/phase0/sszTypes.ts | 104 +++++- .../ssz/test/lodestarTypes/phase0/types.ts | 7 +- .../test/lodestarTypes/primitive/sszTypes.ts | 31 +- .../ssz/test/lodestarTypes/primitive/types.ts | 5 + packages/ssz/test/lodestarTypes/sszTypes.ts | 6 + packages/ssz/test/lodestarTypes/types.ts | 13 + .../test/lodestarTypes/utils/StringType.ts | 55 +++ .../ssz/test/lodestarTypes/utils/lazyVar.ts | 12 - .../test/lodestarTypes/utils/typeguards.ts | 43 +++ packages/ssz/test/specTestVersioning.ts | 2 +- packages/ssz/test/unit/eth2/allForks.test.ts | 13 +- .../ssz/test/unit/eth2/minMaxSize.test.ts | 26 +- 30 files changed, 1620 insertions(+), 132 deletions(-) create mode 100644 packages/ssz/test/lodestarTypes/capella/index.ts create mode 100644 packages/ssz/test/lodestarTypes/capella/sszTypes.ts create mode 100644 packages/ssz/test/lodestarTypes/capella/types.ts create mode 100644 packages/ssz/test/lodestarTypes/deneb/index.ts create mode 100644 packages/ssz/test/lodestarTypes/deneb/sszTypes.ts create mode 100644 packages/ssz/test/lodestarTypes/deneb/types.ts create mode 100644 packages/ssz/test/lodestarTypes/utils/StringType.ts delete mode 100644 packages/ssz/test/lodestarTypes/utils/lazyVar.ts create mode 100644 packages/ssz/test/lodestarTypes/utils/typeguards.ts diff --git a/packages/ssz/test/lodestarTypes/allForks/index.ts b/packages/ssz/test/lodestarTypes/allForks/index.ts index 0a5a5875..a1361536 100644 --- a/packages/ssz/test/lodestarTypes/allForks/index.ts +++ b/packages/ssz/test/lodestarTypes/allForks/index.ts @@ -1,2 +1,3 @@ +export * from "./types"; export * as ts from "./types"; export * as ssz from "./sszTypes"; diff --git a/packages/ssz/test/lodestarTypes/allForks/sszTypes.ts b/packages/ssz/test/lodestarTypes/allForks/sszTypes.ts index d2c289b1..8e360d51 100644 --- a/packages/ssz/test/lodestarTypes/allForks/sszTypes.ts +++ b/packages/ssz/test/lodestarTypes/allForks/sszTypes.ts @@ -1,8 +1,8 @@ -/* eslint-disable @typescript-eslint/naming-convention */ - import {ssz as phase0} from "../phase0"; import {ssz as altair} from "../altair"; import {ssz as bellatrix} from "../bellatrix"; +import {ssz as capella} from "../capella"; +import {ssz as deneb} from "../deneb"; /** * Index the ssz types that differ by fork @@ -30,4 +30,131 @@ export const allForks = { BeaconState: bellatrix.BeaconState, Metadata: altair.Metadata, }, + capella: { + BeaconBlockBody: capella.BeaconBlockBody, + BeaconBlock: capella.BeaconBlock, + SignedBeaconBlock: capella.SignedBeaconBlock, + BeaconState: capella.BeaconState, + Metadata: altair.Metadata, + }, + deneb: { + BeaconBlockBody: deneb.BeaconBlockBody, + BeaconBlock: deneb.BeaconBlock, + SignedBeaconBlock: deneb.SignedBeaconBlock, + BeaconState: deneb.BeaconState, + Metadata: altair.Metadata, + }, +}; + +/** + * Index the execution ssz types that differ by fork + * A record of AllForksExecutionSSZTypes indexed by fork + */ +export const allForksExecution = { + bellatrix: { + BeaconBlockBody: bellatrix.BeaconBlockBody, + BeaconBlock: bellatrix.BeaconBlock, + SignedBeaconBlock: bellatrix.SignedBeaconBlock, + BeaconState: bellatrix.BeaconState, + ExecutionPayload: bellatrix.ExecutionPayload, + ExecutionPayloadHeader: bellatrix.ExecutionPayloadHeader, + BuilderBid: bellatrix.BuilderBid, + SignedBuilderBid: bellatrix.SignedBuilderBid, + SSEPayloadAttributes: bellatrix.SSEPayloadAttributes, + }, + capella: { + BeaconBlockBody: capella.BeaconBlockBody, + BeaconBlock: capella.BeaconBlock, + SignedBeaconBlock: capella.SignedBeaconBlock, + BeaconState: capella.BeaconState, + // Not used in phase0 but added for type consitency + ExecutionPayload: capella.ExecutionPayload, + ExecutionPayloadHeader: capella.ExecutionPayloadHeader, + BuilderBid: capella.BuilderBid, + SignedBuilderBid: capella.SignedBuilderBid, + SSEPayloadAttributes: capella.SSEPayloadAttributes, + }, + deneb: { + BeaconBlockBody: deneb.BeaconBlockBody, + BeaconBlock: deneb.BeaconBlock, + SignedBeaconBlock: deneb.SignedBeaconBlock, + BeaconState: deneb.BeaconState, + ExecutionPayload: deneb.ExecutionPayload, + ExecutionPayloadHeader: deneb.ExecutionPayloadHeader, + BuilderBid: deneb.BuilderBid, + SignedBuilderBid: deneb.SignedBuilderBid, + SSEPayloadAttributes: deneb.SSEPayloadAttributes, + }, +}; + +/** + * Index the blinded ssz types that differ by fork + * A record of AllForksBlindedSSZTypes indexed by fork + */ +export const allForksBlinded = { + bellatrix: { + BeaconBlockBody: bellatrix.BlindedBeaconBlockBody, + BeaconBlock: bellatrix.BlindedBeaconBlock, + SignedBeaconBlock: bellatrix.SignedBlindedBeaconBlock, + }, + capella: { + BeaconBlockBody: capella.BlindedBeaconBlockBody, + BeaconBlock: capella.BlindedBeaconBlock, + SignedBeaconBlock: capella.SignedBlindedBeaconBlock, + }, + deneb: { + BeaconBlockBody: deneb.BlindedBeaconBlockBody, + BeaconBlock: deneb.BlindedBeaconBlock, + SignedBeaconBlock: deneb.SignedBlindedBeaconBlock, + }, +}; + +export const allForksLightClient = { + altair: { + BeaconBlock: altair.BeaconBlock, + BeaconBlockBody: altair.BeaconBlockBody, + LightClientHeader: altair.LightClientHeader, + LightClientBootstrap: altair.LightClientBootstrap, + LightClientUpdate: altair.LightClientUpdate, + LightClientFinalityUpdate: altair.LightClientFinalityUpdate, + LightClientOptimisticUpdate: altair.LightClientOptimisticUpdate, + LightClientStore: altair.LightClientStore, + }, + bellatrix: { + BeaconBlock: bellatrix.BeaconBlock, + BeaconBlockBody: bellatrix.BeaconBlockBody, + LightClientHeader: altair.LightClientHeader, + LightClientBootstrap: altair.LightClientBootstrap, + LightClientUpdate: altair.LightClientUpdate, + LightClientFinalityUpdate: altair.LightClientFinalityUpdate, + LightClientOptimisticUpdate: altair.LightClientOptimisticUpdate, + LightClientStore: altair.LightClientStore, + }, + capella: { + BeaconBlock: capella.BeaconBlock, + BeaconBlockBody: capella.BeaconBlockBody, + LightClientHeader: capella.LightClientHeader, + LightClientBootstrap: capella.LightClientBootstrap, + LightClientUpdate: capella.LightClientUpdate, + LightClientFinalityUpdate: capella.LightClientFinalityUpdate, + LightClientOptimisticUpdate: capella.LightClientOptimisticUpdate, + LightClientStore: capella.LightClientStore, + }, + deneb: { + BeaconBlock: deneb.BeaconBlock, + BeaconBlockBody: deneb.BeaconBlockBody, + LightClientHeader: deneb.LightClientHeader, + LightClientBootstrap: deneb.LightClientBootstrap, + LightClientUpdate: deneb.LightClientUpdate, + LightClientFinalityUpdate: deneb.LightClientFinalityUpdate, + LightClientOptimisticUpdate: deneb.LightClientOptimisticUpdate, + LightClientStore: deneb.LightClientStore, + }, +}; + +export const allForksBlobs = { + deneb: { + BlobSidecar: deneb.BlobSidecar, + BlindedBlobSidecar: deneb.BlindedBlobSidecar, + }, }; diff --git a/packages/ssz/test/lodestarTypes/allForks/types.ts b/packages/ssz/test/lodestarTypes/allForks/types.ts index b28b21b5..161a87e0 100644 --- a/packages/ssz/test/lodestarTypes/allForks/types.ts +++ b/packages/ssz/test/lodestarTypes/allForks/types.ts @@ -1,19 +1,102 @@ +import {CompositeType, ContainerType, ValueOf, CompositeView, CompositeViewDU} from "../../../src"; import {ts as phase0} from "../phase0"; import {ts as altair} from "../altair"; import {ts as bellatrix} from "../bellatrix"; +import {ts as capella} from "../capella"; +import {ts as deneb} from "../deneb"; + import {ssz as phase0Ssz} from "../phase0"; import {ssz as altairSsz} from "../altair"; import {ssz as bellatrixSsz} from "../bellatrix"; -import {CompositeType, ContainerType, ValueOf, CompositeView, CompositeViewDU} from "../../../src"; +import {ssz as capellaSsz} from "../capella"; +import {ssz as denebSsz} from "../deneb"; // Re-export union types for types that are _known_ to differ -export type BeaconBlockBody = phase0.BeaconBlockBody | altair.BeaconBlockBody | bellatrix.BeaconBlockBody; -export type BeaconBlock = phase0.BeaconBlock | altair.BeaconBlock | bellatrix.BeaconBlock; -export type SignedBeaconBlock = phase0.SignedBeaconBlock | altair.SignedBeaconBlock | bellatrix.SignedBeaconBlock; -export type BeaconState = phase0.BeaconState | altair.BeaconState | bellatrix.BeaconState; +export type BeaconBlockBody = + | phase0.BeaconBlockBody + | altair.BeaconBlockBody + | bellatrix.BeaconBlockBody + | capella.BeaconBlockBody + | deneb.BeaconBlockBody; +export type BeaconBlock = + | phase0.BeaconBlock + | altair.BeaconBlock + | bellatrix.BeaconBlock + | capella.BeaconBlock + | deneb.BeaconBlock; +export type SignedBeaconBlock = + | phase0.SignedBeaconBlock + | altair.SignedBeaconBlock + | bellatrix.SignedBeaconBlock + | capella.SignedBeaconBlock + | deneb.SignedBeaconBlock; +export type BeaconState = + | phase0.BeaconState + | altair.BeaconState + | bellatrix.BeaconState + | capella.BeaconState + | deneb.BeaconState; export type Metadata = phase0.Metadata | altair.Metadata; +// For easy reference in the assemble block for building payloads +export type ExecutionBlockBody = bellatrix.BeaconBlockBody | capella.BeaconBlockBody | deneb.BeaconBlockBody; + +// These two additional types will also change bellatrix forward +export type ExecutionPayload = bellatrix.ExecutionPayload | capella.ExecutionPayload | deneb.ExecutionPayload; +export type ExecutionPayloadHeader = + | bellatrix.ExecutionPayloadHeader + | capella.ExecutionPayloadHeader + | deneb.ExecutionPayloadHeader; + +// Blinded types that will change across forks +export type BlindedBeaconBlockBody = + | bellatrix.BlindedBeaconBlockBody + | capella.BlindedBeaconBlockBody + | deneb.BlindedBeaconBlockBody; +export type BlindedBeaconBlock = bellatrix.BlindedBeaconBlock | capella.BlindedBeaconBlock | deneb.BlindedBeaconBlock; +export type SignedBlindedBeaconBlock = + | bellatrix.SignedBlindedBeaconBlock + | capella.SignedBlindedBeaconBlock + | deneb.SignedBlindedBeaconBlock; + +// Full or blinded types +export type FullOrBlindedExecutionPayload = + | bellatrix.FullOrBlindedExecutionPayload + | capella.FullOrBlindedExecutionPayload; +export type FullOrBlindedBeaconBlockBody = BeaconBlockBody | BlindedBeaconBlockBody; +export type FullOrBlindedBeaconBlock = BeaconBlock | BlindedBeaconBlock; +export type FullOrBlindedSignedBeaconBlock = SignedBeaconBlock | SignedBlindedBeaconBlock; + +export type FullOrBlindedBlobSidecar = deneb.BlobSidecar | deneb.BlindedBlobSidecar; +export type FullOrBlindedSignedBlobSidecar = deneb.SignedBlobSidecar | deneb.SignedBlindedBlobSidecar; + +export type FullOrBlindedBlobSidecars = deneb.BlobSidecars | deneb.BlindedBlobSidecars; + +export type BuilderBid = bellatrix.BuilderBid | capella.BuilderBid | deneb.BuilderBid; +export type SignedBuilderBid = bellatrix.SignedBuilderBid | capella.SignedBuilderBid | deneb.SignedBuilderBid; + +export type LightClientHeader = altair.LightClientHeader | capella.LightClientHeader | deneb.LightClientHeader; +export type LightClientBootstrap = + | altair.LightClientBootstrap + | capella.LightClientBootstrap + | deneb.LightClientBootstrap; +export type LightClientUpdate = altair.LightClientUpdate | capella.LightClientUpdate | deneb.LightClientUpdate; +export type LightClientFinalityUpdate = + | altair.LightClientFinalityUpdate + | capella.LightClientFinalityUpdate + | deneb.LightClientFinalityUpdate; +export type LightClientOptimisticUpdate = + | altair.LightClientOptimisticUpdate + | capella.LightClientOptimisticUpdate + | deneb.LightClientOptimisticUpdate; +export type LightClientStore = altair.LightClientStore | capella.LightClientStore | deneb.LightClientStore; + +export type SSEPayloadAttributes = + | bellatrix.SSEPayloadAttributes + | capella.SSEPayloadAttributes + | deneb.SSEPayloadAttributes; + /** * Types known to change between forks */ @@ -23,6 +106,32 @@ export type AllForksTypes = { SignedBeaconBlock: SignedBeaconBlock; BeaconState: BeaconState; Metadata: Metadata; + ExecutionPayload: ExecutionPayload; + ExecutionPayloadHeader: ExecutionPayloadHeader; + LightClientHeader: LightClientHeader; + BuilderBid: BuilderBid; + SignedBuilderBid: SignedBuilderBid; +}; + +export type AllForksBlindedTypes = { + BeaconBlockBody: BlindedBeaconBlockBody; + BeaconBlock: BlindedBeaconBlock; + SignedBeaconBlock: SignedBlindedBeaconBlock; +}; + +export type AllForksLightClient = { + BeaconBlock: altair.BeaconBlock | bellatrix.BeaconBlock | capella.BeaconBlock | deneb.BeaconBlock; + LightClientHeader: LightClientHeader; + LightClientBootstrap: LightClientBootstrap; + LightClientUpdate: LightClientUpdate; + LightClientFinalityUpdate: LightClientFinalityUpdate; + LightClientOptimisticUpdate: LightClientOptimisticUpdate; + LightClientStore: LightClientStore; +}; + +export type AllForksExecution = { + BeaconBlock: bellatrix.BeaconBlock | capella.BeaconBlock | deneb.BeaconBlock; + BeaconBlockBody: bellatrix.BeaconBlockBody | capella.BeaconBlockBody | deneb.BeaconBlockBody; }; /** @@ -40,6 +149,7 @@ export type AllForksTypes = { * phase0.BeaconState | altair.BeaconState | bellatrix.BeaconState * ``` */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any type AllForksTypeOf> = CompositeType< ValueOf, CompositeView, @@ -47,22 +157,134 @@ type AllForksTypeOf> = CompositeType >; /** - * AllForksSSZTypes are the union of all fork fields + * SSZ Types known to change between forks. + * + * Re-wrapping a union of fields in a new ContainerType allows to pass a generic block to .serialize() * - .serialize() requires a value with ONLY the common fork fields * - .deserialize() and ValueOf return a value with ONLY the general fork fields */ export type AllForksSSZTypes = { BeaconBlockBody: AllForksTypeOf< - typeof phase0Ssz.BeaconBlockBody | typeof altairSsz.BeaconBlockBody | typeof bellatrixSsz.BeaconBlockBody + | typeof phase0Ssz.BeaconBlockBody + | typeof altairSsz.BeaconBlockBody + | typeof bellatrixSsz.BeaconBlockBody + | typeof capellaSsz.BeaconBlockBody + | typeof denebSsz.BeaconBlockBody >; BeaconBlock: AllForksTypeOf< - typeof phase0Ssz.BeaconBlock | typeof altairSsz.BeaconBlock | typeof bellatrixSsz.BeaconBlock + | typeof phase0Ssz.BeaconBlock + | typeof altairSsz.BeaconBlock + | typeof bellatrixSsz.BeaconBlock + | typeof capellaSsz.BeaconBlock + | typeof denebSsz.BeaconBlock >; SignedBeaconBlock: AllForksTypeOf< - typeof phase0Ssz.SignedBeaconBlock | typeof altairSsz.SignedBeaconBlock | typeof bellatrixSsz.SignedBeaconBlock + | typeof phase0Ssz.SignedBeaconBlock + | typeof altairSsz.SignedBeaconBlock + | typeof bellatrixSsz.SignedBeaconBlock + | typeof capellaSsz.SignedBeaconBlock + | typeof denebSsz.SignedBeaconBlock >; BeaconState: AllForksTypeOf< - typeof phase0Ssz.BeaconState | typeof altairSsz.BeaconState | typeof bellatrixSsz.BeaconState + | typeof phase0Ssz.BeaconState + | typeof altairSsz.BeaconState + | typeof bellatrixSsz.BeaconState + | typeof capellaSsz.BeaconState + | typeof denebSsz.BeaconState >; Metadata: AllForksTypeOf; }; + +export type AllForksExecutionSSZTypes = { + BeaconBlockBody: AllForksTypeOf< + typeof bellatrixSsz.BeaconBlockBody | typeof capellaSsz.BeaconBlockBody | typeof denebSsz.BeaconBlockBody + >; + BeaconBlock: AllForksTypeOf< + typeof bellatrixSsz.BeaconBlock | typeof capellaSsz.BeaconBlock | typeof denebSsz.BeaconBlock + >; + SignedBeaconBlock: AllForksTypeOf< + typeof bellatrixSsz.SignedBeaconBlock | typeof capellaSsz.SignedBeaconBlock | typeof denebSsz.SignedBeaconBlock + >; + BeaconState: AllForksTypeOf< + typeof bellatrixSsz.BeaconState | typeof capellaSsz.BeaconState | typeof denebSsz.BeaconState + >; + ExecutionPayload: AllForksTypeOf< + typeof bellatrixSsz.ExecutionPayload | typeof capellaSsz.ExecutionPayload | typeof denebSsz.ExecutionPayload + >; + ExecutionPayloadHeader: AllForksTypeOf< + | typeof bellatrixSsz.ExecutionPayloadHeader + | typeof capellaSsz.ExecutionPayloadHeader + | typeof denebSsz.ExecutionPayloadHeader + >; + BuilderBid: AllForksTypeOf< + typeof bellatrixSsz.BuilderBid | typeof capellaSsz.BuilderBid | typeof denebSsz.BuilderBid + >; + SignedBuilderBid: AllForksTypeOf< + typeof bellatrixSsz.SignedBuilderBid | typeof capellaSsz.SignedBuilderBid | typeof denebSsz.SignedBuilderBid + >; + SSEPayloadAttributes: AllForksTypeOf< + | typeof bellatrixSsz.SSEPayloadAttributes + | typeof capellaSsz.SSEPayloadAttributes + | typeof denebSsz.SSEPayloadAttributes + >; +}; + +export type AllForksBlindedSSZTypes = { + BeaconBlockBody: AllForksTypeOf< + | typeof bellatrixSsz.BlindedBeaconBlockBody + | typeof capellaSsz.BlindedBeaconBlock + | typeof denebSsz.BlindedBeaconBlock + >; + BeaconBlock: AllForksTypeOf< + typeof bellatrixSsz.BlindedBeaconBlock | typeof capellaSsz.BlindedBeaconBlock | typeof denebSsz.BlindedBeaconBlock + >; + SignedBeaconBlock: AllForksTypeOf< + | typeof bellatrixSsz.SignedBlindedBeaconBlock + | typeof capellaSsz.SignedBlindedBeaconBlock + | typeof denebSsz.SignedBlindedBeaconBlock + >; +}; + +export type AllForksLightClientSSZTypes = { + BeaconBlock: AllForksTypeOf< + | typeof altairSsz.BeaconBlock + | typeof bellatrixSsz.BeaconBlock + | typeof capellaSsz.BeaconBlock + | typeof denebSsz.BeaconBlock + >; + BeaconBlockBody: AllForksTypeOf< + | typeof altairSsz.BeaconBlockBody + | typeof bellatrixSsz.BeaconBlockBody + | typeof capellaSsz.BeaconBlockBody + | typeof denebSsz.BeaconBlockBody + >; + LightClientHeader: AllForksTypeOf< + typeof altairSsz.LightClientHeader | typeof capellaSsz.LightClientHeader | typeof denebSsz.LightClientHeader + >; + LightClientBootstrap: AllForksTypeOf< + | typeof altairSsz.LightClientBootstrap + | typeof capellaSsz.LightClientBootstrap + | typeof denebSsz.LightClientBootstrap + >; + LightClientUpdate: AllForksTypeOf< + typeof altairSsz.LightClientUpdate | typeof capellaSsz.LightClientUpdate | typeof denebSsz.LightClientUpdate + >; + LightClientFinalityUpdate: AllForksTypeOf< + | typeof altairSsz.LightClientFinalityUpdate + | typeof capellaSsz.LightClientFinalityUpdate + | typeof denebSsz.LightClientFinalityUpdate + >; + LightClientOptimisticUpdate: AllForksTypeOf< + | typeof altairSsz.LightClientOptimisticUpdate + | typeof capellaSsz.LightClientOptimisticUpdate + | typeof denebSsz.LightClientOptimisticUpdate + >; + LightClientStore: AllForksTypeOf< + typeof altairSsz.LightClientStore | typeof capellaSsz.LightClientStore | typeof denebSsz.LightClientStore + >; +}; + +export type AllForksBlobsSSZTypes = { + BlobSidecar: AllForksTypeOf; + BlindedBlobSidecar: AllForksTypeOf; +}; diff --git a/packages/ssz/test/lodestarTypes/altair/index.ts b/packages/ssz/test/lodestarTypes/altair/index.ts index 0a5a5875..a1361536 100644 --- a/packages/ssz/test/lodestarTypes/altair/index.ts +++ b/packages/ssz/test/lodestarTypes/altair/index.ts @@ -1,2 +1,3 @@ +export * from "./types"; export * as ts from "./types"; export * as ssz from "./sszTypes"; diff --git a/packages/ssz/test/lodestarTypes/altair/sszTypes.ts b/packages/ssz/test/lodestarTypes/altair/sszTypes.ts index 778f326e..715220e5 100644 --- a/packages/ssz/test/lodestarTypes/altair/sszTypes.ts +++ b/packages/ssz/test/lodestarTypes/altair/sszTypes.ts @@ -1,16 +1,14 @@ import {BitVectorType, ContainerType, ListBasicType, ListCompositeType, VectorCompositeType} from "../../../src"; -import * as phase0Ssz from "../phase0/sszTypes"; -import * as primitiveSsz from "../primitive/sszTypes"; import {preset, FINALIZED_ROOT_DEPTH, NEXT_SYNC_COMMITTEE_DEPTH, SYNC_COMMITTEE_SUBNET_COUNT} from "../params"; - const { SYNC_COMMITTEE_SIZE, - SLOTS_PER_HISTORICAL_ROOT, HISTORICAL_ROOTS_LIMIT, - SLOTS_PER_EPOCH, VALIDATOR_REGISTRY_LIMIT, EPOCHS_PER_SYNC_COMMITTEE_PERIOD, + SLOTS_PER_EPOCH, } = preset; +import * as phase0Ssz from "../phase0/sszTypes"; +import * as primitiveSsz from "../primitive/sszTypes"; const { Bytes32, @@ -20,7 +18,6 @@ const { SubcommitteeIndex, ValidatorIndex, Root, - Version, BLSPubkey, BLSSignature, ParticipationFlags, @@ -72,7 +69,7 @@ export const ContributionAndProof = new ContainerType( contribution: SyncCommitteeContribution, selectionProof: BLSSignature, }, - {typeName: "ContributionAndProof", jsonCase: "eth2"} + {typeName: "ContributionAndProof", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const SignedContributionAndProof = new ContainerType( @@ -101,23 +98,12 @@ export const SyncAggregate = new ContainerType( {typeName: "SyncCommitteeBits", jsonCase: "eth2"} ); -export const HistoricalBlockRoots = new VectorCompositeType(Root, SLOTS_PER_HISTORICAL_ROOT); -export const HistoricalStateRoots = new VectorCompositeType(Root, SLOTS_PER_HISTORICAL_ROOT); - -export const HistoricalBatch = new ContainerType( - { - blockRoots: HistoricalBlockRoots, - stateRoots: HistoricalStateRoots, - }, - {typeName: "HistoricalBatch", jsonCase: "eth2"} -); - export const BeaconBlockBody = new ContainerType( { ...phase0Ssz.BeaconBlockBody.fields, syncAggregate: SyncAggregate, }, - {typeName: "BeaconBlockBody", jsonCase: "eth2"} + {typeName: "BeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const BeaconBlock = new ContainerType( @@ -128,7 +114,7 @@ export const BeaconBlock = new ContainerType( stateRoot: Root, body: BeaconBlockBody, }, - {typeName: "BeaconBlock", jsonCase: "eth2"} + {typeName: "BeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const SignedBeaconBlock = new ContainerType( @@ -152,8 +138,8 @@ export const BeaconState = new ContainerType( fork: phase0Ssz.Fork, // History latestBlockHeader: phase0Ssz.BeaconBlockHeader, - blockRoots: HistoricalBlockRoots, - stateRoots: HistoricalStateRoots, + blockRoots: phase0Ssz.HistoricalBlockRoots, + stateRoots: phase0Ssz.HistoricalStateRoots, historicalRoots: new ListCompositeType(Root, HISTORICAL_ROOTS_LIMIT), // Eth1 eth1Data: phase0Ssz.Eth1Data, @@ -182,31 +168,66 @@ export const BeaconState = new ContainerType( {typeName: "BeaconState", jsonCase: "eth2"} ); -export const LightClientSnapshot = new ContainerType( +export const LightClientHeader = new ContainerType( + { + beacon: phase0Ssz.BeaconBlockHeader, + }, + {typeName: "LightClientHeader", jsonCase: "eth2"} +); + +export const LightClientBootstrap = new ContainerType( { - header: phase0Ssz.BeaconBlockHeader, + header: LightClientHeader, currentSyncCommittee: SyncCommittee, - nextSyncCommittee: SyncCommittee, + currentSyncCommitteeBranch: new VectorCompositeType(Bytes32, NEXT_SYNC_COMMITTEE_DEPTH), }, - {typeName: "LightClientSnapshot", jsonCase: "eth2"} + {typeName: "LightClientBootstrap", jsonCase: "eth2"} ); export const LightClientUpdate = new ContainerType( { - attestedHeader: phase0Ssz.BeaconBlockHeader, + attestedHeader: LightClientHeader, nextSyncCommittee: SyncCommittee, nextSyncCommitteeBranch: new VectorCompositeType(Bytes32, NEXT_SYNC_COMMITTEE_DEPTH), - finalizedHeader: phase0Ssz.BeaconBlockHeader, + finalizedHeader: LightClientHeader, finalityBranch: new VectorCompositeType(Bytes32, FINALIZED_ROOT_DEPTH), syncAggregate: SyncAggregate, - forkVersion: Version, + signatureSlot: Slot, }, {typeName: "LightClientUpdate", jsonCase: "eth2"} ); +export const LightClientFinalityUpdate = new ContainerType( + { + attestedHeader: LightClientHeader, + finalizedHeader: LightClientHeader, + finalityBranch: new VectorCompositeType(Bytes32, FINALIZED_ROOT_DEPTH), + syncAggregate: SyncAggregate, + signatureSlot: Slot, + }, + {typeName: "LightClientFinalityUpdate", jsonCase: "eth2"} +); + +export const LightClientOptimisticUpdate = new ContainerType( + { + attestedHeader: LightClientHeader, + syncAggregate: SyncAggregate, + signatureSlot: Slot, + }, + {typeName: "LightClientOptimisticUpdate", jsonCase: "eth2"} +); + +export const LightClientUpdatesByRange = new ContainerType( + { + startPeriod: UintNum64, + count: UintNum64, + }, + {typeName: "LightClientUpdatesByRange", jsonCase: "eth2"} +); + export const LightClientStore = new ContainerType( { - snapshot: LightClientSnapshot, + snapshot: LightClientBootstrap, validUpdates: new ListCompositeType(LightClientUpdate, EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH), }, {typeName: "LightClientStore", jsonCase: "eth2"} diff --git a/packages/ssz/test/lodestarTypes/altair/types.ts b/packages/ssz/test/lodestarTypes/altair/types.ts index 92d9ea98..e824d5f9 100644 --- a/packages/ssz/test/lodestarTypes/altair/types.ts +++ b/packages/ssz/test/lodestarTypes/altair/types.ts @@ -14,6 +14,11 @@ export type BeaconBlockBody = ValueOf; export type BeaconBlock = ValueOf; export type SignedBeaconBlock = ValueOf; export type BeaconState = ValueOf; -export type LightClientSnapshot = ValueOf; + +export type LightClientHeader = ValueOf; +export type LightClientBootstrap = ValueOf; export type LightClientUpdate = ValueOf; +export type LightClientFinalityUpdate = ValueOf; +export type LightClientOptimisticUpdate = ValueOf; export type LightClientStore = ValueOf; +export type LightClientUpdatesByRange = ValueOf; diff --git a/packages/ssz/test/lodestarTypes/bellatrix/index.ts b/packages/ssz/test/lodestarTypes/bellatrix/index.ts index 0a5a5875..a1361536 100644 --- a/packages/ssz/test/lodestarTypes/bellatrix/index.ts +++ b/packages/ssz/test/lodestarTypes/bellatrix/index.ts @@ -1,2 +1,3 @@ +export * from "./types"; export * as ts from "./types"; export * as ssz from "./sszTypes"; diff --git a/packages/ssz/test/lodestarTypes/bellatrix/sszTypes.ts b/packages/ssz/test/lodestarTypes/bellatrix/sszTypes.ts index f34ab444..868aabe9 100644 --- a/packages/ssz/test/lodestarTypes/bellatrix/sszTypes.ts +++ b/packages/ssz/test/lodestarTypes/bellatrix/sszTypes.ts @@ -1,27 +1,46 @@ -import {ByteListType, ByteVectorType, ContainerType, ListCompositeType, VectorCompositeType} from "../../../src"; +import {ByteListType, ByteVectorType, ContainerType, ListCompositeType} from "../../../src"; +import {preset} from "../params"; import {ssz as primitiveSsz} from "../primitive"; import {ssz as phase0Ssz} from "../phase0"; import {ssz as altairSsz} from "../altair"; -import {preset} from "../params"; - +import {stringType} from "../utils/StringType"; const { BYTES_PER_LOGS_BLOOM, HISTORICAL_ROOTS_LIMIT, MAX_TRANSACTIONS_PER_PAYLOAD, MAX_BYTES_PER_TRANSACTION, MAX_EXTRA_DATA_BYTES, - SLOTS_PER_HISTORICAL_ROOT, } = preset; -const {Bytes20, Bytes32, UintNum64, Slot, ValidatorIndex, Root, BLSSignature, UintBn256: Uint256} = primitiveSsz; +const { + Bytes32, + UintNum64, + Slot, + ValidatorIndex, + Root, + BLSSignature, + UintBn256: Uint256, + BLSPubkey, + ExecutionAddress, +} = primitiveSsz; +/** + * ByteList[MAX_BYTES_PER_TRANSACTION] + * + * Spec v1.0.1 + */ export const Transaction = new ByteListType(MAX_BYTES_PER_TRANSACTION); +/** + * Union[OpaqueTransaction] + * + * Spec v1.0.1 + */ export const Transactions = new ListCompositeType(Transaction, MAX_TRANSACTIONS_PER_PAYLOAD); -const executionPayloadFields = { +export const CommonExecutionPayloadType = new ContainerType({ parentHash: Root, - feeRecipient: Bytes20, + feeRecipient: ExecutionAddress, stateRoot: Bytes32, receiptsRoot: Bytes32, logsBloom: new ByteVectorType(BYTES_PER_LOGS_BLOOM), @@ -33,13 +52,12 @@ const executionPayloadFields = { // TODO: if there is perf issue, consider making ByteListType extraData: new ByteListType(MAX_EXTRA_DATA_BYTES), baseFeePerGas: Uint256, - // Extra payload fields blockHash: Root, -}; +}); export const ExecutionPayload = new ContainerType( { - ...executionPayloadFields, + ...CommonExecutionPayloadType.fields, transactions: Transactions, }, {typeName: "ExecutionPayload", jsonCase: "eth2"} @@ -47,7 +65,7 @@ export const ExecutionPayload = new ContainerType( export const ExecutionPayloadHeader = new ContainerType( { - ...executionPayloadFields, + ...CommonExecutionPayloadType.fields, transactionsRoot: Root, }, {typeName: "ExecutionPayloadHeader", jsonCase: "eth2"} @@ -58,7 +76,7 @@ export const BeaconBlockBody = new ContainerType( ...altairSsz.BeaconBlockBody.fields, executionPayload: ExecutionPayload, }, - {typeName: "BeaconBlockBody", jsonCase: "eth2"} + {typeName: "BeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const BeaconBlock = new ContainerType( @@ -70,7 +88,7 @@ export const BeaconBlock = new ContainerType( stateRoot: Root, body: BeaconBlockBody, }, - {typeName: "BeaconBlock", jsonCase: "eth2"} + {typeName: "BeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const SignedBeaconBlock = new ContainerType( @@ -90,18 +108,6 @@ export const PowBlock = new ContainerType( {typeName: "PowBlock", jsonCase: "eth2"} ); -// Re-declare with the new expanded type -export const HistoricalBlockRoots = new VectorCompositeType(Root, SLOTS_PER_HISTORICAL_ROOT); -export const HistoricalStateRoots = new VectorCompositeType(Root, SLOTS_PER_HISTORICAL_ROOT); - -export const HistoricalBatch = new ContainerType( - { - blockRoots: HistoricalBlockRoots, - stateRoots: HistoricalStateRoots, - }, - {typeName: "HistoricalBatch", jsonCase: "eth2"} -); - // we don't reuse phase0.BeaconState fields since we need to replace some keys // and we cannot keep order doing that export const BeaconState = new ContainerType( @@ -112,8 +118,8 @@ export const BeaconState = new ContainerType( fork: phase0Ssz.Fork, // History latestBlockHeader: phase0Ssz.BeaconBlockHeader, - blockRoots: HistoricalBlockRoots, - stateRoots: HistoricalStateRoots, + blockRoots: phase0Ssz.HistoricalBlockRoots, + stateRoots: phase0Ssz.HistoricalStateRoots, historicalRoots: new ListCompositeType(Root, HISTORICAL_ROOTS_LIMIT), // Eth1 eth1Data: phase0Ssz.Eth1Data, @@ -143,3 +149,91 @@ export const BeaconState = new ContainerType( }, {typeName: "BeaconState", jsonCase: "eth2"} ); + +export const BlindedBeaconBlockBody = new ContainerType( + { + ...altairSsz.BeaconBlockBody.fields, + executionPayloadHeader: ExecutionPayloadHeader, + }, + {typeName: "BlindedBeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const BlindedBeaconBlock = new ContainerType( + { + slot: Slot, + proposerIndex: ValidatorIndex, + // Reclare expandedType() with altair block and altair state + parentRoot: Root, + stateRoot: Root, + body: BlindedBeaconBlockBody, + }, + {typeName: "BlindedBeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const SignedBlindedBeaconBlock = new ContainerType( + { + message: BlindedBeaconBlock, + signature: BLSSignature, + }, + {typeName: "SignedBlindedBeaconBlock", jsonCase: "eth2"} +); + +export const ValidatorRegistrationV1 = new ContainerType( + { + feeRecipient: ExecutionAddress, + gasLimit: UintNum64, + timestamp: UintNum64, + pubkey: BLSPubkey, + }, + {typeName: "ValidatorRegistrationV1", jsonCase: "eth2"} +); + +export const SignedValidatorRegistrationV1 = new ContainerType( + { + message: ValidatorRegistrationV1, + signature: BLSSignature, + }, + {typeName: "SignedValidatorRegistrationV1", jsonCase: "eth2"} +); + +export const BuilderBid = new ContainerType( + { + header: ExecutionPayloadHeader, + value: Uint256, + pubkey: BLSPubkey, + }, + {typeName: "BuilderBid", jsonCase: "eth2"} +); + +export const SignedBuilderBid = new ContainerType( + { + message: BuilderBid, + signature: BLSSignature, + }, + {typeName: "SignedBuilderBid", jsonCase: "eth2"} +); + +// PayloadAttributes primarily for SSE event +export const PayloadAttributes = new ContainerType( + {timestamp: UintNum64, prevRandao: Bytes32, suggestedFeeRecipient: stringType}, + {typeName: "PayloadAttributes", jsonCase: "eth2"} +); + +export const SSEPayloadAttributesCommon = new ContainerType( + { + proposerIndex: UintNum64, + proposalSlot: Slot, + proposalBlockNumber: UintNum64, + parentBlockRoot: Root, + parentBlockHash: Root, + }, + {typeName: "SSEPayloadAttributesCommon", jsonCase: "eth2"} +); + +export const SSEPayloadAttributes = new ContainerType( + { + ...SSEPayloadAttributesCommon.fields, + payloadAttributes: PayloadAttributes, + }, + {typeName: "SSEPayloadAttributes", jsonCase: "eth2"} +); diff --git a/packages/ssz/test/lodestarTypes/bellatrix/types.ts b/packages/ssz/test/lodestarTypes/bellatrix/types.ts index c1ccf151..cd02d110 100644 --- a/packages/ssz/test/lodestarTypes/bellatrix/types.ts +++ b/packages/ssz/test/lodestarTypes/bellatrix/types.ts @@ -2,6 +2,7 @@ import {ValueOf} from "../../../src"; import * as ssz from "./sszTypes"; export type Transaction = ValueOf; +export type Transactions = ValueOf; export type ExecutionPayload = ValueOf; export type ExecutionPayloadHeader = ValueOf; export type BeaconBlockBody = ValueOf; @@ -9,3 +10,15 @@ export type BeaconBlock = ValueOf; export type SignedBeaconBlock = ValueOf; export type BeaconState = ValueOf; export type PowBlock = ValueOf; + +export type BlindedBeaconBlockBody = ValueOf; +export type BlindedBeaconBlock = ValueOf; +export type SignedBlindedBeaconBlock = ValueOf; + +export type ValidatorRegistrationV1 = ValueOf; +export type SignedValidatorRegistrationV1 = ValueOf; +export type BuilderBid = ValueOf; +export type SignedBuilderBid = ValueOf; +export type SSEPayloadAttributes = ValueOf; + +export type FullOrBlindedExecutionPayload = ExecutionPayload | ExecutionPayloadHeader; diff --git a/packages/ssz/test/lodestarTypes/capella/index.ts b/packages/ssz/test/lodestarTypes/capella/index.ts new file mode 100644 index 00000000..a1361536 --- /dev/null +++ b/packages/ssz/test/lodestarTypes/capella/index.ts @@ -0,0 +1,3 @@ +export * from "./types"; +export * as ts from "./types"; +export * as ssz from "./sszTypes"; diff --git a/packages/ssz/test/lodestarTypes/capella/sszTypes.ts b/packages/ssz/test/lodestarTypes/capella/sszTypes.ts new file mode 100644 index 00000000..73caab2e --- /dev/null +++ b/packages/ssz/test/lodestarTypes/capella/sszTypes.ts @@ -0,0 +1,279 @@ +import {ContainerType, ListCompositeType, VectorCompositeType} from "../../../src"; +import {preset, BLOCK_BODY_EXECUTION_PAYLOAD_DEPTH as EXECUTION_PAYLOAD_DEPTH} from "../params"; +import {ssz as primitiveSsz} from "../primitive"; +import {ssz as phase0Ssz} from "../phase0"; +import {ssz as altairSsz} from "../altair"; +import {ssz as bellatrixSsz} from "../bellatrix"; +const { + HISTORICAL_ROOTS_LIMIT, + MAX_WITHDRAWALS_PER_PAYLOAD, + MAX_BLS_TO_EXECUTION_CHANGES, + EPOCHS_PER_SYNC_COMMITTEE_PERIOD, + SLOTS_PER_EPOCH, +} = preset; + +const { + UintNum64, + Slot, + ValidatorIndex, + WithdrawalIndex, + Root, + BLSSignature, + BLSPubkey, + ExecutionAddress, + Gwei, + UintBn256, + Bytes32, +} = primitiveSsz; + +export const Withdrawal = new ContainerType( + { + index: WithdrawalIndex, + validatorIndex: ValidatorIndex, + address: ExecutionAddress, + amount: Gwei, + }, + {typeName: "Withdrawal", jsonCase: "eth2"} +); + +export const BLSToExecutionChange = new ContainerType( + { + validatorIndex: ValidatorIndex, + fromBlsPubkey: BLSPubkey, + toExecutionAddress: ExecutionAddress, + }, + {typeName: "BLSToExecutionChange", jsonCase: "eth2"} +); + +export const SignedBLSToExecutionChange = new ContainerType( + { + message: BLSToExecutionChange, + signature: BLSSignature, + }, + {typeName: "SignedBLSToExecutionChange", jsonCase: "eth2"} +); + +export const Withdrawals = new ListCompositeType(Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD); +export const ExecutionPayload = new ContainerType( + { + ...bellatrixSsz.ExecutionPayload.fields, + withdrawals: Withdrawals, // New in capella + }, + {typeName: "ExecutionPayload", jsonCase: "eth2"} +); + +export const ExecutionPayloadHeader = new ContainerType( + { + ...bellatrixSsz.ExecutionPayloadHeader.fields, + withdrawalsRoot: Root, // New in capella + }, + {typeName: "ExecutionPayloadHeader", jsonCase: "eth2"} +); + +export const BLSToExecutionChanges = new ListCompositeType(SignedBLSToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES); +export const BeaconBlockBody = new ContainerType( + { + ...altairSsz.BeaconBlockBody.fields, + executionPayload: ExecutionPayload, // Modified in capella + blsToExecutionChanges: BLSToExecutionChanges, + }, + {typeName: "BeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const BeaconBlock = new ContainerType( + { + slot: Slot, + proposerIndex: ValidatorIndex, + // Reclare expandedType() with altair block and altair state + parentRoot: Root, + stateRoot: Root, + body: BeaconBlockBody, // Modified in Capella + }, + {typeName: "BeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const SignedBeaconBlock = new ContainerType( + { + message: BeaconBlock, // Modified in capella + signature: BLSSignature, + }, + {typeName: "SignedBeaconBlock", jsonCase: "eth2"} +); + +export const BuilderBid = new ContainerType( + { + header: ExecutionPayloadHeader, + value: UintBn256, + pubkey: BLSPubkey, + }, + {typeName: "BuilderBid", jsonCase: "eth2"} +); + +export const SignedBuilderBid = new ContainerType( + { + message: BuilderBid, + signature: BLSSignature, + }, + {typeName: "SignedBuilderBid", jsonCase: "eth2"} +); + +export const HistoricalSummary = new ContainerType( + { + blockSummaryRoot: Root, + stateSummaryRoot: Root, + }, + {typeName: "HistoricalSummary", jsonCase: "eth2"} +); + +// we don't reuse bellatrix.BeaconState fields since we need to replace some keys +// and we cannot keep order doing that +export const BeaconState = new ContainerType( + { + genesisTime: UintNum64, + genesisValidatorsRoot: Root, + slot: primitiveSsz.Slot, + fork: phase0Ssz.Fork, + // History + latestBlockHeader: phase0Ssz.BeaconBlockHeader, + blockRoots: phase0Ssz.HistoricalBlockRoots, + stateRoots: phase0Ssz.HistoricalStateRoots, + // historical_roots Frozen in Capella, replaced by historical_summaries + historicalRoots: new ListCompositeType(Root, HISTORICAL_ROOTS_LIMIT), + // Eth1 + eth1Data: phase0Ssz.Eth1Data, + eth1DataVotes: phase0Ssz.Eth1DataVotes, + eth1DepositIndex: UintNum64, + // Registry + validators: phase0Ssz.Validators, + balances: phase0Ssz.Balances, + randaoMixes: phase0Ssz.RandaoMixes, + // Slashings + slashings: phase0Ssz.Slashings, + // Participation + previousEpochParticipation: altairSsz.EpochParticipation, + currentEpochParticipation: altairSsz.EpochParticipation, + // Finality + justificationBits: phase0Ssz.JustificationBits, + previousJustifiedCheckpoint: phase0Ssz.Checkpoint, + currentJustifiedCheckpoint: phase0Ssz.Checkpoint, + finalizedCheckpoint: phase0Ssz.Checkpoint, + // Inactivity + inactivityScores: altairSsz.InactivityScores, + // Sync + currentSyncCommittee: altairSsz.SyncCommittee, + nextSyncCommittee: altairSsz.SyncCommittee, + // Execution + latestExecutionPayloadHeader: ExecutionPayloadHeader, // [Modified in Capella] + // Withdrawals + nextWithdrawalIndex: WithdrawalIndex, // [New in Capella] + nextWithdrawalValidatorIndex: ValidatorIndex, // [New in Capella] + // Deep history valid from Capella onwards + historicalSummaries: new ListCompositeType(HistoricalSummary, HISTORICAL_ROOTS_LIMIT), // [New in Capella] + }, + {typeName: "BeaconState", jsonCase: "eth2"} +); + +export const BlindedBeaconBlockBody = new ContainerType( + { + ...altairSsz.BeaconBlockBody.fields, + executionPayloadHeader: ExecutionPayloadHeader, // Modified in capella + blsToExecutionChanges: BLSToExecutionChanges, // New in capella + }, + {typeName: "BlindedBeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const BlindedBeaconBlock = new ContainerType( + { + slot: Slot, + proposerIndex: ValidatorIndex, + // Reclare expandedType() with altair block and altair state + parentRoot: Root, + stateRoot: Root, + body: BlindedBeaconBlockBody, // Modified in capella + }, + {typeName: "BlindedBeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const SignedBlindedBeaconBlock = new ContainerType( + { + message: BlindedBeaconBlock, // Modified in capella + signature: BLSSignature, + }, + {typeName: "SignedBlindedBeaconBlock", jsonCase: "eth2"} +); + +export const LightClientHeader = new ContainerType( + { + beacon: phase0Ssz.BeaconBlockHeader, + execution: ExecutionPayloadHeader, + executionBranch: new VectorCompositeType(Bytes32, EXECUTION_PAYLOAD_DEPTH), + }, + {typeName: "LightClientHeader", jsonCase: "eth2"} +); + +export const LightClientBootstrap = new ContainerType( + { + header: LightClientHeader, + currentSyncCommittee: altairSsz.SyncCommittee, + currentSyncCommitteeBranch: altairSsz.LightClientBootstrap.fields.currentSyncCommitteeBranch, + }, + {typeName: "LightClientBootstrap", jsonCase: "eth2"} +); + +export const LightClientUpdate = new ContainerType( + { + attestedHeader: LightClientHeader, + nextSyncCommittee: altairSsz.SyncCommittee, + nextSyncCommitteeBranch: altairSsz.LightClientUpdate.fields.nextSyncCommitteeBranch, + finalizedHeader: LightClientHeader, + finalityBranch: altairSsz.LightClientUpdate.fields.finalityBranch, + syncAggregate: altairSsz.SyncAggregate, + signatureSlot: Slot, + }, + {typeName: "LightClientUpdate", jsonCase: "eth2"} +); + +export const LightClientFinalityUpdate = new ContainerType( + { + attestedHeader: LightClientHeader, + finalizedHeader: LightClientHeader, + finalityBranch: altairSsz.LightClientFinalityUpdate.fields.finalityBranch, + syncAggregate: altairSsz.SyncAggregate, + signatureSlot: Slot, + }, + {typeName: "LightClientFinalityUpdate", jsonCase: "eth2"} +); + +export const LightClientOptimisticUpdate = new ContainerType( + { + attestedHeader: LightClientHeader, + syncAggregate: altairSsz.SyncAggregate, + signatureSlot: Slot, + }, + {typeName: "LightClientOptimisticUpdate", jsonCase: "eth2"} +); + +export const LightClientStore = new ContainerType( + { + snapshot: LightClientBootstrap, + validUpdates: new ListCompositeType(LightClientUpdate, EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH), + }, + {typeName: "LightClientStore", jsonCase: "eth2"} +); + +// PayloadAttributes primarily for SSE event +export const PayloadAttributes = new ContainerType( + { + ...bellatrixSsz.PayloadAttributes.fields, + withdrawals: Withdrawals, + }, + {typeName: "PayloadAttributes", jsonCase: "eth2"} +); + +export const SSEPayloadAttributes = new ContainerType( + { + ...bellatrixSsz.SSEPayloadAttributesCommon.fields, + payloadAttributes: PayloadAttributes, + }, + {typeName: "SSEPayloadAttributes", jsonCase: "eth2"} +); diff --git a/packages/ssz/test/lodestarTypes/capella/types.ts b/packages/ssz/test/lodestarTypes/capella/types.ts new file mode 100644 index 00000000..9f3cb33e --- /dev/null +++ b/packages/ssz/test/lodestarTypes/capella/types.ts @@ -0,0 +1,33 @@ +import {ValueOf} from "../../../src"; +import * as ssz from "./sszTypes"; + +export type Withdrawal = ValueOf; +export type Withdrawals = ValueOf; +export type BLSToExecutionChange = ValueOf; +export type BLSToExecutionChanges = ValueOf; +export type SignedBLSToExecutionChange = ValueOf; + +export type ExecutionPayload = ValueOf; +export type ExecutionPayloadHeader = ValueOf; + +export type BeaconBlockBody = ValueOf; +export type BeaconBlock = ValueOf; +export type SignedBeaconBlock = ValueOf; +export type BeaconState = ValueOf; + +export type BlindedBeaconBlockBody = ValueOf; +export type BlindedBeaconBlock = ValueOf; +export type SignedBlindedBeaconBlock = ValueOf; + +export type FullOrBlindedExecutionPayload = ExecutionPayload | ExecutionPayloadHeader; + +export type BuilderBid = ValueOf; +export type SignedBuilderBid = ValueOf; +export type SSEPayloadAttributes = ValueOf; + +export type LightClientHeader = ValueOf; +export type LightClientBootstrap = ValueOf; +export type LightClientUpdate = ValueOf; +export type LightClientFinalityUpdate = ValueOf; +export type LightClientOptimisticUpdate = ValueOf; +export type LightClientStore = ValueOf; diff --git a/packages/ssz/test/lodestarTypes/deneb/index.ts b/packages/ssz/test/lodestarTypes/deneb/index.ts new file mode 100644 index 00000000..a1361536 --- /dev/null +++ b/packages/ssz/test/lodestarTypes/deneb/index.ts @@ -0,0 +1,3 @@ +export * from "./types"; +export * as ts from "./types"; +export * as ssz from "./sszTypes"; diff --git a/packages/ssz/test/lodestarTypes/deneb/sszTypes.ts b/packages/ssz/test/lodestarTypes/deneb/sszTypes.ts new file mode 100644 index 00000000..bbc760ad --- /dev/null +++ b/packages/ssz/test/lodestarTypes/deneb/sszTypes.ts @@ -0,0 +1,352 @@ +import {ContainerType, ListCompositeType, ByteVectorType, VectorCompositeType} from "../../../src"; +import { + preset, + BYTES_PER_FIELD_ELEMENT, + BLOCK_BODY_EXECUTION_PAYLOAD_DEPTH as EXECUTION_PAYLOAD_DEPTH, + MAX_REQUEST_BLOCKS_DENEB, +} from "../params"; +import {ssz as primitiveSsz} from "../primitive"; +import {ssz as phase0Ssz} from "../phase0"; +import {ssz as altairSsz} from "../altair"; +import {ssz as bellatrixSsz} from "../bellatrix"; +import {ssz as capellaSsz} from "../capella"; +const { + HISTORICAL_ROOTS_LIMIT, + MAX_BLOB_COMMITMENTS_PER_BLOCK, + FIELD_ELEMENTS_PER_BLOB, + EPOCHS_PER_SYNC_COMMITTEE_PERIOD, + SLOTS_PER_EPOCH, + MAX_BLOBS_PER_BLOCK, +} = preset; +export const MAX_REQUEST_BLOB_SIDECARS = MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK; + +const { + UintNum64, + Slot, + Root, + BLSSignature, + UintBn64, + UintBn256, + Bytes32, + Bytes48, + Bytes96, + BLSPubkey, + BlobIndex, + ValidatorIndex, +} = primitiveSsz; + +// Polynomial commitments +// https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md + +// Custom types +// https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/polynomial-commitments.md#custom-types +export const G1Point = Bytes48; +export const G2Point = Bytes96; +export const BLSFieldElement = Bytes32; +export const KZGCommitment = Bytes48; +export const KZGProof = Bytes48; + +// Beacon chain + +// Custom types +// https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/beacon-chain.md#custom-types + +export const Blob = new ByteVectorType(BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_BLOB); +export const Blobs = new ListCompositeType(Blob, MAX_BLOB_COMMITMENTS_PER_BLOCK); +export const BlindedBlob = Bytes32; +export const BlindedBlobs = new ListCompositeType(BlindedBlob, MAX_BLOB_COMMITMENTS_PER_BLOCK); + +export const VersionedHash = Bytes32; +export const BlobKzgCommitments = new ListCompositeType(KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK); +export const KZGProofs = new ListCompositeType(KZGProof, MAX_BLOB_COMMITMENTS_PER_BLOCK); + +// ReqResp types +// ============= + +export const BlobSidecarsByRangeRequest = new ContainerType( + { + startSlot: Slot, + count: UintNum64, + }, + {typeName: "BlobSidecarsByRangeRequest", jsonCase: "eth2"} +); + +export const BlobIdentifier = new ContainerType( + { + blockRoot: Root, + index: BlobIndex, + }, + {typeName: "BlobIdentifier", jsonCase: "eth2"} +); + +export const BlobSidecarsByRootRequest = new ListCompositeType(BlobIdentifier, MAX_REQUEST_BLOB_SIDECARS); + +// Beacon Chain types +// https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/beacon-chain.md#containers + +export const ExecutionPayload = new ContainerType( + { + ...capellaSsz.ExecutionPayload.fields, + blobGasUsed: UintBn64, // New in DENEB + excessBlobGas: UintBn64, // New in DENEB + }, + {typeName: "ExecutionPayload", jsonCase: "eth2"} +); + +export const ExecutionPayloadHeader = new ContainerType( + { + ...capellaSsz.ExecutionPayloadHeader.fields, + blobGasUsed: UintBn64, // New in DENEB + excessBlobGas: UintBn64, // New in DENEB + }, + {typeName: "ExecutionPayloadHeader", jsonCase: "eth2"} +); + +// We have to preserve Fields ordering while changing the type of ExecutionPayload +export const BeaconBlockBody = new ContainerType( + { + ...altairSsz.BeaconBlockBody.fields, + executionPayload: ExecutionPayload, // Modified in DENEB + blsToExecutionChanges: capellaSsz.BeaconBlockBody.fields.blsToExecutionChanges, + blobKzgCommitments: BlobKzgCommitments, // New in DENEB + }, + {typeName: "BeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const BeaconBlock = new ContainerType( + { + ...capellaSsz.BeaconBlock.fields, + body: BeaconBlockBody, // Modified in DENEB + }, + {typeName: "BeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const SignedBeaconBlock = new ContainerType( + { + message: BeaconBlock, // Modified in DENEB + signature: BLSSignature, + }, + {typeName: "SignedBeaconBlock", jsonCase: "eth2"} +); + +export const BlobSidecar = new ContainerType( + { + blockRoot: Root, + index: BlobIndex, + slot: Slot, + blockParentRoot: Root, + proposerIndex: ValidatorIndex, + blob: Blob, + kzgCommitment: KZGCommitment, + kzgProof: KZGProof, + }, + {typeName: "BlobSidecar", jsonCase: "eth2"} +); + +export const BlobSidecars = new ListCompositeType(BlobSidecar, MAX_BLOB_COMMITMENTS_PER_BLOCK); + +export const SignedBlobSidecar = new ContainerType( + { + message: BlobSidecar, + signature: BLSSignature, + }, + {typeName: "SignedBlobSidecar", jsonCase: "eth2"} +); +export const SignedBlobSidecars = new ListCompositeType(SignedBlobSidecar, MAX_BLOB_COMMITMENTS_PER_BLOCK); + +export const BlindedBlobSidecar = new ContainerType( + { + blockRoot: Root, + index: BlobIndex, + slot: Slot, + blockParentRoot: Root, + proposerIndex: ValidatorIndex, + blobRoot: BlindedBlob, + kzgCommitment: KZGCommitment, + kzgProof: KZGProof, + }, + {typeName: "BlindedBlobSidecar", jsonCase: "eth2"} +); + +export const BlindedBlobSidecars = new ListCompositeType(BlindedBlobSidecar, MAX_BLOB_COMMITMENTS_PER_BLOCK); + +export const SignedBlindedBlobSidecar = new ContainerType( + { + message: BlindedBlobSidecar, + signature: BLSSignature, + }, + {typeName: "SignedBlindedBlobSidecar", jsonCase: "eth2"} +); + +export const SignedBlindedBlobSidecars = new ListCompositeType( + SignedBlindedBlobSidecar, + MAX_BLOB_COMMITMENTS_PER_BLOCK +); + +export const BlindedBeaconBlockBody = new ContainerType( + { + ...altairSsz.BeaconBlockBody.fields, + executionPayloadHeader: ExecutionPayloadHeader, // Modified in DENEB + blsToExecutionChanges: capellaSsz.BeaconBlockBody.fields.blsToExecutionChanges, + blobKzgCommitments: BlobKzgCommitments, // New in DENEB + }, + {typeName: "BlindedBeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const BlindedBeaconBlock = new ContainerType( + { + ...capellaSsz.BlindedBeaconBlock.fields, + body: BlindedBeaconBlockBody, // Modified in DENEB + }, + {typeName: "BlindedBeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +export const SignedBlindedBeaconBlock = new ContainerType( + { + message: BlindedBeaconBlock, // Modified in DENEB + signature: BLSSignature, + }, + {typeName: "SignedBlindedBeaconBlock", jsonCase: "eth2"} +); + +export const BuilderBid = new ContainerType( + { + header: ExecutionPayloadHeader, + value: UintBn256, + pubkey: BLSPubkey, + blobKzgCommitments: BlobKzgCommitments, + }, + {typeName: "BuilderBid", jsonCase: "eth2"} +); + +export const SignedBuilderBid = new ContainerType( + { + message: BuilderBid, + signature: BLSSignature, + }, + {typeName: "SignedBuilderBid", jsonCase: "eth2"} +); + +// We don't spread capella.BeaconState fields since we need to replace +// latestExecutionPayloadHeader and we cannot keep order doing that +export const BeaconState = new ContainerType( + { + genesisTime: UintNum64, + genesisValidatorsRoot: Root, + slot: primitiveSsz.Slot, + fork: phase0Ssz.Fork, + // History + latestBlockHeader: phase0Ssz.BeaconBlockHeader, + blockRoots: phase0Ssz.HistoricalBlockRoots, + stateRoots: phase0Ssz.HistoricalStateRoots, + // historical_roots Frozen in Capella, replaced by historical_summaries + historicalRoots: new ListCompositeType(Root, HISTORICAL_ROOTS_LIMIT), + // Eth1 + eth1Data: phase0Ssz.Eth1Data, + eth1DataVotes: phase0Ssz.Eth1DataVotes, + eth1DepositIndex: UintNum64, + // Registry + validators: phase0Ssz.Validators, + balances: phase0Ssz.Balances, + randaoMixes: phase0Ssz.RandaoMixes, + // Slashings + slashings: phase0Ssz.Slashings, + // Participation + previousEpochParticipation: altairSsz.EpochParticipation, + currentEpochParticipation: altairSsz.EpochParticipation, + // Finality + justificationBits: phase0Ssz.JustificationBits, + previousJustifiedCheckpoint: phase0Ssz.Checkpoint, + currentJustifiedCheckpoint: phase0Ssz.Checkpoint, + finalizedCheckpoint: phase0Ssz.Checkpoint, + // Inactivity + inactivityScores: altairSsz.InactivityScores, + // Sync + currentSyncCommittee: altairSsz.SyncCommittee, + nextSyncCommittee: altairSsz.SyncCommittee, + // Execution + latestExecutionPayloadHeader: ExecutionPayloadHeader, // Modified in DENEB + // Withdrawals + nextWithdrawalIndex: capellaSsz.BeaconState.fields.nextWithdrawalIndex, + nextWithdrawalValidatorIndex: capellaSsz.BeaconState.fields.nextWithdrawalValidatorIndex, + // Deep history valid from Capella onwards + historicalSummaries: capellaSsz.BeaconState.fields.historicalSummaries, + }, + {typeName: "BeaconState", jsonCase: "eth2"} +); + +export const LightClientHeader = new ContainerType( + { + beacon: phase0Ssz.BeaconBlockHeader, + execution: ExecutionPayloadHeader, + executionBranch: new VectorCompositeType(Bytes32, EXECUTION_PAYLOAD_DEPTH), + }, + {typeName: "LightClientHeader", jsonCase: "eth2"} +); + +export const LightClientBootstrap = new ContainerType( + { + header: LightClientHeader, + currentSyncCommittee: altairSsz.SyncCommittee, + currentSyncCommitteeBranch: altairSsz.LightClientBootstrap.fields.currentSyncCommitteeBranch, + }, + {typeName: "LightClientBootstrap", jsonCase: "eth2"} +); + +export const LightClientUpdate = new ContainerType( + { + attestedHeader: LightClientHeader, + nextSyncCommittee: altairSsz.SyncCommittee, + nextSyncCommitteeBranch: altairSsz.LightClientUpdate.fields.nextSyncCommitteeBranch, + finalizedHeader: LightClientHeader, + finalityBranch: altairSsz.LightClientUpdate.fields.finalityBranch, + syncAggregate: altairSsz.SyncAggregate, + signatureSlot: Slot, + }, + {typeName: "LightClientUpdate", jsonCase: "eth2"} +); + +export const LightClientFinalityUpdate = new ContainerType( + { + attestedHeader: LightClientHeader, + finalizedHeader: LightClientHeader, + finalityBranch: altairSsz.LightClientFinalityUpdate.fields.finalityBranch, + syncAggregate: altairSsz.SyncAggregate, + signatureSlot: Slot, + }, + {typeName: "LightClientFinalityUpdate", jsonCase: "eth2"} +); + +export const LightClientOptimisticUpdate = new ContainerType( + { + attestedHeader: LightClientHeader, + syncAggregate: altairSsz.SyncAggregate, + signatureSlot: Slot, + }, + {typeName: "LightClientOptimisticUpdate", jsonCase: "eth2"} +); + +export const LightClientStore = new ContainerType( + { + snapshot: LightClientBootstrap, + validUpdates: new ListCompositeType(LightClientUpdate, EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH), + }, + {typeName: "LightClientStore", jsonCase: "eth2"} +); + +// PayloadAttributes primarily for SSE event +export const PayloadAttributes = new ContainerType( + { + ...capellaSsz.PayloadAttributes.fields, + parentBeaconBlockRoot: Root, + }, + {typeName: "PayloadAttributes", jsonCase: "eth2"} +); + +export const SSEPayloadAttributes = new ContainerType( + { + ...bellatrixSsz.SSEPayloadAttributesCommon.fields, + payloadAttributes: PayloadAttributes, + }, + {typeName: "SSEPayloadAttributes", jsonCase: "eth2"} +); diff --git a/packages/ssz/test/lodestarTypes/deneb/types.ts b/packages/ssz/test/lodestarTypes/deneb/types.ts new file mode 100644 index 00000000..4f550be9 --- /dev/null +++ b/packages/ssz/test/lodestarTypes/deneb/types.ts @@ -0,0 +1,52 @@ +import {ValueOf} from "../../../src"; +import * as ssz from "./sszTypes"; + +export type KZGProof = ValueOf; +export type KZGCommitment = ValueOf; + +export type Blob = ValueOf; +export type Blobs = ValueOf; +export type BlindedBlob = ValueOf; +export type BlindedBlobs = ValueOf; +export type BlobSidecar = ValueOf; +export type BlobSidecars = ValueOf; +export type BlindedBlobSidecar = ValueOf; +export type BlindedBlobSidecars = ValueOf; +export type SignedBlobSidecar = ValueOf; +export type SignedBlobSidecars = ValueOf; +export type SignedBlindedBlobSidecar = ValueOf; +export type SignedBlindedBlobSidecars = ValueOf; + +export type BlobKzgCommitments = ValueOf; +export type KZGProofs = ValueOf; +export type BLSFieldElement = ValueOf; + +export type BlobIdentifier = ValueOf; +export type BlobSidecarsByRangeRequest = ValueOf; +export type BlobSidecarsByRootRequest = ValueOf; + +export type ExecutionPayload = ValueOf; +export type ExecutionPayloadHeader = ValueOf; + +export type BeaconBlockBody = ValueOf; +export type BeaconBlock = ValueOf; +export type SignedBeaconBlock = ValueOf; + +export type BeaconState = ValueOf; + +export type BlindedBeaconBlockBody = ValueOf; +export type BlindedBeaconBlock = ValueOf; +export type SignedBlindedBeaconBlock = ValueOf; + +export type FullOrBlindedExecutionPayload = ExecutionPayload | ExecutionPayloadHeader; + +export type BuilderBid = ValueOf; +export type SignedBuilderBid = ValueOf; +export type SSEPayloadAttributes = ValueOf; + +export type LightClientHeader = ValueOf; +export type LightClientBootstrap = ValueOf; +export type LightClientUpdate = ValueOf; +export type LightClientFinalityUpdate = ValueOf; +export type LightClientOptimisticUpdate = ValueOf; +export type LightClientStore = ValueOf; diff --git a/packages/ssz/test/lodestarTypes/index.ts b/packages/ssz/test/lodestarTypes/index.ts index 9d4b4b1c..4fa87b3a 100644 --- a/packages/ssz/test/lodestarTypes/index.ts +++ b/packages/ssz/test/lodestarTypes/index.ts @@ -1,2 +1,6 @@ export * from "./types"; export * as ssz from "./sszTypes"; +// Typeguards +export * from "./utils/typeguards"; +// String type +export {StringType, stringType} from "./utils/StringType"; diff --git a/packages/ssz/test/lodestarTypes/params.ts b/packages/ssz/test/lodestarTypes/params.ts index 8782d0c8..edc05f1d 100644 --- a/packages/ssz/test/lodestarTypes/params.ts +++ b/packages/ssz/test/lodestarTypes/params.ts @@ -5,6 +5,9 @@ export const FINALIZED_ROOT_DEPTH = 6; export const SYNC_COMMITTEE_SUBNET_COUNT = 4; export const MAX_REQUEST_BLOCKS = 2 ** 10; // 1024 export const JUSTIFICATION_BITS_LENGTH = 4; +export const BLOCK_BODY_EXECUTION_PAYLOAD_DEPTH = 4; +export const MAX_REQUEST_BLOCKS_DENEB = 2 ** 7; // 128 +export const BYTES_PER_FIELD_ELEMENT = 32; export const ACTIVE_PRESET = process.env.LODESTAR_PRESET === "mainnet" ? "mainnet" : "minimal"; @@ -26,15 +29,10 @@ const presetMainnet = { // 5 (plus 1.25) HYSTERESIS_UPWARD_MULTIPLIER: 5, - // Fork Choice - // --------------------------------------------------------------- - // 2**3 (= 8) - SAFE_SLOTS_TO_UPDATE_JUSTIFIED: 8, - // Gwei values // --------------------------------------------------------------- // 2**0 * 10**9 (= 1,000,000,000) Gwei - MIN_DEPOSIT_AMOUNT: BigInt(1000000000), + MIN_DEPOSIT_AMOUNT: 1000000000, // 2**5 * 10**9 (= 32,000,000,000) Gwei MAX_EFFECTIVE_BALANCE: 32000000000, // 2**0 * 10**9 (= 1,000,000,000) Gwei @@ -95,20 +93,38 @@ const presetMainnet = { // 2**4 (= 16) MAX_VOLUNTARY_EXITS: 16, + // ALTAIR + ///////// SYNC_COMMITTEE_SIZE: 512, EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 256, INACTIVITY_PENALTY_QUOTIENT_ALTAIR: 50331648, MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR: 64, PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR: 2, - - INACTIVITY_PENALTY_QUOTIENT_MERGE: 16777216, - MIN_SLASHING_PENALTY_QUOTIENT_MERGE: 32, - PROPORTIONAL_SLASHING_MULTIPLIER_MERGE: 3, - + MIN_SYNC_COMMITTEE_PARTICIPANTS: 1, + UPDATE_TIMEOUT: 8192, + + // BELLATRIX + //////////// + INACTIVITY_PENALTY_QUOTIENT_BELLATRIX: 16777216, + MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX: 32, + PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX: 3, MAX_BYTES_PER_TRANSACTION: 1073741824, MAX_TRANSACTIONS_PER_PAYLOAD: 1048576, BYTES_PER_LOGS_BLOOM: 256, MAX_EXTRA_DATA_BYTES: 32, + + // CAPELLA + ////////// + MAX_BLS_TO_EXECUTION_CHANGES: 16, + MAX_WITHDRAWALS_PER_PAYLOAD: 16, + MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: 16384, + + // DENEB + /////////// + // https://github.com/ethereum/consensus-specs/blob/dev/presets/mainnet/eip4844.yaml + FIELD_ELEMENTS_PER_BLOB: 4096, + MAX_BLOB_COMMITMENTS_PER_BLOCK: 4096, + MAX_BLOBS_PER_BLOCK: 6, }; const presetMinimal = { @@ -129,15 +145,10 @@ const presetMinimal = { // 5 (plus 1.25) HYSTERESIS_UPWARD_MULTIPLIER: 5, - // Fork Choice - // --------------------------------------------------------------- - // 2**1 (= 1) - SAFE_SLOTS_TO_UPDATE_JUSTIFIED: 2, - // Gwei values // --------------------------------------------------------------- // 2**0 * 10**9 (= 1,000,000,000) Gwei - MIN_DEPOSIT_AMOUNT: BigInt(1000000000), + MIN_DEPOSIT_AMOUNT: 1000000000, // 2**5 * 10**9 (= 32,000,000,000) Gwei MAX_EFFECTIVE_BALANCE: 32000000000, // 2**0 * 10**9 (= 1,000,000,000) Gwei @@ -158,11 +169,11 @@ const presetMinimal = { // [customized] smaller state SLOTS_PER_HISTORICAL_ROOT: 64, /* -// 2**8 (= 256) epochs -MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256, -// [customized] higher frequency of committee turnover and faster time to acceptable voluntary exit -SHARD_COMMITTEE_PERIOD: 64, -*/ + // 2**8 (= 256) epochs + MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256, + // [customized] higher frequency of committee turnover and faster time to acceptable voluntary exit + SHARD_COMMITTEE_PERIOD: 64, + */ // 2**2 (= 4) epochs MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4, @@ -205,20 +216,38 @@ SHARD_COMMITTEE_PERIOD: 64, // 2**4 (= 16) MAX_VOLUNTARY_EXITS: 16, + // ALTAIR + ///////// SYNC_COMMITTEE_SIZE: 32, EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 8, INACTIVITY_PENALTY_QUOTIENT_ALTAIR: 50331648, MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR: 64, PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR: 2, - - INACTIVITY_PENALTY_QUOTIENT_MERGE: 16777216, - MIN_SLASHING_PENALTY_QUOTIENT_MERGE: 32, - PROPORTIONAL_SLASHING_MULTIPLIER_MERGE: 3, - + MIN_SYNC_COMMITTEE_PARTICIPANTS: 1, + UPDATE_TIMEOUT: 64, + + // BELLATRIX + //////////// + INACTIVITY_PENALTY_QUOTIENT_BELLATRIX: 16777216, + MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX: 32, + PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX: 3, MAX_BYTES_PER_TRANSACTION: 1073741824, MAX_TRANSACTIONS_PER_PAYLOAD: 1048576, BYTES_PER_LOGS_BLOOM: 256, MAX_EXTRA_DATA_BYTES: 32, + + // CAPELLA + ////////// + MAX_BLS_TO_EXECUTION_CHANGES: 16, + MAX_WITHDRAWALS_PER_PAYLOAD: 4, + MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: 16, + + // DENEB + /////////// + // https://github.com/ethereum/consensus-specs/blob/dev/presets/minimal/eip4844.yaml + FIELD_ELEMENTS_PER_BLOB: 4, + MAX_BLOB_COMMITMENTS_PER_BLOCK: 16, + MAX_BLOBS_PER_BLOCK: 6, }; export const preset = ACTIVE_PRESET === "mainnet" ? presetMainnet : presetMinimal; diff --git a/packages/ssz/test/lodestarTypes/phase0/index.ts b/packages/ssz/test/lodestarTypes/phase0/index.ts index 0a5a5875..a1361536 100644 --- a/packages/ssz/test/lodestarTypes/phase0/index.ts +++ b/packages/ssz/test/lodestarTypes/phase0/index.ts @@ -1,2 +1,3 @@ +export * from "./types"; export * as ts from "./types"; export * as ssz from "./sszTypes"; diff --git a/packages/ssz/test/lodestarTypes/phase0/sszTypes.ts b/packages/ssz/test/lodestarTypes/phase0/sszTypes.ts index 15961354..8700f597 100644 --- a/packages/ssz/test/lodestarTypes/phase0/sszTypes.ts +++ b/packages/ssz/test/lodestarTypes/phase0/sszTypes.ts @@ -8,7 +8,6 @@ import { VectorBasicType, VectorCompositeType, } from "../../../src"; -import * as primitiveSsz from "../primitive/sszTypes"; import { preset, MAX_REQUEST_BLOCKS, @@ -16,6 +15,7 @@ import { JUSTIFICATION_BITS_LENGTH, ATTESTATION_SUBNET_COUNT, } from "../params"; +import * as primitiveSsz from "../primitive/sszTypes"; const { EPOCHS_PER_ETH1_VOTING_PERIOD, @@ -36,10 +36,11 @@ const { const { Boolean, Bytes32, - UintBn64, UintNum64, + UintBn64, Slot, Epoch, + EpochInf, CommitteeIndex, ValidatorIndex, Gwei, @@ -56,6 +57,7 @@ const { export const AttestationSubnets = new BitVectorType(ATTESTATION_SUBNET_COUNT); +/** BeaconBlockHeader where slot is bounded by the clock, and values above it are invalid */ export const BeaconBlockHeader = new ContainerType( { slot: Slot, @@ -64,7 +66,19 @@ export const BeaconBlockHeader = new ContainerType( stateRoot: Root, bodyRoot: Root, }, - {typeName: "BeaconBlockHeader", jsonCase: "eth2"} + {typeName: "BeaconBlockHeader", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +/** BeaconBlockHeader where slot is NOT bounded by the clock, i.e. slashings. So slot is a bigint. */ +export const BeaconBlockHeaderBigint = new ContainerType( + { + slot: UintBn64, + proposerIndex: ValidatorIndex, + parentRoot: Root, + stateRoot: Root, + bodyRoot: Root, + }, + {typeName: "BeaconBlockHeader", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const SignedBeaconBlockHeader = new ContainerType( @@ -75,6 +89,16 @@ export const SignedBeaconBlockHeader = new ContainerType( {typeName: "SignedBeaconBlockHeader", jsonCase: "eth2"} ); +/** Same as `SignedBeaconBlockHeader` but slot is not bounded by the clock and must be a bigint */ +export const SignedBeaconBlockHeaderBigint = new ContainerType( + { + message: BeaconBlockHeaderBigint, + signature: BLSSignature, + }, + {typeName: "SignedBeaconBlockHeader", jsonCase: "eth2"} +); + +/** Checkpoint where epoch is bounded by the clock, and values above it are invalid */ export const Checkpoint = new ContainerType( { epoch: Epoch, @@ -83,6 +107,15 @@ export const Checkpoint = new ContainerType( {typeName: "Checkpoint", jsonCase: "eth2"} ); +/** Checkpoint where epoch is NOT bounded by the clock, so must be a bigint */ +export const CheckpointBigint = new ContainerType( + { + epoch: UintBn64, + root: Root, + }, + {typeName: "Checkpoint", jsonCase: "eth2"} +); + export const CommitteeBits = new BitListType(MAX_VALIDATORS_PER_COMMITTEE); export const CommitteeIndices = new ListBasicType(ValidatorIndex, MAX_VALIDATORS_PER_COMMITTEE); @@ -185,16 +218,28 @@ export const HistoricalBatch = new ContainerType( {typeName: "HistoricalBatch", jsonCase: "eth2"} ); +/** + * Non-spec'ed helper type to allow efficient hashing in epoch transition. + * This type is like a 'Header' of HistoricalBatch where its fields are hashed. + */ +export const HistoricalBatchRoots = new ContainerType( + { + blockRoots: Root, // Hashed HistoricalBlockRoots + stateRoots: Root, // Hashed HistoricalStateRoots + }, + {typeName: "HistoricalBatchRoots", jsonCase: "eth2"} +); + export const ValidatorContainer = new ContainerType( { pubkey: BLSPubkey, withdrawalCredentials: Bytes32, effectiveBalance: UintNum64, slashed: Boolean, - activationEligibilityEpoch: Epoch, - activationEpoch: Epoch, - exitEpoch: Epoch, - withdrawableEpoch: Epoch, + activationEligibilityEpoch: EpochInf, + activationEpoch: EpochInf, + exitEpoch: EpochInf, + withdrawableEpoch: EpochInf, }, {typeName: "Validator", jsonCase: "eth2"} ); @@ -220,7 +265,19 @@ export const AttestationData = new ContainerType( source: Checkpoint, target: Checkpoint, }, - {typeName: "AttestationData", jsonCase: "eth2"} + {typeName: "AttestationData", jsonCase: "eth2", cachePermanentRootStruct: true} +); + +/** Same as `AttestationData` but epoch, slot and index are not bounded and must be a bigint */ +export const AttestationDataBigint = new ContainerType( + { + slot: UintBn64, + index: UintBn64, + beaconBlockRoot: Root, + source: CheckpointBigint, + target: CheckpointBigint, + }, + {typeName: "AttestationData", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const IndexedAttestation = new ContainerType( @@ -232,6 +289,16 @@ export const IndexedAttestation = new ContainerType( {typeName: "IndexedAttestation", jsonCase: "eth2"} ); +/** Same as `IndexedAttestation` but epoch, slot and index are not bounded and must be a bigint */ +export const IndexedAttestationBigint = new ContainerType( + { + attestingIndices: CommitteeIndices, + data: AttestationDataBigint, + signature: BLSSignature, + }, + {typeName: "IndexedAttestation", jsonCase: "eth2"} +); + export const PendingAttestation = new ContainerType( { aggregationBits: CommitteeBits, @@ -264,8 +331,11 @@ export const Attestation = new ContainerType( export const AttesterSlashing = new ContainerType( { - attestation1: IndexedAttestation, - attestation2: IndexedAttestation, + // In state transition, AttesterSlashing attestations are only partially validated. Their slot and epoch could + // be higher than the clock and the slashing would still be valid. Same applies to attestation data index, which + // can be any arbitrary value. Must use bigint variants to hash correctly to all possible values + attestation1: IndexedAttestationBigint, + attestation2: IndexedAttestationBigint, }, {typeName: "AttesterSlashing", jsonCase: "eth2"} ); @@ -280,8 +350,10 @@ export const Deposit = new ContainerType( export const ProposerSlashing = new ContainerType( { - signedHeader1: SignedBeaconBlockHeader, - signedHeader2: SignedBeaconBlockHeader, + // In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the + // clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values + signedHeader1: SignedBeaconBlockHeaderBigint, + signedHeader2: SignedBeaconBlockHeaderBigint, }, {typeName: "ProposerSlashing", jsonCase: "eth2"} ); @@ -291,7 +363,7 @@ export const VoluntaryExit = new ContainerType( epoch: Epoch, validatorIndex: ValidatorIndex, }, - {typeName: "VoluntaryExit", jsonCase: "eth2"} + {typeName: "VoluntaryExit", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const SignedVoluntaryExit = new ContainerType( @@ -316,7 +388,7 @@ export const BeaconBlockBody = new ContainerType( deposits: new ListCompositeType(Deposit, MAX_DEPOSITS), voluntaryExits: new ListCompositeType(SignedVoluntaryExit, MAX_VOLUNTARY_EXITS), }, - {typeName: "BeaconBlockBody", jsonCase: "eth2"} + {typeName: "BeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const BeaconBlock = new ContainerType( @@ -327,7 +399,7 @@ export const BeaconBlock = new ContainerType( stateRoot: Root, body: BeaconBlockBody, }, - {typeName: "BeaconBlock", jsonCase: "eth2"} + {typeName: "BeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const SignedBeaconBlock = new ContainerType( @@ -395,7 +467,7 @@ export const AggregateAndProof = new ContainerType( aggregate: Attestation, selectionProof: BLSSignature, }, - {typeName: "AggregateAndProof", jsonCase: "eth2"} + {typeName: "AggregateAndProof", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const SignedAggregateAndProof = new ContainerType( diff --git a/packages/ssz/test/lodestarTypes/phase0/types.ts b/packages/ssz/test/lodestarTypes/phase0/types.ts index 0214687b..dc877ead 100644 --- a/packages/ssz/test/lodestarTypes/phase0/types.ts +++ b/packages/ssz/test/lodestarTypes/phase0/types.ts @@ -3,10 +3,12 @@ import * as ssz from "./sszTypes"; export type AttestationSubnets = ValueOf; export type BeaconBlockHeader = ValueOf; +export type BeaconBlockHeaderBigint = ValueOf; export type SignedBeaconBlockHeader = ValueOf; +export type SignedBeaconBlockHeaderBigint = ValueOf; export type Checkpoint = ValueOf; export type DepositMessage = ValueOf; -export type DepositData = ValueOf; +export type DepositData = ValueOf; export type DepositEvent = ValueOf; export type Eth1Data = ValueOf; export type Eth1DataOrdered = ValueOf; @@ -16,8 +18,11 @@ export type ForkData = ValueOf; export type ENRForkID = ValueOf; export type HistoricalBatch = ValueOf; export type Validator = ValueOf; +export type Validators = ValueOf; export type AttestationData = ValueOf; +export type AttestationDataBigint = ValueOf; export type IndexedAttestation = ValueOf; +export type IndexedAttestationBigint = ValueOf; export type PendingAttestation = ValueOf; export type SigningData = ValueOf; export type Attestation = ValueOf; diff --git a/packages/ssz/test/lodestarTypes/primitive/sszTypes.ts b/packages/ssz/test/lodestarTypes/primitive/sszTypes.ts index 7cd2fc92..61d4f162 100644 --- a/packages/ssz/test/lodestarTypes/primitive/sszTypes.ts +++ b/packages/ssz/test/lodestarTypes/primitive/sszTypes.ts @@ -18,14 +18,41 @@ export const UintBn128 = new UintBigintType(16); export const UintBn256 = new UintBigintType(32); // Custom types, defined for type hinting and readability -export const Slot = UintNumInf64; -export const Epoch = UintNumInf64; + +/** + * Use JS Number for performance, values must be limited to 2**52-1. + * Slot is a time unit, so in all usages it's bounded by the clock, ensuring < 2**53-1 + */ +export const Slot = UintNum64; +/** + * Use JS Number for performance, values must be limited to 2**52-1. + * Epoch is a time unit, so in all usages it's bounded by the clock, ensuring < 2**53-1 + */ +export const Epoch = UintNum64; +/** Same as @see Epoch + some validator properties must represent 2**52-1 also, which we map to `Infinity` */ +export const EpochInf = UintNumInf64; +/** + * Use JS Number for performance, values must be limited to 2**52-1. + * SyncPeriod is a time unit, so in all usages it's bounded by the clock, ensuring < 2**53-1 + */ export const SyncPeriod = UintNum64; +/** + * Use JS Number for performance, values must be limited to 2**52-1. + * CommitteeIndex is bounded by the max possible number of committees which is bounded by `VALIDATOR_REGISTRY_LIMIT` + */ export const CommitteeIndex = UintNum64; +/** @see CommitteeIndex */ export const SubcommitteeIndex = UintNum64; +/** + * Use JS Number for performance, values must be limited to 2**52-1. + * ValidatorIndex is bounded by `VALIDATOR_REGISTRY_LIMIT` + */ export const ValidatorIndex = UintNum64; +export const WithdrawalIndex = UintNum64; export const Gwei = UintBn64; +export const Wei = UintBn256; export const Root = new ByteVectorType(32); +export const BlobIndex = UintNum64; export const Version = Bytes4; export const DomainType = Bytes4; diff --git a/packages/ssz/test/lodestarTypes/primitive/types.ts b/packages/ssz/test/lodestarTypes/primitive/types.ts index ef03f0ec..a4314d3e 100644 --- a/packages/ssz/test/lodestarTypes/primitive/types.ts +++ b/packages/ssz/test/lodestarTypes/primitive/types.ts @@ -28,7 +28,10 @@ export type SyncPeriod = UintNum64; export type CommitteeIndex = UintNum64; export type SubcommitteeIndex = UintNum64; export type ValidatorIndex = UintNum64; +export type WithdrawalIndex = UintNum64; +export type BlobIndex = UintNum64; export type Gwei = UintBn64; +export type Wei = UintBn256; export type Root = Bytes32; export type Version = Bytes4; export type DomainType = Bytes4; @@ -42,3 +45,5 @@ export type ExecutionAddress = Bytes20; /** Common non-spec type to represent roots as strings */ export type RootHex = string; +/** Non-spec type to signal time is represented in seconds */ +export type TimeSeconds = number; diff --git a/packages/ssz/test/lodestarTypes/sszTypes.ts b/packages/ssz/test/lodestarTypes/sszTypes.ts index ced5ef6b..9e0fd409 100644 --- a/packages/ssz/test/lodestarTypes/sszTypes.ts +++ b/packages/ssz/test/lodestarTypes/sszTypes.ts @@ -2,6 +2,12 @@ export * from "./primitive/sszTypes"; export {ssz as phase0} from "./phase0"; export {ssz as altair} from "./altair"; export {ssz as bellatrix} from "./bellatrix"; +export {ssz as capella} from "./capella"; +export {ssz as deneb} from "./deneb"; import {ssz as allForksSsz} from "./allForks"; export const allForks = allForksSsz.allForks; +export const allForksBlinded = allForksSsz.allForksBlinded; +export const allForksExecution = allForksSsz.allForksExecution; +export const allForksBlobs = allForksSsz.allForksBlobs; +export const allForksLightClient = allForksSsz.allForksLightClient; diff --git a/packages/ssz/test/lodestarTypes/types.ts b/packages/ssz/test/lodestarTypes/types.ts index a3aef1cf..477ee9c4 100644 --- a/packages/ssz/test/lodestarTypes/types.ts +++ b/packages/ssz/test/lodestarTypes/types.ts @@ -1,9 +1,22 @@ +import {Slot} from "./primitive/types"; + export * from "./primitive/types"; export {ts as phase0} from "./phase0"; export {ts as altair} from "./altair"; export {ts as bellatrix} from "./bellatrix"; +export {ts as capella} from "./capella"; +export {ts as deneb} from "./deneb"; export {ts as allForks} from "./allForks"; /** Common non-spec type to represent roots as strings */ export type RootHex = string; + +/** Handy enum to represent the block production source */ +export enum ProducedBlockSource { + builder = "builder", + engine = "engine", +} + +export type SlotRootHex = {slot: Slot; root: RootHex}; +export type SlotOptionalRoot = {slot: Slot; root?: RootHex}; diff --git a/packages/ssz/test/lodestarTypes/utils/StringType.ts b/packages/ssz/test/lodestarTypes/utils/StringType.ts new file mode 100644 index 00000000..0c60a0a9 --- /dev/null +++ b/packages/ssz/test/lodestarTypes/utils/StringType.ts @@ -0,0 +1,55 @@ +import {BasicType} from "../../../src"; + +export class StringType extends BasicType { + readonly typeName = "string"; + byteLength = 0; + fixedSize = 0; + minSize = 0; + maxSize = 0; + + defaultValue(): T { + return "" as T; + } + + // Serialization + deserialization + + value_serializeToBytes(): number { + throw Error("Not supported in String type"); + } + value_deserializeFromBytes(): T { + throw Error("Not supported in String type"); + } + tree_serializeToBytes(): number { + throw Error("Not supported in String type"); + } + tree_deserializeFromBytes(): never { + throw Error("Not supported in String type"); + } + + // Fast tree opts + + tree_getFromNode(): T { + throw Error("Not supported in String type"); + } + tree_setToNode(): void { + throw Error("Not supported in String type"); + } + tree_getFromPackedNode(): T { + throw Error("Not supported in String type"); + } + tree_setToPackedNode(): void { + throw Error("Not supported in String type"); + } + + // JSON + + fromJson(json: unknown): T { + return json as T; + } + + toJson(value: T): unknown { + return value; + } +} + +export const stringType = new StringType(); diff --git a/packages/ssz/test/lodestarTypes/utils/lazyVar.ts b/packages/ssz/test/lodestarTypes/utils/lazyVar.ts deleted file mode 100644 index 9378501d..00000000 --- a/packages/ssz/test/lodestarTypes/utils/lazyVar.ts +++ /dev/null @@ -1,12 +0,0 @@ -export class LazyVariable { - private var: {set: false} | {set: true; value: T} = {set: false}; - - get(): T { - if (!this.var.set) throw Error("variable not set"); - return this.var.value; - } - - set(value: T): void { - this.var = {set: true, value}; - } -} diff --git a/packages/ssz/test/lodestarTypes/utils/typeguards.ts b/packages/ssz/test/lodestarTypes/utils/typeguards.ts new file mode 100644 index 00000000..09d79ac3 --- /dev/null +++ b/packages/ssz/test/lodestarTypes/utils/typeguards.ts @@ -0,0 +1,43 @@ +import { + FullOrBlindedBeaconBlock, + FullOrBlindedSignedBeaconBlock, + FullOrBlindedBeaconBlockBody, + FullOrBlindedExecutionPayload, + ExecutionPayloadHeader, + FullOrBlindedBlobSidecar, + FullOrBlindedSignedBlobSidecar, + BlindedBeaconBlockBody, + BlindedBeaconBlock, +} from "../allForks/types"; +import {ts as bellatrix} from "../bellatrix"; +import {ts as deneb} from "../deneb"; + +export function isBlindedExecution(payload: FullOrBlindedExecutionPayload): payload is ExecutionPayloadHeader { + // we just check transactionsRoot for determinging as it the base field + // that is present and differs from ExecutionPayload for all forks + return (payload as ExecutionPayloadHeader).transactionsRoot !== undefined; +} + +export function isBlindedBeaconBlock(block: FullOrBlindedBeaconBlock): block is BlindedBeaconBlock { + return isBlindedBeaconBlockBody(block.body); +} + +export function isBlindedBeaconBlockBody(body: FullOrBlindedBeaconBlockBody): body is BlindedBeaconBlockBody { + return (body as BlindedBeaconBlockBody).executionPayloadHeader !== undefined; +} + +export function isBlindedSignedBeaconBlock( + signedBlock: FullOrBlindedSignedBeaconBlock +): signedBlock is bellatrix.SignedBlindedBeaconBlock { + return (signedBlock as bellatrix.SignedBlindedBeaconBlock).message.body.executionPayloadHeader !== undefined; +} + +export function isBlindedBlobSidecar(blob: FullOrBlindedBlobSidecar): blob is deneb.BlindedBlobSidecar { + return (blob as deneb.BlindedBlobSidecar).blobRoot !== undefined; +} + +export function isBlindedSignedBlobSidecar( + blob: FullOrBlindedSignedBlobSidecar +): blob is deneb.SignedBlindedBlobSidecar { + return (blob as deneb.SignedBlindedBlobSidecar).message.blobRoot !== undefined; +} diff --git a/packages/ssz/test/specTestVersioning.ts b/packages/ssz/test/specTestVersioning.ts index 432e04f3..eaa96504 100644 --- a/packages/ssz/test/specTestVersioning.ts +++ b/packages/ssz/test/specTestVersioning.ts @@ -8,5 +8,5 @@ import path from "path"; // The contents of this file MUST include the URL, version and target path, and nothing else. export const SPEC_TEST_REPO_URL = "https://github.com/ethereum/consensus-spec-tests"; -export const SPEC_TEST_VERSION = "v1.1.10"; +export const SPEC_TEST_VERSION = "v1.4.0-beta.1"; export const SPEC_TEST_LOCATION = path.join(__dirname, "../spec-tests"); diff --git a/packages/ssz/test/unit/eth2/allForks.test.ts b/packages/ssz/test/unit/eth2/allForks.test.ts index 2e2c704f..ea4f2b37 100644 --- a/packages/ssz/test/unit/eth2/allForks.test.ts +++ b/packages/ssz/test/unit/eth2/allForks.test.ts @@ -15,10 +15,17 @@ describe("Eth2 allForks BeaconState, non-cached and cached", () => { type BeaconStatePhase0 = CompositeViewDU; type BeaconStateAltair = CompositeViewDU; type BeaconStateBellatrix = CompositeViewDU; + type BeaconStateCapella = CompositeViewDU; + type BeaconStateDeneb = CompositeViewDU; // Union at the TreeViewDU level // Equivalent to CompositeViewDU - type BeaconStateAllForks = BeaconStatePhase0 | BeaconStateAltair | BeaconStateBellatrix; + type BeaconStateAllForks = + | BeaconStatePhase0 + | BeaconStateAltair + | BeaconStateBellatrix + | BeaconStateCapella + | BeaconStateDeneb; // Union at the fields level // NOTE: using this type for CachedBeaconStateAllForks makes single fork BeaconState types incompatible to it @@ -378,6 +385,8 @@ describe("Eth2 allForks BeaconState, non-cached and cached", () => { | CompositeView | CompositeView | CompositeView + | CompositeView + | CompositeView ): void { state; } @@ -386,6 +395,8 @@ describe("Eth2 allForks BeaconState, non-cached and cached", () => { | CompositeViewDU | CompositeViewDU | CompositeViewDU + | CompositeViewDU + | CompositeViewDU ): void { state; } diff --git a/packages/ssz/test/unit/eth2/minMaxSize.test.ts b/packages/ssz/test/unit/eth2/minMaxSize.test.ts index 220ce8a6..695768f9 100644 --- a/packages/ssz/test/unit/eth2/minMaxSize.test.ts +++ b/packages/ssz/test/unit/eth2/minMaxSize.test.ts @@ -13,8 +13,11 @@ describe("Get minSize and maxSize of eth2 data structures", () => { phase0: { AttestationSubnets: {minSize: 8, maxSize: 8}, BeaconBlockHeader: {minSize: 112, maxSize: 112}, + BeaconBlockHeaderBigint: {minSize: 112, maxSize: 112}, SignedBeaconBlockHeader: {minSize: 208, maxSize: 208}, + SignedBeaconBlockHeaderBigint: {minSize: 208, maxSize: 208}, Checkpoint: {minSize: 40, maxSize: 40}, + CheckpointBigint: {minSize: 40, maxSize: 40}, CommitteeBits: {minSize: 1, maxSize: 257}, CommitteeIndices: {minSize: 0, maxSize: 16384}, DepositMessage: {minSize: 88, maxSize: 88}, @@ -40,7 +43,9 @@ describe("Get minSize and maxSize of eth2 data structures", () => { Slashings: {minSize: 512, maxSize: 512}, JustificationBits: {minSize: 1, maxSize: 1}, AttestationData: {minSize: 128, maxSize: 128}, + AttestationDataBigint: {minSize: 128, maxSize: 128}, IndexedAttestation: {minSize: 228, maxSize: 16612}, + IndexedAttestationBigint: {minSize: 228, maxSize: 16612}, PendingAttestation: {minSize: 149, maxSize: 405}, SigningData: {minSize: 64, maxSize: 64}, Attestation: {minSize: 229, maxSize: 485}, @@ -64,6 +69,7 @@ describe("Get minSize and maxSize of eth2 data structures", () => { BeaconBlocksByRangeRequest: {minSize: 24, maxSize: 24}, BeaconBlocksByRootRequest: {minSize: 0, maxSize: 32768}, Genesis: {minSize: 44, maxSize: 44}, + HistoricalBatchRoots: {minSize: 64, maxSize: 64}, }, altair: { SyncSubnets: {minSize: 1, maxSize: 1}, @@ -86,8 +92,13 @@ describe("Get minSize and maxSize of eth2 data structures", () => { InactivityScores: {minSize: 0, maxSize: 8796093022208}, BeaconState: {minSize: 10229, maxSize: 152832653144309}, LightClientSnapshot: {minSize: 3280, maxSize: 3280}, - LightClientUpdate: {minSize: 2264, maxSize: 2264}, - LightClientStore: {minSize: 3284, maxSize: 148180}, + LightClientUpdate: {minSize: 2268, maxSize: 2268}, + LightClientStore: {minSize: 1860, maxSize: 147012}, + LightClientHeader: {minSize: 112, maxSize: 112}, + LightClientBootstrap: {minSize: 1856, maxSize: 1856}, + LightClientFinalityUpdate: {minSize: 524, maxSize: 524}, + LightClientOptimisticUpdate: {minSize: 220, maxSize: 220}, + LightClientUpdatesByRange: {minSize: 16, maxSize: 16}, }, bellatrix: { Transaction: {minSize: 0, maxSize: 1073741824}, @@ -102,6 +113,17 @@ describe("Get minSize and maxSize of eth2 data structures", () => { HistoricalStateRoots: {minSize: 2048, maxSize: 2048}, HistoricalBatch: {minSize: 4096, maxSize: 4096}, BeaconState: {minSize: 10769, maxSize: 152832653144881}, + CommonExecutionPayloadType: {minSize: 504, maxSize: 536}, + BlindedBeaconBlockBody: {minSize: 860, maxSize: 158244}, + BlindedBeaconBlock: {minSize: 944, maxSize: 158328}, + SignedBlindedBeaconBlock: {minSize: 1044, maxSize: 158428}, + ValidatorRegistrationV1: {minSize: 84, maxSize: 84}, + SignedValidatorRegistrationV1: {minSize: 180, maxSize: 180}, + BuilderBid: {minSize: 620, maxSize: 652}, + SignedBuilderBid: {minSize: 720, maxSize: 752}, + PayloadAttributes: {minSize: 40, maxSize: 40}, + SSEPayloadAttributesCommon: {minSize: 88, maxSize: 88}, + SSEPayloadAttributes: {minSize: 128, maxSize: 128}, }, };