diff --git a/beacon/blsync/engineclient.go b/beacon/blsync/engineclient.go index f9000a512a..77bee83f5b 100644 --- a/beacon/blsync/engineclient.go +++ b/beacon/blsync/engineclient.go @@ -140,7 +140,7 @@ func (ec *engineClient) callForkchoiceUpdated(fork string, event types.ChainHead var method string switch fork { - case "deneb": + case "deneb", "electra": method = "engine_forkchoiceUpdatedV3" case "capella": method = "engine_forkchoiceUpdatedV2" diff --git a/beacon/light/api/light_api.go b/beacon/light/api/light_api.go index 91f66c08be..f9a5aae153 100755 --- a/beacon/light/api/light_api.go +++ b/beacon/light/api/light_api.go @@ -43,7 +43,6 @@ var ( ) type CommitteeUpdate struct { - Version string Update types.LightClientUpdate NextSyncCommittee types.SerializedSyncCommittee } @@ -81,9 +80,9 @@ func (u *CommitteeUpdate) UnmarshalJSON(input []byte) error { if err := json.Unmarshal(input, &dec); err != nil { return err } - u.Version = dec.Version u.NextSyncCommittee = dec.Data.NextSyncCommittee u.Update = types.LightClientUpdate{ + Version: dec.Version, AttestedHeader: types.SignedHeader{ Header: dec.Data.Header.Beacon, Signature: dec.Data.SyncAggregate, @@ -206,7 +205,7 @@ func (api *BeaconLightApi) GetOptimisticUpdate() (types.OptimisticUpdate, error) func decodeOptimisticUpdate(enc []byte) (types.OptimisticUpdate, error) { var data struct { - Version string + Version string `json:"version"` Data struct { Attested jsonHeaderWithExecProof `json:"attested_header"` Aggregate types.SyncAggregate `json:"sync_aggregate"` @@ -259,7 +258,7 @@ func (api *BeaconLightApi) GetFinalityUpdate() (types.FinalityUpdate, error) { func decodeFinalityUpdate(enc []byte) (types.FinalityUpdate, error) { var data struct { - Version string + Version string `json:"version"` Data struct { Attested jsonHeaderWithExecProof `json:"attested_header"` Finalized jsonHeaderWithExecProof `json:"finalized_header"` @@ -289,6 +288,7 @@ func decodeFinalityUpdate(enc []byte) (types.FinalityUpdate, error) { } return types.FinalityUpdate{ + Version: data.Version, Attested: types.HeaderWithExecProof{ Header: data.Data.Attested.Beacon, PayloadHeader: attestedExecHeader, @@ -355,7 +355,8 @@ func (api *BeaconLightApi) GetCheckpointData(checkpointHash common.Hash) (*types // See data structure definition here: // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#lightclientbootstrap type bootstrapData struct { - Data struct { + Version string `json:"version"` + Data struct { Header jsonBeaconHeader `json:"header"` Committee *types.SerializedSyncCommittee `json:"current_sync_committee"` CommitteeBranch merkle.Values `json:"current_sync_committee_branch"` @@ -374,6 +375,7 @@ func (api *BeaconLightApi) GetCheckpointData(checkpointHash common.Hash) (*types return nil, fmt.Errorf("invalid checkpoint block header, have %v want %v", header.Hash(), checkpointHash) } checkpoint := &types.BootstrapData{ + Version: data.Version, Header: header, CommitteeBranch: data.Data.CommitteeBranch, CommitteeRoot: data.Data.Committee.Root(), @@ -395,7 +397,7 @@ func (api *BeaconLightApi) GetBeaconBlock(blockRoot common.Hash) (*types.BeaconB } var beaconBlockMessage struct { - Version string + Version string `json:"version"` Data struct { Message json.RawMessage `json:"message"` } diff --git a/beacon/light/test_helpers.go b/beacon/light/test_helpers.go index 7bd19ca0ad..50e554b3d7 100644 --- a/beacon/light/test_helpers.go +++ b/beacon/light/test_helpers.go @@ -39,10 +39,10 @@ func GenerateTestUpdate(config *params.ChainConfig, period uint64, committee, ne var attestedHeader types.Header if finalizedHeader { update.FinalizedHeader = new(types.Header) - *update.FinalizedHeader, update.NextSyncCommitteeBranch = makeTestHeaderWithMerkleProof(types.SyncPeriodStart(period)+100, params.StateIndexNextSyncCommittee, merkle.Value(update.NextSyncCommitteeRoot)) - attestedHeader, update.FinalityBranch = makeTestHeaderWithMerkleProof(types.SyncPeriodStart(period)+200, params.StateIndexFinalBlock, merkle.Value(update.FinalizedHeader.Hash())) + *update.FinalizedHeader, update.NextSyncCommitteeBranch = makeTestHeaderWithMerkleProof(types.SyncPeriodStart(period)+100, params.StateIndexNextSyncCommittee(""), merkle.Value(update.NextSyncCommitteeRoot)) + attestedHeader, update.FinalityBranch = makeTestHeaderWithMerkleProof(types.SyncPeriodStart(period)+200, params.StateIndexFinalBlock(""), merkle.Value(update.FinalizedHeader.Hash())) } else { - attestedHeader, update.NextSyncCommitteeBranch = makeTestHeaderWithMerkleProof(types.SyncPeriodStart(period)+2000, params.StateIndexNextSyncCommittee, merkle.Value(update.NextSyncCommitteeRoot)) + attestedHeader, update.NextSyncCommitteeBranch = makeTestHeaderWithMerkleProof(types.SyncPeriodStart(period)+2000, params.StateIndexNextSyncCommittee(""), merkle.Value(update.NextSyncCommitteeRoot)) } update.AttestedHeader = GenerateTestSignedHeader(attestedHeader, config, committee, attestedHeader.Slot+1, signerCount) return update @@ -63,7 +63,7 @@ func GenerateTestSignedHeader(header types.Header, config *params.ChainConfig, c } func GenerateTestCheckpoint(period uint64, committee *types.SerializedSyncCommittee) *types.BootstrapData { - header, branch := makeTestHeaderWithMerkleProof(types.SyncPeriodStart(period)+200, params.StateIndexSyncCommittee, merkle.Value(committee.Root())) + header, branch := makeTestHeaderWithMerkleProof(types.SyncPeriodStart(period)+200, params.StateIndexSyncCommittee(""), merkle.Value(committee.Root())) return &types.BootstrapData{ Header: header, Committee: committee, diff --git a/beacon/params/networks.go b/beacon/params/networks.go index 1204e0176f..eda225e0fe 100644 --- a/beacon/params/networks.go +++ b/beacon/params/networks.go @@ -41,7 +41,8 @@ var ( AddFork("ALTAIR", 50, []byte{144, 0, 0, 112}). AddFork("BELLATRIX", 100, []byte{144, 0, 0, 113}). AddFork("CAPELLA", 56832, []byte{144, 0, 0, 114}). - AddFork("DENEB", 132608, []byte{144, 0, 0, 115}) + AddFork("DENEB", 132608, []byte{144, 0, 0, 115}). + AddFork("ELECTRA", 222464, []byte{144, 0, 0, 116}) HoleskyLightConfig = (&ChainConfig{ GenesisValidatorsRoot: common.HexToHash("0x9143aa7c615a7f7115e2b6aac319c03529df8242ae705fba9df39b79c59fa8b1"), @@ -52,5 +53,6 @@ var ( AddFork("ALTAIR", 0, []byte{2, 1, 112, 0}). AddFork("BELLATRIX", 0, []byte{3, 1, 112, 0}). AddFork("CAPELLA", 256, []byte{4, 1, 112, 0}). - AddFork("DENEB", 29696, []byte{5, 1, 112, 0}) + AddFork("DENEB", 29696, []byte{5, 1, 112, 0}). + AddFork("ELECTRA", 115968, []byte{6, 1, 112, 0}) ) diff --git a/beacon/params/params.go b/beacon/params/params.go index e4e0d00934..c6600cee5f 100644 --- a/beacon/params/params.go +++ b/beacon/params/params.go @@ -29,18 +29,46 @@ const ( ) const ( - StateIndexGenesisTime = 32 - StateIndexGenesisValidators = 33 - StateIndexForkVersion = 141 - StateIndexLatestHeader = 36 - StateIndexBlockRoots = 37 - StateIndexStateRoots = 38 - StateIndexHistoricRoots = 39 - StateIndexFinalBlock = 105 - StateIndexSyncCommittee = 54 - StateIndexNextSyncCommittee = 55 - StateIndexExecPayload = 56 - StateIndexExecHead = 908 + StateIndexGenesisTime = 32 + StateIndexGenesisValidators = 33 + StateIndexForkVersion = 141 + StateIndexLatestHeader = 36 + StateIndexBlockRoots = 37 + StateIndexStateRoots = 38 + StateIndexHistoricRoots = 39 + StateIndexFinalBlockOld = 105 + StateIndexFinalBlockElectra = 169 + StateIndexSyncCommitteeOld = 54 + StateIndexSyncCommitteeElectra = 86 + StateIndexNextSyncCommitteeOld = 55 + StateIndexNextSyncCommitteeElectra = 87 + StateIndexExecPayload = 56 + StateIndexExecHead = 908 BodyIndexExecPayload = 25 ) + +func StateIndexFinalBlock(forkName string) uint64 { + switch forkName { + case "bellatrix", "capella", "deneb": + return StateIndexFinalBlockOld + default: + return StateIndexFinalBlockElectra + } +} +func StateIndexSyncCommittee(forkName string) uint64 { + switch forkName { + case "bellatrix", "capella", "deneb": + return StateIndexSyncCommitteeOld + default: + return StateIndexSyncCommitteeElectra + } +} +func StateIndexNextSyncCommittee(forkName string) uint64 { + switch forkName { + case "bellatrix", "capella", "deneb": + return StateIndexNextSyncCommitteeOld + default: + return StateIndexNextSyncCommitteeElectra + } +} diff --git a/beacon/types/beacon_block.go b/beacon/types/beacon_block.go index 05dfd84791..a2e31d5abf 100644 --- a/beacon/types/beacon_block.go +++ b/beacon/types/beacon_block.go @@ -144,6 +144,7 @@ func (b *BeaconBlock) ExecutionRequestsList() [][]byte { func marshalRequests(spec *zrntcommon.Spec, items ...zrntcommon.SpecObj) (list [][]byte) { var buf bytes.Buffer + list = [][]byte{} for typ, data := range items { buf.Reset() buf.WriteByte(byte(typ)) diff --git a/beacon/types/light_sync.go b/beacon/types/light_sync.go index fa6041cf0e..128ee77f1b 100644 --- a/beacon/types/light_sync.go +++ b/beacon/types/light_sync.go @@ -36,6 +36,7 @@ type HeadInfo struct { // together with a proof through a beacon header and corresponding state. // Note: BootstrapData is fetched from a server based on a known checkpoint hash. type BootstrapData struct { + Version string Header Header CommitteeRoot common.Hash Committee *SerializedSyncCommittee `rlp:"-"` @@ -47,7 +48,7 @@ func (c *BootstrapData) Validate() error { if c.CommitteeRoot != c.Committee.Root() { return errors.New("wrong committee root") } - return merkle.VerifyProof(c.Header.StateRoot, params.StateIndexSyncCommittee, c.CommitteeBranch, merkle.Value(c.CommitteeRoot)) + return merkle.VerifyProof(c.Header.StateRoot, params.StateIndexSyncCommittee(c.Version), c.CommitteeBranch, merkle.Value(c.CommitteeRoot)) } // LightClientUpdate is a proof of the next sync committee root based on a header @@ -59,6 +60,7 @@ func (c *BootstrapData) Validate() error { // See data structure definition here: // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#lightclientupdate type LightClientUpdate struct { + Version string AttestedHeader SignedHeader // Arbitrary header out of the period signed by the sync committee NextSyncCommitteeRoot common.Hash // Sync committee of the next period advertised in the current one NextSyncCommitteeBranch merkle.Values // Proof for the next period's sync committee @@ -79,11 +81,11 @@ func (update *LightClientUpdate) Validate() error { if update.FinalizedHeader.SyncPeriod() != period { return errors.New("finalized header is from different period") } - if err := merkle.VerifyProof(update.AttestedHeader.Header.StateRoot, params.StateIndexFinalBlock, update.FinalityBranch, merkle.Value(update.FinalizedHeader.Hash())); err != nil { + if err := merkle.VerifyProof(update.AttestedHeader.Header.StateRoot, params.StateIndexFinalBlock(update.Version), update.FinalityBranch, merkle.Value(update.FinalizedHeader.Hash())); err != nil { return fmt.Errorf("invalid finalized header proof: %w", err) } } - if err := merkle.VerifyProof(update.AttestedHeader.Header.StateRoot, params.StateIndexNextSyncCommittee, update.NextSyncCommitteeBranch, merkle.Value(update.NextSyncCommitteeRoot)); err != nil { + if err := merkle.VerifyProof(update.AttestedHeader.Header.StateRoot, params.StateIndexNextSyncCommittee(update.Version), update.NextSyncCommitteeBranch, merkle.Value(update.NextSyncCommitteeRoot)); err != nil { return fmt.Errorf("invalid next sync committee proof: %w", err) } return nil @@ -194,6 +196,7 @@ func (u *OptimisticUpdate) Validate() error { // See data structure definition here: // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#lightclientfinalityupdate type FinalityUpdate struct { + Version string Attested, Finalized HeaderWithExecProof FinalityBranch merkle.Values // Sync committee BLS signature aggregate @@ -223,7 +226,7 @@ func (u *FinalityUpdate) Validate() error { if err := u.Finalized.Validate(); err != nil { return err } - return merkle.VerifyProof(u.Attested.StateRoot, params.StateIndexFinalBlock, u.FinalityBranch, merkle.Value(u.Finalized.Hash())) + return merkle.VerifyProof(u.Attested.StateRoot, params.StateIndexFinalBlock(u.Version), u.FinalityBranch, merkle.Value(u.Finalized.Hash())) } // ChainHeadEvent returns an authenticated execution payload associated with the