Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electra upgrade #1283

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/relayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: setup go
uses: actions/checkout@v4
with:
go-version: '^1.20.1'
go-version: '^1.22.5'

- name: check go version
run: go version
Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

# ethereum
foundry-bin
go-ethereum
#go-ethereum Geth 1.14.9 is not in nix flakes yet
# gnupg for forge install
gnupg

Expand Down
2 changes: 1 addition & 1 deletion relayer/cmd/import_beacon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func importBeaconState(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("read finalized state data from file: %w", err)
}

afterDenebFork := (conf.Source.Beacon.Spec.DenebForkEpoch + 1) * 32
afterDenebFork := (conf.Source.Beacon.Spec.ForkVersions.Deneb + 1) * 32

attestedState, err := syncer.UnmarshalBeaconState(afterDenebFork, attestedData)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion relayer/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Build() {
}

func BuildMain() error {
err := sh.Run("sszgen", "--path", "relays/beacon/state", "--objs", "BeaconStateCapellaMainnet,BlockRootsContainerMainnet,TransactionsRootContainer,BeaconBlockCapellaMainnet,WithdrawalsRootContainerMainnet,BeaconStateDenebMainnet,BeaconBlockDenebMainnet")
err := sh.Run("sszgen", "--path", "relays/beacon/state", "--objs", "BeaconStateCapellaMainnet,BlockRootsContainerMainnet,TransactionsRootContainer,BeaconBlockCapellaMainnet,WithdrawalsRootContainerMainnet,BeaconStateDenebMainnet,BeaconBlockDenebMainnet,BeaconStateElectra,BeaconBlockElectra,DepositRequestsContainer,WithdrawalRequestsContainer,ConsolidationRequestsContainer")
if err != nil {
return err
}
Expand Down
13 changes: 9 additions & 4 deletions relayer/relays/beacon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ type Config struct {
}

type SpecSettings struct {
SyncCommitteeSize uint64 `mapstructure:"syncCommitteeSize"`
SlotsInEpoch uint64 `mapstructure:"slotsInEpoch"`
EpochsPerSyncCommitteePeriod uint64 `mapstructure:"epochsPerSyncCommitteePeriod"`
DenebForkEpoch uint64 `mapstructure:"denebForkedEpoch"`
SyncCommitteeSize uint64 `mapstructure:"syncCommitteeSize"`
SlotsInEpoch uint64 `mapstructure:"slotsInEpoch"`
EpochsPerSyncCommitteePeriod uint64 `mapstructure:"epochsPerSyncCommitteePeriod"`
ForkVersions ForkVersions `mapstructure:"forkVersions"`
}

type ForkVersions struct {
Deneb uint64 `mapstructure:"deneb"`
Electra uint64 `mapstructure:"electra"`
}

type SourceConfig struct {
Expand Down
19 changes: 14 additions & 5 deletions relayer/relays/beacon/header/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ func TestSyncInterimFinalizedUpdate_WithDataFromAPI(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -81,7 +84,10 @@ func TestSyncInterimFinalizedUpdate_WithDataFromStore(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -147,7 +153,10 @@ func TestSyncInterimFinalizedUpdate_WithDataFromStoreWithDifferentBlocks(t *test
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
ForkVersions: config.ForkVersions{
Deneb: 0,
Electra: 800000,
},
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -213,7 +222,7 @@ func TestSyncInterimFinalizedUpdate_BeaconStateNotAvailableInAPIAndStore(t *test
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
//DenebForkEpoch: 0,
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down Expand Up @@ -257,7 +266,7 @@ func TestSyncInterimFinalizedUpdate_NoValidBlocksFound(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
//DenebForkEpoch: 0,
}
p := protocol.New(settings, MaxRedundancy)
client := mock.API{}
Expand Down
48 changes: 0 additions & 48 deletions relayer/relays/beacon/header/syncer/api/api_deneb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package api
import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/snowfork/go-substrate-rpc-client/v4/types"
beaconjson "github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/json"
"github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/scale"
"github.com/snowfork/snowbridge/relayer/relays/beacon/state"
"github.com/snowfork/snowbridge/relayer/relays/util"
Expand Down Expand Up @@ -55,49 +53,3 @@ func DenebExecutionPayloadToScale(e *state.ExecutionPayloadDeneb) (scale.Executi
}, nil
}

func DenebJsonExecutionPayloadHeaderToScale(e *beaconjson.FullExecutionPayloadHeaderJson) (scale.ExecutionPayloadHeaderDeneb, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused method.

var executionPayloadHeader scale.ExecutionPayloadHeaderDeneb
var baseFeePerGas big.Int
baseFeePerGasU64, err := util.ToUint64(e.BaseFeePerGas)
if err != nil {
return executionPayloadHeader, err
}
blockNumber, err := util.ToUint64(e.BlockNumber)
if err != nil {
return executionPayloadHeader, err
}
baseFeePerGas.SetUint64(baseFeePerGasU64)
gasLimit, err := util.ToUint64(e.GasLimit)
if err != nil {
return executionPayloadHeader, err
}
gasUsed, err := util.ToUint64(e.GasUsed)
if err != nil {
return executionPayloadHeader, err
}
timestamp, err := util.ToUint64(e.Timestamp)
if err != nil {
return executionPayloadHeader, err
}
blobGasUsed, _ := util.ToUint64(e.BlobGasUsed)
excessBlobGas, _ := util.ToUint64(e.ExcessBlobGas)
return scale.ExecutionPayloadHeaderDeneb{
ParentHash: types.NewH256(common.HexToHash(e.ParentHash).Bytes()),
FeeRecipient: types.NewH160(common.HexToAddress(e.FeeRecipient).Bytes()),
StateRoot: types.NewH256(common.HexToHash(e.StateRoot).Bytes()),
ReceiptsRoot: types.NewH256(common.HexToHash(e.ReceiptsRoot).Bytes()),
LogsBloom: common.FromHex(e.LogsBloom),
PrevRandao: types.NewH256(common.HexToHash(e.PrevRandao).Bytes()),
BlockNumber: types.NewU64(blockNumber),
GasLimit: types.NewU64(gasLimit),
GasUsed: types.NewU64(gasUsed),
Timestamp: types.NewU64(timestamp),
ExtraData: common.FromHex(e.ExtraData),
BaseFeePerGas: types.NewU256(baseFeePerGas),
BlockHash: types.NewH256(common.HexToHash(e.BlockHash).Bytes()),
TransactionsRoot: types.NewH256(common.HexToHash(e.TransactionsRoot).Bytes()),
WithdrawalsRoot: types.NewH256(common.HexToHash(e.WithdrawalsRoot).Bytes()),
BlobGasUsed: types.NewU64(blobGasUsed),
ExcessBlobGas: types.NewU64(excessBlobGas),
}, nil
}
126 changes: 126 additions & 0 deletions relayer/relays/beacon/header/syncer/api/api_electra.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package api

import (
"math/big"

"github.com/snowfork/go-substrate-rpc-client/v4/types"
"github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/scale"
"github.com/snowfork/snowbridge/relayer/relays/beacon/state"
"github.com/snowfork/snowbridge/relayer/relays/util"
)

func ElectraExecutionPayloadToScale(e *state.ExecutionPayloadElectra) (scale.ExecutionPayloadHeaderElectra, error) {
var payloadHeader scale.ExecutionPayloadHeaderElectra
transactionsContainer := state.TransactionsRootContainer{}
transactionsContainer.Transactions = e.Transactions

transactionsRoot, err := transactionsContainer.HashTreeRoot()
if err != nil {
return payloadHeader, err
}

withdrawalContainer := state.WithdrawalsRootContainerMainnet{}
withdrawalContainer.Withdrawals = e.Withdrawals
withdrawalRoot, err := withdrawalContainer.HashTreeRoot()
if err != nil {
return payloadHeader, err
}

baseFeePerGas := big.Int{}
// Change BaseFeePerGas back from little-endian to big-endian
baseFeePerGas.SetBytes(util.ChangeByteOrder(e.BaseFeePerGas[:]))

return scale.ExecutionPayloadHeaderElectra{
ParentHash: types.NewH256(e.ParentHash[:]),
FeeRecipient: e.FeeRecipient,
StateRoot: types.NewH256(e.StateRoot[:]),
ReceiptsRoot: types.NewH256(e.ReceiptsRoot[:]),
LogsBloom: e.LogsBloom[:],
PrevRandao: types.NewH256(e.PrevRandao[:]),
BlockNumber: types.NewU64(e.BlockNumber),
GasLimit: types.NewU64(e.GasLimit),
GasUsed: types.NewU64(e.GasUsed),
Timestamp: types.NewU64(e.Timestamp),
ExtraData: e.ExtraData,
BaseFeePerGas: types.NewU256(baseFeePerGas),
BlockHash: types.NewH256(e.BlockHash[:]),
TransactionsRoot: transactionsRoot,
WithdrawalsRoot: withdrawalRoot,
BlobGasUsed: types.NewU64(e.BlobGasUsed),
ExcessBlobGas: types.NewU64(e.ExcessBlobGas),
}, nil
}

func (a AttesterSlashingResponse) ToFastSSZElectra() (*state.AttesterSlashingElectra, error) {
attestation1, err := a.Attestation1.ToFastSSZElectra()
if err != nil {
return nil, err
}

attestation2, err := a.Attestation2.ToFastSSZElectra()
if err != nil {
return nil, err
}

return &state.AttesterSlashingElectra{
Attestation1: attestation1,
Attestation2: attestation2,
}, nil
}

func (i IndexedAttestationResponse) ToFastSSZElectra() (*state.IndexedAttestationElectra, error) {
data, err := i.Data.ToFastSSZ()
if err != nil {
return nil, err
}

attestationIndexes := []uint64{}
for _, index := range i.AttestingIndices {
indexInt, err := util.ToUint64(index)
if err != nil {
return nil, err
}

attestationIndexes = append(attestationIndexes, indexInt)
}

signature, err := util.HexStringToByteArray(i.Signature)
if err != nil {
return nil, err
}

return &state.IndexedAttestationElectra{
AttestationIndices: attestationIndexes,
Data: data,
Signature: signature,
}, nil
}

func (a AttestationResponse) ToFastSSZElectra() (*state.AttestationElectra, error) {
data, err := a.Data.ToFastSSZ()
if err != nil {
return nil, err
}

aggregationBits, err := util.HexStringToByteArray(a.AggregationBits)
if err != nil {
return nil, err
}

signature, err := util.HexStringTo96Bytes(a.Signature)
if err != nil {
return nil, err
}

committeeBits, err := util.HexStringToByteArray(a.CommitteeBits)
if err != nil {
return nil, err
}

return &state.AttestationElectra{
AggregationBits: aggregationBits,
Data: data,
Signature: signature,
CommitteeBits: committeeBits,
}, nil
}
Loading
Loading