From a16de4c47826a36acc4041cebfb2a574b35ab8aa Mon Sep 17 00:00:00 2001 From: harkamal Date: Sun, 27 Aug 2023 17:57:24 +0530 Subject: [PATCH] get the types to match current kaustinen network --- packages/types/src/verge/sszTypes.ts | 80 +++++++++++++++++----------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/packages/types/src/verge/sszTypes.ts b/packages/types/src/verge/sszTypes.ts index 402944d5f939..c7e15942e7dd 100644 --- a/packages/types/src/verge/sszTypes.ts +++ b/packages/types/src/verge/sszTypes.ts @@ -3,9 +3,8 @@ import { ListCompositeType, ByteVectorType, VectorCompositeType, - ListBasicType, - UnionType, - NoneType, + ByteListType, + OptionalType, } from "@chainsafe/ssz"; import { HISTORICAL_ROOTS_LIMIT, @@ -17,8 +16,9 @@ import { import {ssz as primitiveSsz} from "../primitive/index.js"; import {ssz as phase0Ssz} from "../phase0/index.js"; import {ssz as altairSsz} from "../altair/index.js"; -import {ssz as capellaSsz} from "../capella/index.js"; -import {ssz as denebSsz} from "../deneb/index.js"; +import {ssz as bellatrixSsz} from "../bellatrix/index.js"; +// import {ssz as capellaSsz} from "../capella/index.js"; +// import {ssz as denebSsz} from "../deneb/index.js"; const {UintNum64, Root, BLSSignature} = primitiveSsz; @@ -38,11 +38,20 @@ export const SuffixStateDiff = new ContainerType( suffix: primitiveSsz.Byte, // Null means not currently present // TODO: Use new SSZ type Optional: https://github.com/ethereum/consensus-specs/commit/db74090c1e8dc1fb2c052bae268e22dc63061e32 - currentValue: new UnionType([new NoneType(), primitiveSsz.Bytes32]), + currentValue: new OptionalType(primitiveSsz.Bytes32), + // newValue not present for the kaustenine network // Null means value not updated - newValue: new UnionType([new NoneType(), primitiveSsz.Bytes32]), + // newValue: new OptionalType(primitiveSsz.Bytes32), }, - {typeName: "SuffixStateDiff", jsonCase: "eth2"} + { + typeName: "SuffixStateDiff", + casingMap: { + suffix: "suffix", + currentValue: "currentValue", + // newValue not present for the kaustenine network + // newValue: "newValue" + }, + } ); export const StemStateDiff = new ContainerType( @@ -51,7 +60,7 @@ export const StemStateDiff = new ContainerType( // Valid only if list is sorted by suffixes suffixDiffs: new ListCompositeType(SuffixStateDiff, VERKLE_WIDTH), }, - {typeName: "StemStateDiff", jsonCase: "eth2"} + {typeName: "StemStateDiff", casingMap: {stem: "stem", suffixDiffs: "suffixDiffs"}} ); // Valid only if list is sorted by stems @@ -59,30 +68,39 @@ export const StateDiff = new ListCompositeType(StemStateDiff, MAX_STEMS); export const IpaProof = new ContainerType( { - C_L: new VectorCompositeType(BanderwagonGroupElement, IPA_PROOF_DEPTH), - C_R: new VectorCompositeType(BanderwagonGroupElement, IPA_PROOF_DEPTH), + cl: new VectorCompositeType(BanderwagonGroupElement, IPA_PROOF_DEPTH), + cr: new VectorCompositeType(BanderwagonGroupElement, IPA_PROOF_DEPTH), finalEvaluation: BanderwagonFieldElement, }, - {typeName: "IpaProof", jsonCase: "eth2"} + {typeName: "IpaProof", casingMap: {cl: "cl", cr: "cr", finalEvaluation: "finalEvaluation"}} ); export const VerkleProof = new ContainerType( { - other_stems: new ListCompositeType(Bytes31, MAX_STEMS), - depth_extension_present: new ListBasicType(primitiveSsz.Uint8, MAX_STEMS), - commitments_by_path: new ListCompositeType(BanderwagonGroupElement, MAX_STEMS * MAX_COMMITMENTS_PER_STEM), - D: BanderwagonGroupElement, + otherStems: new ListCompositeType(Bytes31, MAX_STEMS), + depthExtensionPresent: new ByteListType(MAX_STEMS), + commitmentsByPath: new ListCompositeType(BanderwagonGroupElement, MAX_STEMS * MAX_COMMITMENTS_PER_STEM), + d: BanderwagonGroupElement, ipaProof: IpaProof, }, - {typeName: "VerkleProof", jsonCase: "eth2"} + { + typeName: "VerkleProof", + casingMap: { + otherStems: "otherStems", + depthExtensionPresent: "depthExtensionPresent", + commitmentsByPath: "commitmentsByPath", + d: "d", + ipaProof: "ipaProof", + }, + } ); export const ExecutionWitness = new ContainerType( { - state_diff: StateDiff, - verkle_proof: VerkleProof, + stateDiff: StateDiff, + verkleProof: VerkleProof, }, - {typeName: "ExecutionWitness", jsonCase: "eth2"} + {typeName: "ExecutionWitness", casingMap: {stateDiff: "stateDiff", verkleProof: "verkleProof"}} ); // Beacon Chain types @@ -90,7 +108,7 @@ export const ExecutionWitness = new ContainerType( export const ExecutionPayload = new ContainerType( { - ...denebSsz.ExecutionPayload.fields, + ...bellatrixSsz.ExecutionPayload.fields, executionWitness: ExecutionWitness, // New in verge }, {typeName: "ExecutionPayload", jsonCase: "eth2"} @@ -98,8 +116,8 @@ export const ExecutionPayload = new ContainerType( export const ExecutionPayloadHeader = new ContainerType( { - ...denebSsz.ExecutionPayloadHeader.fields, - executionWitness: ExecutionWitness, // New in verge + ...bellatrixSsz.ExecutionPayloadHeader.fields, + executionWitnessRoot: Root, // New in verge }, {typeName: "ExecutionPayloadHeader", jsonCase: "eth2"} ); @@ -109,15 +127,15 @@ export const BeaconBlockBody = new ContainerType( { ...altairSsz.BeaconBlockBody.fields, executionPayload: ExecutionPayload, // Modified in verge - blsToExecutionChanges: capellaSsz.BeaconBlockBody.fields.blsToExecutionChanges, - blobKzgCommitments: denebSsz.BlobKzgCommitments, + // blsToExecutionChanges: capellaSsz.BeaconBlockBody.fields.blsToExecutionChanges, + // blobKzgCommitments: denebSsz.BlobKzgCommitments, }, {typeName: "BeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const BeaconBlock = new ContainerType( { - ...denebSsz.BeaconBlock.fields, + ...bellatrixSsz.BeaconBlock.fields, body: BeaconBlockBody, // Modified in verge }, {typeName: "BeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} @@ -135,14 +153,14 @@ export const BlindedBeaconBlockBody = new ContainerType( { ...BeaconBlockBody.fields, executionPayloadHeader: ExecutionPayloadHeader, // Modified in verge - blobKzgCommitments: denebSsz.BlobKzgCommitments, + // blobKzgCommitments: denebSsz.BlobKzgCommitments, }, {typeName: "BlindedBeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true} ); export const BlindedBeaconBlock = new ContainerType( { - ...denebSsz.BlindedBeaconBlock.fields, + ...bellatrixSsz.BlindedBeaconBlock.fields, body: BlindedBeaconBlockBody, // Modified in DENEB }, {typeName: "BlindedBeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true} @@ -196,10 +214,10 @@ export const BeaconState = new ContainerType( // Execution latestExecutionPayloadHeader: ExecutionPayloadHeader, // Modified in verge // Withdrawals - nextWithdrawalIndex: capellaSsz.BeaconState.fields.nextWithdrawalIndex, - nextWithdrawalValidatorIndex: capellaSsz.BeaconState.fields.nextWithdrawalValidatorIndex, + // nextWithdrawalIndex: capellaSsz.BeaconState.fields.nextWithdrawalIndex, + // nextWithdrawalValidatorIndex: capellaSsz.BeaconState.fields.nextWithdrawalValidatorIndex, // Deep history valid from Capella onwards - historicalSummaries: capellaSsz.BeaconState.fields.historicalSummaries, + // historicalSummaries: capellaSsz.BeaconState.fields.historicalSummaries, }, {typeName: "BeaconState", jsonCase: "eth2"} );