Skip to content

Commit

Permalink
get the types to match current kaustinen network
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Aug 27, 2023
1 parent ca236e9 commit a16de4c
Showing 1 changed file with 49 additions and 31 deletions.
80 changes: 49 additions & 31 deletions packages/types/src/verge/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import {
ListCompositeType,
ByteVectorType,
VectorCompositeType,
ListBasicType,
UnionType,
NoneType,
ByteListType,
OptionalType,
} from "@chainsafe/ssz";
import {
HISTORICAL_ROOTS_LIMIT,
Expand All @@ -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;

Expand All @@ -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(
Expand All @@ -51,55 +60,64 @@ 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
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
// https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/beacon-chain.md#containers

export const ExecutionPayload = new ContainerType(
{
...denebSsz.ExecutionPayload.fields,
...bellatrixSsz.ExecutionPayload.fields,
executionWitness: ExecutionWitness, // New in verge
},
{typeName: "ExecutionPayload", jsonCase: "eth2"}
);

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"}
);
Expand All @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -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"}
);

0 comments on commit a16de4c

Please sign in to comment.