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 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -44,7 +44,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
147 changes: 1 addition & 146 deletions relayer/contracts/gateway.go

Large diffs are not rendered by default.

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 @@ -12,10 +12,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 @@ -20,7 +20,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)
client := mock.API{}
Expand Down Expand Up @@ -78,7 +81,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)
client := mock.API{}
Expand Down Expand Up @@ -144,7 +150,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)
client := mock.API{}
Expand Down Expand Up @@ -210,7 +219,7 @@ func TestSyncInterimFinalizedUpdate_BeaconStateNotAvailableInAPIAndStore(t *test
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
//DenebForkEpoch: 0,
}
p := protocol.New(settings)
client := mock.API{}
Expand Down Expand Up @@ -254,7 +263,7 @@ func TestSyncInterimFinalizedUpdate_NoValidBlocksFound(t *testing.T) {
settings := config.SpecSettings{
SlotsInEpoch: 32,
EpochsPerSyncCommitteePeriod: 256,
DenebForkEpoch: 0,
//DenebForkEpoch: 0,
}
p := protocol.New(settings)
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
}
150 changes: 150 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,150 @@
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
}

depositRequestsContainer := state.DepositRequestsContainer{}
depositRequestsContainer.DepositRequests = e.DepositRequests
depositRequestsRoot, err := depositRequestsContainer.HashTreeRoot()
if err != nil {
return payloadHeader, err
}

withdrawalRequestsContainer := state.WithdrawalRequestsContainer{}
withdrawalRequestsContainer.WithdrawalRequests = e.WithdrawalRequests
withdrawalRequestsRoot, err := withdrawalRequestsContainer.HashTreeRoot()
if err != nil {
return payloadHeader, err
}

consolidationRequestsContainer := state.ConsolidationRequestsContainer{}
consolidationRequestsContainer.ConsolidationRequests = e.ConsolidationRequests
consolidationRequestsRoot, err := consolidationRequestsContainer.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),
DepositRequestsRoot: depositRequestsRoot,
WithdrawalRequestsRoot: withdrawalRequestsRoot,
ConsolidationRequestsRoot: consolidationRequestsRoot,
}, 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