diff --git a/CHANGELOG.md b/CHANGELOG.md index 96451816d071..ba92c72f9d7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve - Limit consolidating by validator's effective balance. - Use 16-bit random value for proposer and sync committee selection filter. - Re-organize the content of the `*.proto` files (No functional change). +- Re-organize the content of files to ease the creation of a new fork boilerplate. ### Deprecated diff --git a/api/server/structs/block.go b/api/server/structs/block.go index c53ce6a663ae..6500b2c08046 100644 --- a/api/server/structs/block.go +++ b/api/server/structs/block.go @@ -14,6 +14,10 @@ type SignedMessageJsoner interface { SigString() string } +// ---------------------------------------------------------------------------- +// Phase 0 +// ---------------------------------------------------------------------------- + type SignedBeaconBlock struct { Message *BeaconBlock `json:"message"` Signature string `json:"signature"` @@ -48,6 +52,29 @@ type BeaconBlockBody struct { VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits"` } +type SignedBeaconBlockHeaderContainer struct { + Header *SignedBeaconBlockHeader `json:"header"` + Root string `json:"root"` + Canonical bool `json:"canonical"` +} + +type SignedBeaconBlockHeader struct { + Message *BeaconBlockHeader `json:"message"` + Signature string `json:"signature"` +} + +type BeaconBlockHeader struct { + Slot string `json:"slot"` + ProposerIndex string `json:"proposer_index"` + ParentRoot string `json:"parent_root"` + StateRoot string `json:"state_root"` + BodyRoot string `json:"body_root"` +} + +// ---------------------------------------------------------------------------- +// Altair +// ---------------------------------------------------------------------------- + type SignedBeaconBlockAltair struct { Message *BeaconBlockAltair `json:"message"` Signature string `json:"signature"` @@ -83,6 +110,10 @@ type BeaconBlockBodyAltair struct { SyncAggregate *SyncAggregate `json:"sync_aggregate"` } +// ---------------------------------------------------------------------------- +// Bellatrix +// ---------------------------------------------------------------------------- + type SignedBeaconBlockBellatrix struct { Message *BeaconBlockBellatrix `json:"message"` Signature string `json:"signature"` @@ -155,6 +186,44 @@ type BlindedBeaconBlockBodyBellatrix struct { ExecutionPayloadHeader *ExecutionPayloadHeader `json:"execution_payload_header"` } +type ExecutionPayload struct { + ParentHash string `json:"parent_hash"` + FeeRecipient string `json:"fee_recipient"` + StateRoot string `json:"state_root"` + ReceiptsRoot string `json:"receipts_root"` + LogsBloom string `json:"logs_bloom"` + PrevRandao string `json:"prev_randao"` + BlockNumber string `json:"block_number"` + GasLimit string `json:"gas_limit"` + GasUsed string `json:"gas_used"` + Timestamp string `json:"timestamp"` + ExtraData string `json:"extra_data"` + BaseFeePerGas string `json:"base_fee_per_gas"` + BlockHash string `json:"block_hash"` + Transactions []string `json:"transactions"` +} + +type ExecutionPayloadHeader struct { + ParentHash string `json:"parent_hash"` + FeeRecipient string `json:"fee_recipient"` + StateRoot string `json:"state_root"` + ReceiptsRoot string `json:"receipts_root"` + LogsBloom string `json:"logs_bloom"` + PrevRandao string `json:"prev_randao"` + BlockNumber string `json:"block_number"` + GasLimit string `json:"gas_limit"` + GasUsed string `json:"gas_used"` + Timestamp string `json:"timestamp"` + ExtraData string `json:"extra_data"` + BaseFeePerGas string `json:"base_fee_per_gas"` + BlockHash string `json:"block_hash"` + TransactionsRoot string `json:"transactions_root"` +} + +// ---------------------------------------------------------------------------- +// Capella +// ---------------------------------------------------------------------------- + type SignedBeaconBlockCapella struct { Message *BeaconBlockCapella `json:"message"` Signature string `json:"signature"` @@ -229,6 +298,46 @@ type BlindedBeaconBlockBodyCapella struct { BLSToExecutionChanges []*SignedBLSToExecutionChange `json:"bls_to_execution_changes"` } +type ExecutionPayloadCapella struct { + ParentHash string `json:"parent_hash"` + FeeRecipient string `json:"fee_recipient"` + StateRoot string `json:"state_root"` + ReceiptsRoot string `json:"receipts_root"` + LogsBloom string `json:"logs_bloom"` + PrevRandao string `json:"prev_randao"` + BlockNumber string `json:"block_number"` + GasLimit string `json:"gas_limit"` + GasUsed string `json:"gas_used"` + Timestamp string `json:"timestamp"` + ExtraData string `json:"extra_data"` + BaseFeePerGas string `json:"base_fee_per_gas"` + BlockHash string `json:"block_hash"` + Transactions []string `json:"transactions"` + Withdrawals []*Withdrawal `json:"withdrawals"` +} + +type ExecutionPayloadHeaderCapella struct { + ParentHash string `json:"parent_hash"` + FeeRecipient string `json:"fee_recipient"` + StateRoot string `json:"state_root"` + ReceiptsRoot string `json:"receipts_root"` + LogsBloom string `json:"logs_bloom"` + PrevRandao string `json:"prev_randao"` + BlockNumber string `json:"block_number"` + GasLimit string `json:"gas_limit"` + GasUsed string `json:"gas_used"` + Timestamp string `json:"timestamp"` + ExtraData string `json:"extra_data"` + BaseFeePerGas string `json:"base_fee_per_gas"` + BlockHash string `json:"block_hash"` + TransactionsRoot string `json:"transactions_root"` + WithdrawalsRoot string `json:"withdrawals_root"` +} + +// ---------------------------------------------------------------------------- +// Deneb +// ---------------------------------------------------------------------------- + type SignedBeaconBlockContentsDeneb struct { SignedBlock *SignedBeaconBlockDeneb `json:"signed_block"` KzgProofs []string `json:"kzg_proofs"` @@ -317,6 +426,50 @@ type BlindedBeaconBlockBodyDeneb struct { BlobKzgCommitments []string `json:"blob_kzg_commitments"` } +type ExecutionPayloadDeneb struct { + ParentHash string `json:"parent_hash"` + FeeRecipient string `json:"fee_recipient"` + StateRoot string `json:"state_root"` + ReceiptsRoot string `json:"receipts_root"` + LogsBloom string `json:"logs_bloom"` + PrevRandao string `json:"prev_randao"` + BlockNumber string `json:"block_number"` + GasLimit string `json:"gas_limit"` + GasUsed string `json:"gas_used"` + Timestamp string `json:"timestamp"` + ExtraData string `json:"extra_data"` + BaseFeePerGas string `json:"base_fee_per_gas"` + BlockHash string `json:"block_hash"` + Transactions []string `json:"transactions"` + Withdrawals []*Withdrawal `json:"withdrawals"` + BlobGasUsed string `json:"blob_gas_used"` + ExcessBlobGas string `json:"excess_blob_gas"` +} + +type ExecutionPayloadHeaderDeneb struct { + ParentHash string `json:"parent_hash"` + FeeRecipient string `json:"fee_recipient"` + StateRoot string `json:"state_root"` + ReceiptsRoot string `json:"receipts_root"` + LogsBloom string `json:"logs_bloom"` + PrevRandao string `json:"prev_randao"` + BlockNumber string `json:"block_number"` + GasLimit string `json:"gas_limit"` + GasUsed string `json:"gas_used"` + Timestamp string `json:"timestamp"` + ExtraData string `json:"extra_data"` + BaseFeePerGas string `json:"base_fee_per_gas"` + BlockHash string `json:"block_hash"` + TransactionsRoot string `json:"transactions_root"` + WithdrawalsRoot string `json:"withdrawals_root"` + BlobGasUsed string `json:"blob_gas_used"` + ExcessBlobGas string `json:"excess_blob_gas"` +} + +// ---------------------------------------------------------------------------- +// Electra +// ---------------------------------------------------------------------------- + type SignedBeaconBlockContentsElectra struct { SignedBlock *SignedBeaconBlockElectra `json:"signed_block"` KzgProofs []string `json:"kzg_proofs"` @@ -407,141 +560,13 @@ type BlindedBeaconBlockBodyElectra struct { ExecutionRequests *ExecutionRequests `json:"execution_requests"` } -type SignedBeaconBlockHeaderContainer struct { - Header *SignedBeaconBlockHeader `json:"header"` - Root string `json:"root"` - Canonical bool `json:"canonical"` -} - -type SignedBeaconBlockHeader struct { - Message *BeaconBlockHeader `json:"message"` - Signature string `json:"signature"` -} - -type BeaconBlockHeader struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root"` - StateRoot string `json:"state_root"` - BodyRoot string `json:"body_root"` -} +type ( + ExecutionRequests struct { + Deposits []*DepositRequest `json:"deposits"` + Withdrawals []*WithdrawalRequest `json:"withdrawals"` + Consolidations []*ConsolidationRequest `json:"consolidations"` + } -type ExecutionPayload struct { - ParentHash string `json:"parent_hash"` - FeeRecipient string `json:"fee_recipient"` - StateRoot string `json:"state_root"` - ReceiptsRoot string `json:"receipts_root"` - LogsBloom string `json:"logs_bloom"` - PrevRandao string `json:"prev_randao"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - Timestamp string `json:"timestamp"` - ExtraData string `json:"extra_data"` - BaseFeePerGas string `json:"base_fee_per_gas"` - BlockHash string `json:"block_hash"` - Transactions []string `json:"transactions"` -} - -type ExecutionPayloadHeader struct { - ParentHash string `json:"parent_hash"` - FeeRecipient string `json:"fee_recipient"` - StateRoot string `json:"state_root"` - ReceiptsRoot string `json:"receipts_root"` - LogsBloom string `json:"logs_bloom"` - PrevRandao string `json:"prev_randao"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - Timestamp string `json:"timestamp"` - ExtraData string `json:"extra_data"` - BaseFeePerGas string `json:"base_fee_per_gas"` - BlockHash string `json:"block_hash"` - TransactionsRoot string `json:"transactions_root"` -} - -type ExecutionPayloadCapella struct { - ParentHash string `json:"parent_hash"` - FeeRecipient string `json:"fee_recipient"` - StateRoot string `json:"state_root"` - ReceiptsRoot string `json:"receipts_root"` - LogsBloom string `json:"logs_bloom"` - PrevRandao string `json:"prev_randao"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - Timestamp string `json:"timestamp"` - ExtraData string `json:"extra_data"` - BaseFeePerGas string `json:"base_fee_per_gas"` - BlockHash string `json:"block_hash"` - Transactions []string `json:"transactions"` - Withdrawals []*Withdrawal `json:"withdrawals"` -} - -type ExecutionPayloadHeaderCapella struct { - ParentHash string `json:"parent_hash"` - FeeRecipient string `json:"fee_recipient"` - StateRoot string `json:"state_root"` - ReceiptsRoot string `json:"receipts_root"` - LogsBloom string `json:"logs_bloom"` - PrevRandao string `json:"prev_randao"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - Timestamp string `json:"timestamp"` - ExtraData string `json:"extra_data"` - BaseFeePerGas string `json:"base_fee_per_gas"` - BlockHash string `json:"block_hash"` - TransactionsRoot string `json:"transactions_root"` - WithdrawalsRoot string `json:"withdrawals_root"` -} - -type ExecutionPayloadDeneb struct { - ParentHash string `json:"parent_hash"` - FeeRecipient string `json:"fee_recipient"` - StateRoot string `json:"state_root"` - ReceiptsRoot string `json:"receipts_root"` - LogsBloom string `json:"logs_bloom"` - PrevRandao string `json:"prev_randao"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - Timestamp string `json:"timestamp"` - ExtraData string `json:"extra_data"` - BaseFeePerGas string `json:"base_fee_per_gas"` - BlockHash string `json:"block_hash"` - Transactions []string `json:"transactions"` - Withdrawals []*Withdrawal `json:"withdrawals"` - BlobGasUsed string `json:"blob_gas_used"` - ExcessBlobGas string `json:"excess_blob_gas"` -} - -type ExecutionPayloadElectra = ExecutionPayloadDeneb - -type ExecutionPayloadHeaderDeneb struct { - ParentHash string `json:"parent_hash"` - FeeRecipient string `json:"fee_recipient"` - StateRoot string `json:"state_root"` - ReceiptsRoot string `json:"receipts_root"` - LogsBloom string `json:"logs_bloom"` - PrevRandao string `json:"prev_randao"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - Timestamp string `json:"timestamp"` - ExtraData string `json:"extra_data"` - BaseFeePerGas string `json:"base_fee_per_gas"` - BlockHash string `json:"block_hash"` - TransactionsRoot string `json:"transactions_root"` - WithdrawalsRoot string `json:"withdrawals_root"` - BlobGasUsed string `json:"blob_gas_used"` - ExcessBlobGas string `json:"excess_blob_gas"` -} - -type ExecutionPayloadHeaderElectra = ExecutionPayloadHeaderDeneb - -type ExecutionRequests struct { - Deposits []*DepositRequest `json:"deposits"` - Withdrawals []*WithdrawalRequest `json:"withdrawals"` - Consolidations []*ConsolidationRequest `json:"consolidations"` -} + ExecutionPayloadElectra = ExecutionPayloadDeneb + ExecutionPayloadHeaderElectra = ExecutionPayloadHeaderDeneb +) diff --git a/api/server/structs/conversions_block.go b/api/server/structs/conversions_block.go index de61ed3bda9a..0d19c06fe5cb 100644 --- a/api/server/structs/conversions_block.go +++ b/api/server/structs/conversions_block.go @@ -19,6 +19,10 @@ import ( var ErrUnsupportedConversion = errors.New("Could not determine api struct type to use for value") +// ---------------------------------------------------------------------------- +// Phase 0 +// ---------------------------------------------------------------------------- + func (h *SignedBeaconBlockHeader) ToConsensus() (*eth.SignedBeaconBlockHeader, error) { if h == nil { return nil, errNilValue @@ -205,6 +209,129 @@ func (b *BeaconBlock) ToConsensus() (*eth.BeaconBlock, error) { }, nil } +func BeaconBlockHeaderFromConsensus(h *eth.BeaconBlockHeader) *BeaconBlockHeader { + return &BeaconBlockHeader{ + Slot: fmt.Sprintf("%d", h.Slot), + ProposerIndex: fmt.Sprintf("%d", h.ProposerIndex), + ParentRoot: hexutil.Encode(h.ParentRoot), + StateRoot: hexutil.Encode(h.StateRoot), + BodyRoot: hexutil.Encode(h.BodyRoot), + } +} + +func BeaconBlockFromConsensus(b *eth.BeaconBlock) *BeaconBlock { + return &BeaconBlock{ + Slot: fmt.Sprintf("%d", b.Slot), + ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), + ParentRoot: hexutil.Encode(b.ParentRoot), + StateRoot: hexutil.Encode(b.StateRoot), + Body: &BeaconBlockBody{ + RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), + Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), + Graffiti: hexutil.Encode(b.Body.Graffiti), + ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), + AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), + Attestations: AttsFromConsensus(b.Body.Attestations), + Deposits: DepositsFromConsensus(b.Body.Deposits), + VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), + }, + } +} + +func SignedBeaconBlockMessageJsoner(block interfaces.ReadOnlySignedBeaconBlock) (SignedMessageJsoner, error) { + pb, err := block.Proto() + if err != nil { + return nil, err + } + switch pbStruct := pb.(type) { + case *eth.SignedBeaconBlock: + return SignedBeaconBlockPhase0FromConsensus(pbStruct), nil + case *eth.SignedBeaconBlockAltair: + return SignedBeaconBlockAltairFromConsensus(pbStruct), nil + case *eth.SignedBlindedBeaconBlockBellatrix: + return SignedBlindedBeaconBlockBellatrixFromConsensus(pbStruct) + case *eth.SignedBeaconBlockBellatrix: + return SignedBeaconBlockBellatrixFromConsensus(pbStruct) + case *eth.SignedBlindedBeaconBlockCapella: + return SignedBlindedBeaconBlockCapellaFromConsensus(pbStruct) + case *eth.SignedBeaconBlockCapella: + return SignedBeaconBlockCapellaFromConsensus(pbStruct) + case *eth.SignedBlindedBeaconBlockDeneb: + return SignedBlindedBeaconBlockDenebFromConsensus(pbStruct) + case *eth.SignedBeaconBlockDeneb: + return SignedBeaconBlockDenebFromConsensus(pbStruct) + case *eth.SignedBlindedBeaconBlockElectra: + return SignedBlindedBeaconBlockElectraFromConsensus(pbStruct) + case *eth.SignedBeaconBlockElectra: + return SignedBeaconBlockElectraFromConsensus(pbStruct) + default: + return nil, ErrUnsupportedConversion + } +} + +func SignedBeaconBlockPhase0FromConsensus(b *eth.SignedBeaconBlock) *SignedBeaconBlock { + return &SignedBeaconBlock{ + Message: BeaconBlockFromConsensus(b.Block), + Signature: hexutil.Encode(b.Signature), + } +} + +func ExecutionPayloadFromConsensus(payload *enginev1.ExecutionPayload) (*ExecutionPayload, error) { + baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) + if err != nil { + return nil, err + } + transactions := make([]string, len(payload.Transactions)) + for i, tx := range payload.Transactions { + transactions[i] = hexutil.Encode(tx) + } + + return &ExecutionPayload{ + ParentHash: hexutil.Encode(payload.ParentHash), + FeeRecipient: hexutil.Encode(payload.FeeRecipient), + StateRoot: hexutil.Encode(payload.StateRoot), + ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), + LogsBloom: hexutil.Encode(payload.LogsBloom), + PrevRandao: hexutil.Encode(payload.PrevRandao), + BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), + GasLimit: fmt.Sprintf("%d", payload.GasLimit), + GasUsed: fmt.Sprintf("%d", payload.GasUsed), + Timestamp: fmt.Sprintf("%d", payload.Timestamp), + ExtraData: hexutil.Encode(payload.ExtraData), + BaseFeePerGas: baseFeePerGas, + BlockHash: hexutil.Encode(payload.BlockHash), + Transactions: transactions, + }, nil +} + +func ExecutionPayloadHeaderFromConsensus(payload *enginev1.ExecutionPayloadHeader) (*ExecutionPayloadHeader, error) { + baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) + if err != nil { + return nil, err + } + + return &ExecutionPayloadHeader{ + ParentHash: hexutil.Encode(payload.ParentHash), + FeeRecipient: hexutil.Encode(payload.FeeRecipient), + StateRoot: hexutil.Encode(payload.StateRoot), + ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), + LogsBloom: hexutil.Encode(payload.LogsBloom), + PrevRandao: hexutil.Encode(payload.PrevRandao), + BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), + GasLimit: fmt.Sprintf("%d", payload.GasLimit), + GasUsed: fmt.Sprintf("%d", payload.GasUsed), + Timestamp: fmt.Sprintf("%d", payload.Timestamp), + ExtraData: hexutil.Encode(payload.ExtraData), + BaseFeePerGas: baseFeePerGas, + BlockHash: hexutil.Encode(payload.BlockHash), + TransactionsRoot: hexutil.Encode(payload.TransactionsRoot), + }, nil +} + +// ---------------------------------------------------------------------------- +// Altair +// ---------------------------------------------------------------------------- + func (b *SignedBeaconBlockAltair) ToGeneric() (*eth.GenericSignedBeaconBlock, error) { if b == nil { return nil, errNilValue @@ -337,6 +464,40 @@ func (b *BeaconBlockAltair) ToConsensus() (*eth.BeaconBlockAltair, error) { }, nil } +func BeaconBlockAltairFromConsensus(b *eth.BeaconBlockAltair) *BeaconBlockAltair { + return &BeaconBlockAltair{ + Slot: fmt.Sprintf("%d", b.Slot), + ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), + ParentRoot: hexutil.Encode(b.ParentRoot), + StateRoot: hexutil.Encode(b.StateRoot), + Body: &BeaconBlockBodyAltair{ + RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), + Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), + Graffiti: hexutil.Encode(b.Body.Graffiti), + ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), + AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), + Attestations: AttsFromConsensus(b.Body.Attestations), + Deposits: DepositsFromConsensus(b.Body.Deposits), + VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), + SyncAggregate: &SyncAggregate{ + SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), + SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), + }, + }, + } +} + +func SignedBeaconBlockAltairFromConsensus(b *eth.SignedBeaconBlockAltair) *SignedBeaconBlockAltair { + return &SignedBeaconBlockAltair{ + Message: BeaconBlockAltairFromConsensus(b.Block), + Signature: hexutil.Encode(b.Signature), + } +} + +// ---------------------------------------------------------------------------- +// Bellatrix +// ---------------------------------------------------------------------------- + func (b *SignedBeaconBlockBellatrix) ToGeneric() (*eth.GenericSignedBeaconBlock, error) { if b == nil { return nil, errNilValue @@ -759,6 +920,90 @@ func (b *BlindedBeaconBlockBellatrix) ToConsensus() (*eth.BlindedBeaconBlockBell }, nil } +func BlindedBeaconBlockBellatrixFromConsensus(b *eth.BlindedBeaconBlockBellatrix) (*BlindedBeaconBlockBellatrix, error) { + payload, err := ExecutionPayloadHeaderFromConsensus(b.Body.ExecutionPayloadHeader) + if err != nil { + return nil, err + } + + return &BlindedBeaconBlockBellatrix{ + Slot: fmt.Sprintf("%d", b.Slot), + ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), + ParentRoot: hexutil.Encode(b.ParentRoot), + StateRoot: hexutil.Encode(b.StateRoot), + Body: &BlindedBeaconBlockBodyBellatrix{ + RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), + Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), + Graffiti: hexutil.Encode(b.Body.Graffiti), + ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), + AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), + Attestations: AttsFromConsensus(b.Body.Attestations), + Deposits: DepositsFromConsensus(b.Body.Deposits), + VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), + SyncAggregate: &SyncAggregate{ + SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), + SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), + }, + ExecutionPayloadHeader: payload, + }, + }, nil +} + +func SignedBlindedBeaconBlockBellatrixFromConsensus(b *eth.SignedBlindedBeaconBlockBellatrix) (*SignedBlindedBeaconBlockBellatrix, error) { + blindedBlock, err := BlindedBeaconBlockBellatrixFromConsensus(b.Block) + if err != nil { + return nil, err + } + return &SignedBlindedBeaconBlockBellatrix{ + Message: blindedBlock, + Signature: hexutil.Encode(b.Signature), + }, nil +} + +func BeaconBlockBellatrixFromConsensus(b *eth.BeaconBlockBellatrix) (*BeaconBlockBellatrix, error) { + payload, err := ExecutionPayloadFromConsensus(b.Body.ExecutionPayload) + if err != nil { + return nil, err + } + + return &BeaconBlockBellatrix{ + Slot: fmt.Sprintf("%d", b.Slot), + ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), + ParentRoot: hexutil.Encode(b.ParentRoot), + StateRoot: hexutil.Encode(b.StateRoot), + Body: &BeaconBlockBodyBellatrix{ + RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), + Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), + Graffiti: hexutil.Encode(b.Body.Graffiti), + ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), + AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), + Attestations: AttsFromConsensus(b.Body.Attestations), + Deposits: DepositsFromConsensus(b.Body.Deposits), + VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), + SyncAggregate: &SyncAggregate{ + SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), + SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), + }, + ExecutionPayload: payload, + }, + }, nil +} + +func SignedBeaconBlockBellatrixFromConsensus(b *eth.SignedBeaconBlockBellatrix) (*SignedBeaconBlockBellatrix, error) { + block, err := BeaconBlockBellatrixFromConsensus(b.Block) + if err != nil { + return nil, err + } + return &SignedBeaconBlockBellatrix{ + Message: block, + Signature: hexutil.Encode(b.Signature), + }, nil +} + +// ---------------------------------------------------------------------------- +// Capella +// ---------------------------------------------------------------------------- + func (b *SignedBeaconBlockCapella) ToGeneric() (*eth.GenericSignedBeaconBlock, error) { if b == nil { return nil, errNilValue @@ -1227,28 +1472,168 @@ func (b *BlindedBeaconBlockCapella) ToConsensus() (*eth.BlindedBeaconBlockCapell }, nil } -func (b *SignedBeaconBlockContentsDeneb) ToGeneric() (*eth.GenericSignedBeaconBlock, error) { - if b == nil { - return nil, errNilValue - } - - signedDenebBlock, err := b.SignedBlock.ToConsensus() +func BlindedBeaconBlockCapellaFromConsensus(b *eth.BlindedBeaconBlockCapella) (*BlindedBeaconBlockCapella, error) { + payload, err := ExecutionPayloadHeaderCapellaFromConsensus(b.Body.ExecutionPayloadHeader) if err != nil { - return nil, server.NewDecodeError(err, "SignedBlock") - } - proofs := make([][]byte, len(b.KzgProofs)) - for i, proof := range b.KzgProofs { - proofs[i], err = bytesutil.DecodeHexWithLength(proof, fieldparams.BLSPubkeyLength) - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("KzgProofs[%d]", i)) - } + return nil, err } - blbs := make([][]byte, len(b.Blobs)) - for i, blob := range b.Blobs { - blbs[i], err = bytesutil.DecodeHexWithLength(blob, fieldparams.BlobLength) - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("Blobs[%d]", i)) - } + + return &BlindedBeaconBlockCapella{ + Slot: fmt.Sprintf("%d", b.Slot), + ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), + ParentRoot: hexutil.Encode(b.ParentRoot), + StateRoot: hexutil.Encode(b.StateRoot), + Body: &BlindedBeaconBlockBodyCapella{ + RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), + Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), + Graffiti: hexutil.Encode(b.Body.Graffiti), + ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), + AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), + Attestations: AttsFromConsensus(b.Body.Attestations), + Deposits: DepositsFromConsensus(b.Body.Deposits), + VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), + SyncAggregate: &SyncAggregate{ + SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), + SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), + }, + ExecutionPayloadHeader: payload, + BLSToExecutionChanges: SignedBLSChangesFromConsensus(b.Body.BlsToExecutionChanges), + }, + }, nil +} + +func SignedBlindedBeaconBlockCapellaFromConsensus(b *eth.SignedBlindedBeaconBlockCapella) (*SignedBlindedBeaconBlockCapella, error) { + blindedBlock, err := BlindedBeaconBlockCapellaFromConsensus(b.Block) + if err != nil { + return nil, err + } + return &SignedBlindedBeaconBlockCapella{ + Message: blindedBlock, + Signature: hexutil.Encode(b.Signature), + }, nil +} + +func BeaconBlockCapellaFromConsensus(b *eth.BeaconBlockCapella) (*BeaconBlockCapella, error) { + payload, err := ExecutionPayloadCapellaFromConsensus(b.Body.ExecutionPayload) + if err != nil { + return nil, err + } + + return &BeaconBlockCapella{ + Slot: fmt.Sprintf("%d", b.Slot), + ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), + ParentRoot: hexutil.Encode(b.ParentRoot), + StateRoot: hexutil.Encode(b.StateRoot), + Body: &BeaconBlockBodyCapella{ + RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), + Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), + Graffiti: hexutil.Encode(b.Body.Graffiti), + ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), + AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), + Attestations: AttsFromConsensus(b.Body.Attestations), + Deposits: DepositsFromConsensus(b.Body.Deposits), + VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), + SyncAggregate: &SyncAggregate{ + SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), + SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), + }, + ExecutionPayload: payload, + BLSToExecutionChanges: SignedBLSChangesFromConsensus(b.Body.BlsToExecutionChanges), + }, + }, nil +} + +func SignedBeaconBlockCapellaFromConsensus(b *eth.SignedBeaconBlockCapella) (*SignedBeaconBlockCapella, error) { + block, err := BeaconBlockCapellaFromConsensus(b.Block) + if err != nil { + return nil, err + } + return &SignedBeaconBlockCapella{ + Message: block, + Signature: hexutil.Encode(b.Signature), + }, nil +} + +func ExecutionPayloadCapellaFromConsensus(payload *enginev1.ExecutionPayloadCapella) (*ExecutionPayloadCapella, error) { + baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) + if err != nil { + return nil, err + } + transactions := make([]string, len(payload.Transactions)) + for i, tx := range payload.Transactions { + transactions[i] = hexutil.Encode(tx) + } + + return &ExecutionPayloadCapella{ + ParentHash: hexutil.Encode(payload.ParentHash), + FeeRecipient: hexutil.Encode(payload.FeeRecipient), + StateRoot: hexutil.Encode(payload.StateRoot), + ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), + LogsBloom: hexutil.Encode(payload.LogsBloom), + PrevRandao: hexutil.Encode(payload.PrevRandao), + BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), + GasLimit: fmt.Sprintf("%d", payload.GasLimit), + GasUsed: fmt.Sprintf("%d", payload.GasUsed), + Timestamp: fmt.Sprintf("%d", payload.Timestamp), + ExtraData: hexutil.Encode(payload.ExtraData), + BaseFeePerGas: baseFeePerGas, + BlockHash: hexutil.Encode(payload.BlockHash), + Transactions: transactions, + Withdrawals: WithdrawalsFromConsensus(payload.Withdrawals), + }, nil +} + +func ExecutionPayloadHeaderCapellaFromConsensus(payload *enginev1.ExecutionPayloadHeaderCapella) (*ExecutionPayloadHeaderCapella, error) { + baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) + if err != nil { + return nil, err + } + + return &ExecutionPayloadHeaderCapella{ + ParentHash: hexutil.Encode(payload.ParentHash), + FeeRecipient: hexutil.Encode(payload.FeeRecipient), + StateRoot: hexutil.Encode(payload.StateRoot), + ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), + LogsBloom: hexutil.Encode(payload.LogsBloom), + PrevRandao: hexutil.Encode(payload.PrevRandao), + BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), + GasLimit: fmt.Sprintf("%d", payload.GasLimit), + GasUsed: fmt.Sprintf("%d", payload.GasUsed), + Timestamp: fmt.Sprintf("%d", payload.Timestamp), + ExtraData: hexutil.Encode(payload.ExtraData), + BaseFeePerGas: baseFeePerGas, + BlockHash: hexutil.Encode(payload.BlockHash), + TransactionsRoot: hexutil.Encode(payload.TransactionsRoot), + WithdrawalsRoot: hexutil.Encode(payload.WithdrawalsRoot), + }, nil +} + +// ---------------------------------------------------------------------------- +// Deneb +// ---------------------------------------------------------------------------- + +func (b *SignedBeaconBlockContentsDeneb) ToGeneric() (*eth.GenericSignedBeaconBlock, error) { + if b == nil { + return nil, errNilValue + } + + signedDenebBlock, err := b.SignedBlock.ToConsensus() + if err != nil { + return nil, server.NewDecodeError(err, "SignedBlock") + } + proofs := make([][]byte, len(b.KzgProofs)) + for i, proof := range b.KzgProofs { + proofs[i], err = bytesutil.DecodeHexWithLength(proof, fieldparams.BLSPubkeyLength) + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("KzgProofs[%d]", i)) + } + } + blbs := make([][]byte, len(b.Blobs)) + for i, blob := range b.Blobs { + blbs[i], err = bytesutil.DecodeHexWithLength(blob, fieldparams.BlobLength) + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("Blobs[%d]", i)) + } } blk := ð.SignedBeaconBlockContentsDeneb{ Block: signedDenebBlock, @@ -1833,184 +2218,403 @@ func (b *BlindedBeaconBlockDeneb) ToGeneric() (*eth.GenericBeaconBlock, error) { return ð.GenericBeaconBlock{Block: ð.GenericBeaconBlock_BlindedDeneb{BlindedDeneb: blindedBlock}, IsBlinded: true}, nil } -func (b *SignedBeaconBlockContentsElectra) ToGeneric() (*eth.GenericSignedBeaconBlock, error) { - if b == nil { - return nil, errNilValue - } - - signedElectraBlock, err := b.SignedBlock.ToConsensus() +func BeaconBlockContentsDenebFromConsensus(b *eth.BeaconBlockContentsDeneb) (*BeaconBlockContentsDeneb, error) { + block, err := BeaconBlockDenebFromConsensus(b.Block) if err != nil { - return nil, server.NewDecodeError(err, "SignedBlock") + return nil, err } - proofs := make([][]byte, len(b.KzgProofs)) + proofs := make([]string, len(b.KzgProofs)) for i, proof := range b.KzgProofs { - proofs[i], err = bytesutil.DecodeHexWithLength(proof, fieldparams.BLSPubkeyLength) - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("KzgProofs[%d]", i)) - } + proofs[i] = hexutil.Encode(proof) } - blbs := make([][]byte, len(b.Blobs)) + blbs := make([]string, len(b.Blobs)) for i, blob := range b.Blobs { - blbs[i], err = bytesutil.DecodeHexWithLength(blob, fieldparams.BlobLength) - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("Blobs[%d]", i)) - } + blbs[i] = hexutil.Encode(blob) } - blk := ð.SignedBeaconBlockContentsElectra{ - Block: signedElectraBlock, + return &BeaconBlockContentsDeneb{ + Block: block, KzgProofs: proofs, Blobs: blbs, - } - return ð.GenericSignedBeaconBlock{Block: ð.GenericSignedBeaconBlock_Electra{Electra: blk}}, nil -} - -func (b *SignedBeaconBlockContentsElectra) ToUnsigned() *BeaconBlockContentsElectra { - return &BeaconBlockContentsElectra{ - Block: b.SignedBlock.Message, - KzgProofs: b.KzgProofs, - Blobs: b.Blobs, - } + }, nil } -func (b *BeaconBlockContentsElectra) ToGeneric() (*eth.GenericBeaconBlock, error) { - block, err := b.ToConsensus() +func SignedBeaconBlockContentsDenebFromConsensus(b *eth.SignedBeaconBlockContentsDeneb) (*SignedBeaconBlockContentsDeneb, error) { + block, err := SignedBeaconBlockDenebFromConsensus(b.Block) if err != nil { return nil, err } - return ð.GenericBeaconBlock{Block: ð.GenericBeaconBlock_Electra{Electra: block}}, nil -} - -func (b *BeaconBlockContentsElectra) ToConsensus() (*eth.BeaconBlockContentsElectra, error) { - if b == nil { - return nil, errNilValue - } - - electraBlock, err := b.Block.ToConsensus() - if err != nil { - return nil, server.NewDecodeError(err, "Block") - } - proofs := make([][]byte, len(b.KzgProofs)) + proofs := make([]string, len(b.KzgProofs)) for i, proof := range b.KzgProofs { - proofs[i], err = bytesutil.DecodeHexWithLength(proof, fieldparams.BLSPubkeyLength) - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("KzgProofs[%d]", i)) - } + proofs[i] = hexutil.Encode(proof) } - blbs := make([][]byte, len(b.Blobs)) + + blbs := make([]string, len(b.Blobs)) for i, blob := range b.Blobs { - blbs[i], err = bytesutil.DecodeHexWithLength(blob, fieldparams.BlobLength) - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("Blobs[%d]", i)) - } + blbs[i] = hexutil.Encode(blob) } - return ð.BeaconBlockContentsElectra{ - Block: electraBlock, - KzgProofs: proofs, - Blobs: blbs, + + return &SignedBeaconBlockContentsDeneb{ + SignedBlock: block, + KzgProofs: proofs, + Blobs: blbs, }, nil } -func (b *BeaconBlockElectra) ToConsensus() (*eth.BeaconBlockElectra, error) { - if b == nil { - return nil, errNilValue - } - if b.Body == nil { - return nil, server.NewDecodeError(errNilValue, "Body") - } - if b.Body.Eth1Data == nil { - return nil, server.NewDecodeError(errNilValue, "Body.Eth1Data") - } - if b.Body.SyncAggregate == nil { - return nil, server.NewDecodeError(errNilValue, "Body.SyncAggregate") +func BlindedBeaconBlockDenebFromConsensus(b *eth.BlindedBeaconBlockDeneb) (*BlindedBeaconBlockDeneb, error) { + blobKzgCommitments := make([]string, len(b.Body.BlobKzgCommitments)) + for i := range b.Body.BlobKzgCommitments { + blobKzgCommitments[i] = hexutil.Encode(b.Body.BlobKzgCommitments[i]) } - if b.Body.ExecutionPayload == nil { - return nil, server.NewDecodeError(errNilValue, "Body.ExecutionPayload") + payload, err := ExecutionPayloadHeaderDenebFromConsensus(b.Body.ExecutionPayloadHeader) + if err != nil { + return nil, err } - slot, err := strconv.ParseUint(b.Slot, 10, 64) - if err != nil { - return nil, server.NewDecodeError(err, "Slot") - } - proposerIndex, err := strconv.ParseUint(b.ProposerIndex, 10, 64) - if err != nil { - return nil, server.NewDecodeError(err, "ProposerIndex") - } - parentRoot, err := bytesutil.DecodeHexWithLength(b.ParentRoot, fieldparams.RootLength) + return &BlindedBeaconBlockDeneb{ + Slot: fmt.Sprintf("%d", b.Slot), + ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), + ParentRoot: hexutil.Encode(b.ParentRoot), + StateRoot: hexutil.Encode(b.StateRoot), + Body: &BlindedBeaconBlockBodyDeneb{ + RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), + Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), + Graffiti: hexutil.Encode(b.Body.Graffiti), + ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), + AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), + Attestations: AttsFromConsensus(b.Body.Attestations), + Deposits: DepositsFromConsensus(b.Body.Deposits), + VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), + SyncAggregate: &SyncAggregate{ + SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), + SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), + }, + ExecutionPayloadHeader: payload, + BLSToExecutionChanges: SignedBLSChangesFromConsensus(b.Body.BlsToExecutionChanges), + BlobKzgCommitments: blobKzgCommitments, + }, + }, nil +} + +func SignedBlindedBeaconBlockDenebFromConsensus(b *eth.SignedBlindedBeaconBlockDeneb) (*SignedBlindedBeaconBlockDeneb, error) { + block, err := BlindedBeaconBlockDenebFromConsensus(b.Message) if err != nil { - return nil, server.NewDecodeError(err, "ParentRoot") + return nil, err } - stateRoot, err := bytesutil.DecodeHexWithLength(b.StateRoot, fieldparams.RootLength) + return &SignedBlindedBeaconBlockDeneb{ + Message: block, + Signature: hexutil.Encode(b.Signature), + }, nil +} + +func BeaconBlockDenebFromConsensus(b *eth.BeaconBlockDeneb) (*BeaconBlockDeneb, error) { + baseFeePerGas, err := sszBytesToUint256String(b.Body.ExecutionPayload.BaseFeePerGas) if err != nil { - return nil, server.NewDecodeError(err, "StateRoot") + return nil, err } - randaoReveal, err := bytesutil.DecodeHexWithLength(b.Body.RandaoReveal, fieldparams.BLSSignatureLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.RandaoReveal") + transactions := make([]string, len(b.Body.ExecutionPayload.Transactions)) + for i, tx := range b.Body.ExecutionPayload.Transactions { + transactions[i] = hexutil.Encode(tx) } - depositRoot, err := bytesutil.DecodeHexWithLength(b.Body.Eth1Data.DepositRoot, fieldparams.RootLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.Eth1Data.DepositRoot") + blobKzgCommitments := make([]string, len(b.Body.BlobKzgCommitments)) + for i := range b.Body.BlobKzgCommitments { + blobKzgCommitments[i] = hexutil.Encode(b.Body.BlobKzgCommitments[i]) } - depositCount, err := strconv.ParseUint(b.Body.Eth1Data.DepositCount, 10, 64) + + return &BeaconBlockDeneb{ + Slot: fmt.Sprintf("%d", b.Slot), + ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), + ParentRoot: hexutil.Encode(b.ParentRoot), + StateRoot: hexutil.Encode(b.StateRoot), + Body: &BeaconBlockBodyDeneb{ + RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), + Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), + Graffiti: hexutil.Encode(b.Body.Graffiti), + ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), + AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), + Attestations: AttsFromConsensus(b.Body.Attestations), + Deposits: DepositsFromConsensus(b.Body.Deposits), + VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), + SyncAggregate: &SyncAggregate{ + SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), + SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), + }, + ExecutionPayload: &ExecutionPayloadDeneb{ + ParentHash: hexutil.Encode(b.Body.ExecutionPayload.ParentHash), + FeeRecipient: hexutil.Encode(b.Body.ExecutionPayload.FeeRecipient), + StateRoot: hexutil.Encode(b.Body.ExecutionPayload.StateRoot), + ReceiptsRoot: hexutil.Encode(b.Body.ExecutionPayload.ReceiptsRoot), + LogsBloom: hexutil.Encode(b.Body.ExecutionPayload.LogsBloom), + PrevRandao: hexutil.Encode(b.Body.ExecutionPayload.PrevRandao), + BlockNumber: fmt.Sprintf("%d", b.Body.ExecutionPayload.BlockNumber), + GasLimit: fmt.Sprintf("%d", b.Body.ExecutionPayload.GasLimit), + GasUsed: fmt.Sprintf("%d", b.Body.ExecutionPayload.GasUsed), + Timestamp: fmt.Sprintf("%d", b.Body.ExecutionPayload.Timestamp), + ExtraData: hexutil.Encode(b.Body.ExecutionPayload.ExtraData), + BaseFeePerGas: baseFeePerGas, + BlockHash: hexutil.Encode(b.Body.ExecutionPayload.BlockHash), + Transactions: transactions, + Withdrawals: WithdrawalsFromConsensus(b.Body.ExecutionPayload.Withdrawals), + BlobGasUsed: fmt.Sprintf("%d", b.Body.ExecutionPayload.BlobGasUsed), + ExcessBlobGas: fmt.Sprintf("%d", b.Body.ExecutionPayload.ExcessBlobGas), + }, + BLSToExecutionChanges: SignedBLSChangesFromConsensus(b.Body.BlsToExecutionChanges), + BlobKzgCommitments: blobKzgCommitments, + }, + }, nil +} + +func SignedBeaconBlockDenebFromConsensus(b *eth.SignedBeaconBlockDeneb) (*SignedBeaconBlockDeneb, error) { + block, err := BeaconBlockDenebFromConsensus(b.Block) if err != nil { - return nil, server.NewDecodeError(err, "Body.Eth1Data.DepositCount") + return nil, err } - blockHash, err := bytesutil.DecodeHexWithLength(b.Body.Eth1Data.BlockHash, common.HashLength) + return &SignedBeaconBlockDeneb{ + Message: block, + Signature: hexutil.Encode(b.Signature), + }, nil +} + +func ExecutionPayloadDenebFromConsensus(payload *enginev1.ExecutionPayloadDeneb) (*ExecutionPayloadDeneb, error) { + baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) if err != nil { - return nil, server.NewDecodeError(err, "Body.Eth1Data.BlockHash") + return nil, err } - graffiti, err := bytesutil.DecodeHexWithLength(b.Body.Graffiti, fieldparams.RootLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.Graffiti") + transactions := make([]string, len(payload.Transactions)) + for i, tx := range payload.Transactions { + transactions[i] = hexutil.Encode(tx) } - proposerSlashings, err := ProposerSlashingsToConsensus(b.Body.ProposerSlashings) + + return &ExecutionPayloadDeneb{ + ParentHash: hexutil.Encode(payload.ParentHash), + FeeRecipient: hexutil.Encode(payload.FeeRecipient), + StateRoot: hexutil.Encode(payload.StateRoot), + ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), + LogsBloom: hexutil.Encode(payload.LogsBloom), + PrevRandao: hexutil.Encode(payload.PrevRandao), + BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), + GasLimit: fmt.Sprintf("%d", payload.GasLimit), + GasUsed: fmt.Sprintf("%d", payload.GasUsed), + Timestamp: fmt.Sprintf("%d", payload.Timestamp), + ExtraData: hexutil.Encode(payload.ExtraData), + BaseFeePerGas: baseFeePerGas, + BlockHash: hexutil.Encode(payload.BlockHash), + Transactions: transactions, + Withdrawals: WithdrawalsFromConsensus(payload.Withdrawals), + BlobGasUsed: fmt.Sprintf("%d", payload.BlobGasUsed), + ExcessBlobGas: fmt.Sprintf("%d", payload.ExcessBlobGas), + }, nil +} + +func ExecutionPayloadHeaderDenebFromConsensus(payload *enginev1.ExecutionPayloadHeaderDeneb) (*ExecutionPayloadHeaderDeneb, error) { + baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) if err != nil { - return nil, server.NewDecodeError(err, "Body.ProposerSlashings") + return nil, err } - attesterSlashings, err := AttesterSlashingsElectraToConsensus(b.Body.AttesterSlashings) - if err != nil { - return nil, server.NewDecodeError(err, "Body.AttesterSlashings") + + return &ExecutionPayloadHeaderDeneb{ + ParentHash: hexutil.Encode(payload.ParentHash), + FeeRecipient: hexutil.Encode(payload.FeeRecipient), + StateRoot: hexutil.Encode(payload.StateRoot), + ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), + LogsBloom: hexutil.Encode(payload.LogsBloom), + PrevRandao: hexutil.Encode(payload.PrevRandao), + BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), + GasLimit: fmt.Sprintf("%d", payload.GasLimit), + GasUsed: fmt.Sprintf("%d", payload.GasUsed), + Timestamp: fmt.Sprintf("%d", payload.Timestamp), + ExtraData: hexutil.Encode(payload.ExtraData), + BaseFeePerGas: baseFeePerGas, + BlockHash: hexutil.Encode(payload.BlockHash), + TransactionsRoot: hexutil.Encode(payload.TransactionsRoot), + WithdrawalsRoot: hexutil.Encode(payload.WithdrawalsRoot), + BlobGasUsed: fmt.Sprintf("%d", payload.BlobGasUsed), + ExcessBlobGas: fmt.Sprintf("%d", payload.ExcessBlobGas), + }, nil +} + +// ---------------------------------------------------------------------------- +// Electra +// ---------------------------------------------------------------------------- + +func (b *SignedBeaconBlockContentsElectra) ToGeneric() (*eth.GenericSignedBeaconBlock, error) { + if b == nil { + return nil, errNilValue } - atts, err := AttsElectraToConsensus(b.Body.Attestations) + + signedElectraBlock, err := b.SignedBlock.ToConsensus() if err != nil { - return nil, server.NewDecodeError(err, "Body.Attestations") + return nil, server.NewDecodeError(err, "SignedBlock") } - deposits, err := DepositsToConsensus(b.Body.Deposits) - if err != nil { - return nil, server.NewDecodeError(err, "Body.Deposits") + proofs := make([][]byte, len(b.KzgProofs)) + for i, proof := range b.KzgProofs { + proofs[i], err = bytesutil.DecodeHexWithLength(proof, fieldparams.BLSPubkeyLength) + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("KzgProofs[%d]", i)) + } } - exits, err := SignedExitsToConsensus(b.Body.VoluntaryExits) - if err != nil { - return nil, server.NewDecodeError(err, "Body.VoluntaryExits") + blbs := make([][]byte, len(b.Blobs)) + for i, blob := range b.Blobs { + blbs[i], err = bytesutil.DecodeHexWithLength(blob, fieldparams.BlobLength) + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("Blobs[%d]", i)) + } } - syncCommitteeBits, err := bytesutil.DecodeHexWithLength(b.Body.SyncAggregate.SyncCommitteeBits, fieldparams.SyncAggregateSyncCommitteeBytesLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.SyncAggregate.SyncCommitteeBits") + blk := ð.SignedBeaconBlockContentsElectra{ + Block: signedElectraBlock, + KzgProofs: proofs, + Blobs: blbs, } - syncCommitteeSig, err := bytesutil.DecodeHexWithLength(b.Body.SyncAggregate.SyncCommitteeSignature, fieldparams.BLSSignatureLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.SyncAggregate.SyncCommitteeSignature") + return ð.GenericSignedBeaconBlock{Block: ð.GenericSignedBeaconBlock_Electra{Electra: blk}}, nil +} + +func (b *SignedBeaconBlockContentsElectra) ToUnsigned() *BeaconBlockContentsElectra { + return &BeaconBlockContentsElectra{ + Block: b.SignedBlock.Message, + KzgProofs: b.KzgProofs, + Blobs: b.Blobs, } - payloadParentHash, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.ParentHash, common.HashLength) +} + +func (b *BeaconBlockContentsElectra) ToGeneric() (*eth.GenericBeaconBlock, error) { + block, err := b.ToConsensus() if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayload.ParentHash") + return nil, err } - payloadFeeRecipient, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.FeeRecipient, fieldparams.FeeRecipientLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayload.FeeRecipient") + + return ð.GenericBeaconBlock{Block: ð.GenericBeaconBlock_Electra{Electra: block}}, nil +} + +func (b *BeaconBlockContentsElectra) ToConsensus() (*eth.BeaconBlockContentsElectra, error) { + if b == nil { + return nil, errNilValue } - payloadStateRoot, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.StateRoot, fieldparams.RootLength) + + electraBlock, err := b.Block.ToConsensus() if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayload.StateRoot") + return nil, server.NewDecodeError(err, "Block") } - payloadReceiptsRoot, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.ReceiptsRoot, fieldparams.RootLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayload.ReceiptsRoot") + proofs := make([][]byte, len(b.KzgProofs)) + for i, proof := range b.KzgProofs { + proofs[i], err = bytesutil.DecodeHexWithLength(proof, fieldparams.BLSPubkeyLength) + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("KzgProofs[%d]", i)) + } } - payloadLogsBloom, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.LogsBloom, fieldparams.LogsBloomLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayload.LogsBloom") + blbs := make([][]byte, len(b.Blobs)) + for i, blob := range b.Blobs { + blbs[i], err = bytesutil.DecodeHexWithLength(blob, fieldparams.BlobLength) + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("Blobs[%d]", i)) + } + } + return ð.BeaconBlockContentsElectra{ + Block: electraBlock, + KzgProofs: proofs, + Blobs: blbs, + }, nil +} + +func (b *BeaconBlockElectra) ToConsensus() (*eth.BeaconBlockElectra, error) { + if b == nil { + return nil, errNilValue + } + if b.Body == nil { + return nil, server.NewDecodeError(errNilValue, "Body") + } + if b.Body.Eth1Data == nil { + return nil, server.NewDecodeError(errNilValue, "Body.Eth1Data") + } + if b.Body.SyncAggregate == nil { + return nil, server.NewDecodeError(errNilValue, "Body.SyncAggregate") + } + if b.Body.ExecutionPayload == nil { + return nil, server.NewDecodeError(errNilValue, "Body.ExecutionPayload") + } + + slot, err := strconv.ParseUint(b.Slot, 10, 64) + if err != nil { + return nil, server.NewDecodeError(err, "Slot") + } + proposerIndex, err := strconv.ParseUint(b.ProposerIndex, 10, 64) + if err != nil { + return nil, server.NewDecodeError(err, "ProposerIndex") + } + parentRoot, err := bytesutil.DecodeHexWithLength(b.ParentRoot, fieldparams.RootLength) + if err != nil { + return nil, server.NewDecodeError(err, "ParentRoot") + } + stateRoot, err := bytesutil.DecodeHexWithLength(b.StateRoot, fieldparams.RootLength) + if err != nil { + return nil, server.NewDecodeError(err, "StateRoot") + } + randaoReveal, err := bytesutil.DecodeHexWithLength(b.Body.RandaoReveal, fieldparams.BLSSignatureLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.RandaoReveal") + } + depositRoot, err := bytesutil.DecodeHexWithLength(b.Body.Eth1Data.DepositRoot, fieldparams.RootLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.Eth1Data.DepositRoot") + } + depositCount, err := strconv.ParseUint(b.Body.Eth1Data.DepositCount, 10, 64) + if err != nil { + return nil, server.NewDecodeError(err, "Body.Eth1Data.DepositCount") + } + blockHash, err := bytesutil.DecodeHexWithLength(b.Body.Eth1Data.BlockHash, common.HashLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.Eth1Data.BlockHash") + } + graffiti, err := bytesutil.DecodeHexWithLength(b.Body.Graffiti, fieldparams.RootLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.Graffiti") + } + proposerSlashings, err := ProposerSlashingsToConsensus(b.Body.ProposerSlashings) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ProposerSlashings") + } + attesterSlashings, err := AttesterSlashingsElectraToConsensus(b.Body.AttesterSlashings) + if err != nil { + return nil, server.NewDecodeError(err, "Body.AttesterSlashings") + } + atts, err := AttsElectraToConsensus(b.Body.Attestations) + if err != nil { + return nil, server.NewDecodeError(err, "Body.Attestations") + } + deposits, err := DepositsToConsensus(b.Body.Deposits) + if err != nil { + return nil, server.NewDecodeError(err, "Body.Deposits") + } + exits, err := SignedExitsToConsensus(b.Body.VoluntaryExits) + if err != nil { + return nil, server.NewDecodeError(err, "Body.VoluntaryExits") + } + syncCommitteeBits, err := bytesutil.DecodeHexWithLength(b.Body.SyncAggregate.SyncCommitteeBits, fieldparams.SyncAggregateSyncCommitteeBytesLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.SyncAggregate.SyncCommitteeBits") + } + syncCommitteeSig, err := bytesutil.DecodeHexWithLength(b.Body.SyncAggregate.SyncCommitteeSignature, fieldparams.BLSSignatureLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.SyncAggregate.SyncCommitteeSignature") + } + payloadParentHash, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.ParentHash, common.HashLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ExecutionPayload.ParentHash") + } + payloadFeeRecipient, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.FeeRecipient, fieldparams.FeeRecipientLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ExecutionPayload.FeeRecipient") + } + payloadStateRoot, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.StateRoot, fieldparams.RootLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ExecutionPayload.StateRoot") + } + payloadReceiptsRoot, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.ReceiptsRoot, fieldparams.RootLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ExecutionPayload.ReceiptsRoot") + } + payloadLogsBloom, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.LogsBloom, fieldparams.LogsBloomLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ExecutionPayload.LogsBloom") } payloadPrevRandao, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayload.PrevRandao, fieldparams.RootLength) if err != nil { @@ -2160,7 +2764,7 @@ func (b *BeaconBlockElectra) ToConsensus() (*eth.BeaconBlockElectra, error) { SyncCommitteeBits: syncCommitteeBits, SyncCommitteeSignature: syncCommitteeSig, }, - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: payloadParentHash, FeeRecipient: payloadFeeRecipient, StateRoot: payloadStateRoot, @@ -2354,589 +2958,153 @@ func (b *BlindedBeaconBlockElectra) ToConsensus() (*eth.BlindedBeaconBlockElectr payloadBlockNumber, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.BlockNumber, 10, 64) if err != nil { return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.BlockNumber") - } - payloadGasLimit, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.GasLimit, 10, 64) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.GasLimit") - } - payloadGasUsed, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.GasUsed, 10, 64) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.GasUsed") - } - payloadTimestamp, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.Timestamp, 10, 64) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.Timestamp") - } - payloadExtraData, err := bytesutil.DecodeHexWithMaxLength(b.Body.ExecutionPayloadHeader.ExtraData, fieldparams.RootLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.ExtraData") - } - payloadBaseFeePerGas, err := bytesutil.Uint256ToSSZBytes(b.Body.ExecutionPayloadHeader.BaseFeePerGas) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.BaseFeePerGas") - } - payloadBlockHash, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayloadHeader.BlockHash, common.HashLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.BlockHash") - } - payloadTxsRoot, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayloadHeader.TransactionsRoot, fieldparams.RootLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.TransactionsRoot") - } - payloadWithdrawalsRoot, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayloadHeader.WithdrawalsRoot, fieldparams.RootLength) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.WithdrawalsRoot") - } - payloadBlobGasUsed, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.BlobGasUsed, 10, 64) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayload.BlobGasUsed") - } - payloadExcessBlobGas, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.ExcessBlobGas, 10, 64) - if err != nil { - return nil, server.NewDecodeError(err, "Body.ExecutionPayload.ExcessBlobGas") - } - if b.Body.ExecutionRequests == nil { - return nil, server.NewDecodeError(errors.New("nil execution requests"), "Body.ExecutionRequests") - } - depositRequests := make([]*enginev1.DepositRequest, len(b.Body.ExecutionRequests.Deposits)) - for i, d := range b.Body.ExecutionRequests.Deposits { - depositRequests[i], err = d.ToConsensus() - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("Body.ExecutionRequests.Deposits[%d]", i)) - } - } - - withdrawalRequests := make([]*enginev1.WithdrawalRequest, len(b.Body.ExecutionRequests.Withdrawals)) - for i, w := range b.Body.ExecutionRequests.Withdrawals { - withdrawalRequests[i], err = w.ToConsensus() - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("Body.ExecutionRequests.Withdrawals[%d]", i)) - } - } - - consolidationRequests := make([]*enginev1.ConsolidationRequest, len(b.Body.ExecutionRequests.Consolidations)) - for i, c := range b.Body.ExecutionRequests.Consolidations { - consolidationRequests[i], err = c.ToConsensus() - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("Body.ExecutionRequests.Consolidations[%d]", i)) - } - } - - blsChanges, err := SignedBLSChangesToConsensus(b.Body.BLSToExecutionChanges) - if err != nil { - return nil, server.NewDecodeError(err, "Body.BLSToExecutionChanges") - } - err = slice.VerifyMaxLength(b.Body.BlobKzgCommitments, fieldparams.MaxBlobCommitmentsPerBlock) - if err != nil { - return nil, server.NewDecodeError(err, "Body.BlobKzgCommitments") - } - blobKzgCommitments := make([][]byte, len(b.Body.BlobKzgCommitments)) - for i, b := range b.Body.BlobKzgCommitments { - kzg, err := bytesutil.DecodeHexWithLength(b, fieldparams.BLSPubkeyLength) - if err != nil { - return nil, server.NewDecodeError(err, fmt.Sprintf("Body.BlobKzgCommitments[%d]", i)) - } - blobKzgCommitments[i] = kzg - } - - return ð.BlindedBeaconBlockElectra{ - Slot: primitives.Slot(slot), - ProposerIndex: primitives.ValidatorIndex(proposerIndex), - ParentRoot: parentRoot, - StateRoot: stateRoot, - Body: ð.BlindedBeaconBlockBodyElectra{ - RandaoReveal: randaoReveal, - Eth1Data: ð.Eth1Data{ - DepositRoot: depositRoot, - DepositCount: depositCount, - BlockHash: blockHash, - }, - Graffiti: graffiti, - ProposerSlashings: proposerSlashings, - AttesterSlashings: attesterSlashings, - Attestations: atts, - Deposits: deposits, - VoluntaryExits: exits, - SyncAggregate: ð.SyncAggregate{ - SyncCommitteeBits: syncCommitteeBits, - SyncCommitteeSignature: syncCommitteeSig, - }, - ExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderElectra{ - ParentHash: payloadParentHash, - FeeRecipient: payloadFeeRecipient, - StateRoot: payloadStateRoot, - ReceiptsRoot: payloadReceiptsRoot, - LogsBloom: payloadLogsBloom, - PrevRandao: payloadPrevRandao, - BlockNumber: payloadBlockNumber, - GasLimit: payloadGasLimit, - GasUsed: payloadGasUsed, - Timestamp: payloadTimestamp, - ExtraData: payloadExtraData, - BaseFeePerGas: payloadBaseFeePerGas, - BlockHash: payloadBlockHash, - TransactionsRoot: payloadTxsRoot, - WithdrawalsRoot: payloadWithdrawalsRoot, - BlobGasUsed: payloadBlobGasUsed, - ExcessBlobGas: payloadExcessBlobGas, - }, - BlsToExecutionChanges: blsChanges, - BlobKzgCommitments: blobKzgCommitments, - ExecutionRequests: &enginev1.ExecutionRequests{ - Deposits: depositRequests, - Withdrawals: withdrawalRequests, - Consolidations: consolidationRequests, - }, - }, - }, nil -} - -func (b *BlindedBeaconBlockElectra) ToGeneric() (*eth.GenericBeaconBlock, error) { - if b == nil { - return nil, errNilValue - } - - blindedBlock, err := b.ToConsensus() - if err != nil { - return nil, err - } - return ð.GenericBeaconBlock{Block: ð.GenericBeaconBlock_BlindedElectra{BlindedElectra: blindedBlock}, IsBlinded: true}, nil -} - -func BeaconBlockHeaderFromConsensus(h *eth.BeaconBlockHeader) *BeaconBlockHeader { - return &BeaconBlockHeader{ - Slot: fmt.Sprintf("%d", h.Slot), - ProposerIndex: fmt.Sprintf("%d", h.ProposerIndex), - ParentRoot: hexutil.Encode(h.ParentRoot), - StateRoot: hexutil.Encode(h.StateRoot), - BodyRoot: hexutil.Encode(h.BodyRoot), - } -} - -func BeaconBlockFromConsensus(b *eth.BeaconBlock) *BeaconBlock { - return &BeaconBlock{ - Slot: fmt.Sprintf("%d", b.Slot), - ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), - ParentRoot: hexutil.Encode(b.ParentRoot), - StateRoot: hexutil.Encode(b.StateRoot), - Body: &BeaconBlockBody{ - RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), - Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), - Graffiti: hexutil.Encode(b.Body.Graffiti), - ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), - AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), - Attestations: AttsFromConsensus(b.Body.Attestations), - Deposits: DepositsFromConsensus(b.Body.Deposits), - VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), - }, - } -} - -func SignedBeaconBlockMessageJsoner(block interfaces.ReadOnlySignedBeaconBlock) (SignedMessageJsoner, error) { - pb, err := block.Proto() - if err != nil { - return nil, err - } - switch pbStruct := pb.(type) { - case *eth.SignedBeaconBlock: - return SignedBeaconBlockPhase0FromConsensus(pbStruct), nil - case *eth.SignedBeaconBlockAltair: - return SignedBeaconBlockAltairFromConsensus(pbStruct), nil - case *eth.SignedBlindedBeaconBlockBellatrix: - return SignedBlindedBeaconBlockBellatrixFromConsensus(pbStruct) - case *eth.SignedBeaconBlockBellatrix: - return SignedBeaconBlockBellatrixFromConsensus(pbStruct) - case *eth.SignedBlindedBeaconBlockCapella: - return SignedBlindedBeaconBlockCapellaFromConsensus(pbStruct) - case *eth.SignedBeaconBlockCapella: - return SignedBeaconBlockCapellaFromConsensus(pbStruct) - case *eth.SignedBlindedBeaconBlockDeneb: - return SignedBlindedBeaconBlockDenebFromConsensus(pbStruct) - case *eth.SignedBeaconBlockDeneb: - return SignedBeaconBlockDenebFromConsensus(pbStruct) - case *eth.SignedBlindedBeaconBlockElectra: - return SignedBlindedBeaconBlockElectraFromConsensus(pbStruct) - case *eth.SignedBeaconBlockElectra: - return SignedBeaconBlockElectraFromConsensus(pbStruct) - default: - return nil, ErrUnsupportedConversion - } -} - -func SignedBeaconBlockPhase0FromConsensus(b *eth.SignedBeaconBlock) *SignedBeaconBlock { - return &SignedBeaconBlock{ - Message: BeaconBlockFromConsensus(b.Block), - Signature: hexutil.Encode(b.Signature), - } -} - -func BeaconBlockAltairFromConsensus(b *eth.BeaconBlockAltair) *BeaconBlockAltair { - return &BeaconBlockAltair{ - Slot: fmt.Sprintf("%d", b.Slot), - ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), - ParentRoot: hexutil.Encode(b.ParentRoot), - StateRoot: hexutil.Encode(b.StateRoot), - Body: &BeaconBlockBodyAltair{ - RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), - Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), - Graffiti: hexutil.Encode(b.Body.Graffiti), - ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), - AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), - Attestations: AttsFromConsensus(b.Body.Attestations), - Deposits: DepositsFromConsensus(b.Body.Deposits), - VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), - SyncAggregate: &SyncAggregate{ - SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), - SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), - }, - }, - } -} - -func SignedBeaconBlockAltairFromConsensus(b *eth.SignedBeaconBlockAltair) *SignedBeaconBlockAltair { - return &SignedBeaconBlockAltair{ - Message: BeaconBlockAltairFromConsensus(b.Block), - Signature: hexutil.Encode(b.Signature), - } -} - -func BlindedBeaconBlockBellatrixFromConsensus(b *eth.BlindedBeaconBlockBellatrix) (*BlindedBeaconBlockBellatrix, error) { - payload, err := ExecutionPayloadHeaderFromConsensus(b.Body.ExecutionPayloadHeader) - if err != nil { - return nil, err - } - - return &BlindedBeaconBlockBellatrix{ - Slot: fmt.Sprintf("%d", b.Slot), - ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), - ParentRoot: hexutil.Encode(b.ParentRoot), - StateRoot: hexutil.Encode(b.StateRoot), - Body: &BlindedBeaconBlockBodyBellatrix{ - RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), - Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), - Graffiti: hexutil.Encode(b.Body.Graffiti), - ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), - AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), - Attestations: AttsFromConsensus(b.Body.Attestations), - Deposits: DepositsFromConsensus(b.Body.Deposits), - VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), - SyncAggregate: &SyncAggregate{ - SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), - SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), - }, - ExecutionPayloadHeader: payload, - }, - }, nil -} - -func SignedBlindedBeaconBlockBellatrixFromConsensus(b *eth.SignedBlindedBeaconBlockBellatrix) (*SignedBlindedBeaconBlockBellatrix, error) { - blindedBlock, err := BlindedBeaconBlockBellatrixFromConsensus(b.Block) - if err != nil { - return nil, err - } - return &SignedBlindedBeaconBlockBellatrix{ - Message: blindedBlock, - Signature: hexutil.Encode(b.Signature), - }, nil -} - -func BeaconBlockBellatrixFromConsensus(b *eth.BeaconBlockBellatrix) (*BeaconBlockBellatrix, error) { - payload, err := ExecutionPayloadFromConsensus(b.Body.ExecutionPayload) - if err != nil { - return nil, err - } - - return &BeaconBlockBellatrix{ - Slot: fmt.Sprintf("%d", b.Slot), - ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), - ParentRoot: hexutil.Encode(b.ParentRoot), - StateRoot: hexutil.Encode(b.StateRoot), - Body: &BeaconBlockBodyBellatrix{ - RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), - Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), - Graffiti: hexutil.Encode(b.Body.Graffiti), - ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), - AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), - Attestations: AttsFromConsensus(b.Body.Attestations), - Deposits: DepositsFromConsensus(b.Body.Deposits), - VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), - SyncAggregate: &SyncAggregate{ - SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), - SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), - }, - ExecutionPayload: payload, - }, - }, nil -} - -func SignedBeaconBlockBellatrixFromConsensus(b *eth.SignedBeaconBlockBellatrix) (*SignedBeaconBlockBellatrix, error) { - block, err := BeaconBlockBellatrixFromConsensus(b.Block) - if err != nil { - return nil, err - } - return &SignedBeaconBlockBellatrix{ - Message: block, - Signature: hexutil.Encode(b.Signature), - }, nil -} - -func BlindedBeaconBlockCapellaFromConsensus(b *eth.BlindedBeaconBlockCapella) (*BlindedBeaconBlockCapella, error) { - payload, err := ExecutionPayloadHeaderCapellaFromConsensus(b.Body.ExecutionPayloadHeader) + } + payloadGasLimit, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.GasLimit, 10, 64) if err != nil { - return nil, err + return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.GasLimit") } - - return &BlindedBeaconBlockCapella{ - Slot: fmt.Sprintf("%d", b.Slot), - ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), - ParentRoot: hexutil.Encode(b.ParentRoot), - StateRoot: hexutil.Encode(b.StateRoot), - Body: &BlindedBeaconBlockBodyCapella{ - RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), - Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), - Graffiti: hexutil.Encode(b.Body.Graffiti), - ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), - AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), - Attestations: AttsFromConsensus(b.Body.Attestations), - Deposits: DepositsFromConsensus(b.Body.Deposits), - VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), - SyncAggregate: &SyncAggregate{ - SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), - SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), - }, - ExecutionPayloadHeader: payload, - BLSToExecutionChanges: SignedBLSChangesFromConsensus(b.Body.BlsToExecutionChanges), - }, - }, nil -} - -func SignedBlindedBeaconBlockCapellaFromConsensus(b *eth.SignedBlindedBeaconBlockCapella) (*SignedBlindedBeaconBlockCapella, error) { - blindedBlock, err := BlindedBeaconBlockCapellaFromConsensus(b.Block) + payloadGasUsed, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.GasUsed, 10, 64) if err != nil { - return nil, err + return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.GasUsed") } - return &SignedBlindedBeaconBlockCapella{ - Message: blindedBlock, - Signature: hexutil.Encode(b.Signature), - }, nil -} - -func BeaconBlockCapellaFromConsensus(b *eth.BeaconBlockCapella) (*BeaconBlockCapella, error) { - payload, err := ExecutionPayloadCapellaFromConsensus(b.Body.ExecutionPayload) + payloadTimestamp, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.Timestamp, 10, 64) if err != nil { - return nil, err + return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.Timestamp") } - - return &BeaconBlockCapella{ - Slot: fmt.Sprintf("%d", b.Slot), - ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), - ParentRoot: hexutil.Encode(b.ParentRoot), - StateRoot: hexutil.Encode(b.StateRoot), - Body: &BeaconBlockBodyCapella{ - RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), - Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), - Graffiti: hexutil.Encode(b.Body.Graffiti), - ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), - AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), - Attestations: AttsFromConsensus(b.Body.Attestations), - Deposits: DepositsFromConsensus(b.Body.Deposits), - VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), - SyncAggregate: &SyncAggregate{ - SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), - SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), - }, - ExecutionPayload: payload, - BLSToExecutionChanges: SignedBLSChangesFromConsensus(b.Body.BlsToExecutionChanges), - }, - }, nil -} - -func SignedBeaconBlockCapellaFromConsensus(b *eth.SignedBeaconBlockCapella) (*SignedBeaconBlockCapella, error) { - block, err := BeaconBlockCapellaFromConsensus(b.Block) + payloadExtraData, err := bytesutil.DecodeHexWithMaxLength(b.Body.ExecutionPayloadHeader.ExtraData, fieldparams.RootLength) if err != nil { - return nil, err + return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.ExtraData") } - return &SignedBeaconBlockCapella{ - Message: block, - Signature: hexutil.Encode(b.Signature), - }, nil -} - -func BeaconBlockContentsDenebFromConsensus(b *eth.BeaconBlockContentsDeneb) (*BeaconBlockContentsDeneb, error) { - block, err := BeaconBlockDenebFromConsensus(b.Block) + payloadBaseFeePerGas, err := bytesutil.Uint256ToSSZBytes(b.Body.ExecutionPayloadHeader.BaseFeePerGas) if err != nil { - return nil, err + return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.BaseFeePerGas") } - proofs := make([]string, len(b.KzgProofs)) - for i, proof := range b.KzgProofs { - proofs[i] = hexutil.Encode(proof) + payloadBlockHash, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayloadHeader.BlockHash, common.HashLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.BlockHash") } - blbs := make([]string, len(b.Blobs)) - for i, blob := range b.Blobs { - blbs[i] = hexutil.Encode(blob) + payloadTxsRoot, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayloadHeader.TransactionsRoot, fieldparams.RootLength) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.TransactionsRoot") } - return &BeaconBlockContentsDeneb{ - Block: block, - KzgProofs: proofs, - Blobs: blbs, - }, nil -} - -func SignedBeaconBlockContentsDenebFromConsensus(b *eth.SignedBeaconBlockContentsDeneb) (*SignedBeaconBlockContentsDeneb, error) { - block, err := SignedBeaconBlockDenebFromConsensus(b.Block) + payloadWithdrawalsRoot, err := bytesutil.DecodeHexWithLength(b.Body.ExecutionPayloadHeader.WithdrawalsRoot, fieldparams.RootLength) if err != nil { - return nil, err + return nil, server.NewDecodeError(err, "Body.ExecutionPayloadHeader.WithdrawalsRoot") } - - proofs := make([]string, len(b.KzgProofs)) - for i, proof := range b.KzgProofs { - proofs[i] = hexutil.Encode(proof) + payloadBlobGasUsed, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.BlobGasUsed, 10, 64) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ExecutionPayload.BlobGasUsed") } - - blbs := make([]string, len(b.Blobs)) - for i, blob := range b.Blobs { - blbs[i] = hexutil.Encode(blob) + payloadExcessBlobGas, err := strconv.ParseUint(b.Body.ExecutionPayloadHeader.ExcessBlobGas, 10, 64) + if err != nil { + return nil, server.NewDecodeError(err, "Body.ExecutionPayload.ExcessBlobGas") } - - return &SignedBeaconBlockContentsDeneb{ - SignedBlock: block, - KzgProofs: proofs, - Blobs: blbs, - }, nil -} - -func BlindedBeaconBlockDenebFromConsensus(b *eth.BlindedBeaconBlockDeneb) (*BlindedBeaconBlockDeneb, error) { - blobKzgCommitments := make([]string, len(b.Body.BlobKzgCommitments)) - for i := range b.Body.BlobKzgCommitments { - blobKzgCommitments[i] = hexutil.Encode(b.Body.BlobKzgCommitments[i]) + if b.Body.ExecutionRequests == nil { + return nil, server.NewDecodeError(errors.New("nil execution requests"), "Body.ExecutionRequests") } - payload, err := ExecutionPayloadHeaderDenebFromConsensus(b.Body.ExecutionPayloadHeader) - if err != nil { - return nil, err + depositRequests := make([]*enginev1.DepositRequest, len(b.Body.ExecutionRequests.Deposits)) + for i, d := range b.Body.ExecutionRequests.Deposits { + depositRequests[i], err = d.ToConsensus() + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("Body.ExecutionRequests.Deposits[%d]", i)) + } } - return &BlindedBeaconBlockDeneb{ - Slot: fmt.Sprintf("%d", b.Slot), - ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), - ParentRoot: hexutil.Encode(b.ParentRoot), - StateRoot: hexutil.Encode(b.StateRoot), - Body: &BlindedBeaconBlockBodyDeneb{ - RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), - Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), - Graffiti: hexutil.Encode(b.Body.Graffiti), - ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), - AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), - Attestations: AttsFromConsensus(b.Body.Attestations), - Deposits: DepositsFromConsensus(b.Body.Deposits), - VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), - SyncAggregate: &SyncAggregate{ - SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), - SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), - }, - ExecutionPayloadHeader: payload, - BLSToExecutionChanges: SignedBLSChangesFromConsensus(b.Body.BlsToExecutionChanges), - BlobKzgCommitments: blobKzgCommitments, - }, - }, nil -} + withdrawalRequests := make([]*enginev1.WithdrawalRequest, len(b.Body.ExecutionRequests.Withdrawals)) + for i, w := range b.Body.ExecutionRequests.Withdrawals { + withdrawalRequests[i], err = w.ToConsensus() + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("Body.ExecutionRequests.Withdrawals[%d]", i)) + } + } -func SignedBlindedBeaconBlockDenebFromConsensus(b *eth.SignedBlindedBeaconBlockDeneb) (*SignedBlindedBeaconBlockDeneb, error) { - block, err := BlindedBeaconBlockDenebFromConsensus(b.Message) - if err != nil { - return nil, err + consolidationRequests := make([]*enginev1.ConsolidationRequest, len(b.Body.ExecutionRequests.Consolidations)) + for i, c := range b.Body.ExecutionRequests.Consolidations { + consolidationRequests[i], err = c.ToConsensus() + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("Body.ExecutionRequests.Consolidations[%d]", i)) + } } - return &SignedBlindedBeaconBlockDeneb{ - Message: block, - Signature: hexutil.Encode(b.Signature), - }, nil -} -func BeaconBlockDenebFromConsensus(b *eth.BeaconBlockDeneb) (*BeaconBlockDeneb, error) { - baseFeePerGas, err := sszBytesToUint256String(b.Body.ExecutionPayload.BaseFeePerGas) + blsChanges, err := SignedBLSChangesToConsensus(b.Body.BLSToExecutionChanges) if err != nil { - return nil, err + return nil, server.NewDecodeError(err, "Body.BLSToExecutionChanges") } - transactions := make([]string, len(b.Body.ExecutionPayload.Transactions)) - for i, tx := range b.Body.ExecutionPayload.Transactions { - transactions[i] = hexutil.Encode(tx) + err = slice.VerifyMaxLength(b.Body.BlobKzgCommitments, fieldparams.MaxBlobCommitmentsPerBlock) + if err != nil { + return nil, server.NewDecodeError(err, "Body.BlobKzgCommitments") } - blobKzgCommitments := make([]string, len(b.Body.BlobKzgCommitments)) - for i := range b.Body.BlobKzgCommitments { - blobKzgCommitments[i] = hexutil.Encode(b.Body.BlobKzgCommitments[i]) + blobKzgCommitments := make([][]byte, len(b.Body.BlobKzgCommitments)) + for i, b := range b.Body.BlobKzgCommitments { + kzg, err := bytesutil.DecodeHexWithLength(b, fieldparams.BLSPubkeyLength) + if err != nil { + return nil, server.NewDecodeError(err, fmt.Sprintf("Body.BlobKzgCommitments[%d]", i)) + } + blobKzgCommitments[i] = kzg } - return &BeaconBlockDeneb{ - Slot: fmt.Sprintf("%d", b.Slot), - ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex), - ParentRoot: hexutil.Encode(b.ParentRoot), - StateRoot: hexutil.Encode(b.StateRoot), - Body: &BeaconBlockBodyDeneb{ - RandaoReveal: hexutil.Encode(b.Body.RandaoReveal), - Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data), - Graffiti: hexutil.Encode(b.Body.Graffiti), - ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings), - AttesterSlashings: AttesterSlashingsFromConsensus(b.Body.AttesterSlashings), - Attestations: AttsFromConsensus(b.Body.Attestations), - Deposits: DepositsFromConsensus(b.Body.Deposits), - VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits), - SyncAggregate: &SyncAggregate{ - SyncCommitteeBits: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeBits), - SyncCommitteeSignature: hexutil.Encode(b.Body.SyncAggregate.SyncCommitteeSignature), - }, - ExecutionPayload: &ExecutionPayloadDeneb{ - ParentHash: hexutil.Encode(b.Body.ExecutionPayload.ParentHash), - FeeRecipient: hexutil.Encode(b.Body.ExecutionPayload.FeeRecipient), - StateRoot: hexutil.Encode(b.Body.ExecutionPayload.StateRoot), - ReceiptsRoot: hexutil.Encode(b.Body.ExecutionPayload.ReceiptsRoot), - LogsBloom: hexutil.Encode(b.Body.ExecutionPayload.LogsBloom), - PrevRandao: hexutil.Encode(b.Body.ExecutionPayload.PrevRandao), - BlockNumber: fmt.Sprintf("%d", b.Body.ExecutionPayload.BlockNumber), - GasLimit: fmt.Sprintf("%d", b.Body.ExecutionPayload.GasLimit), - GasUsed: fmt.Sprintf("%d", b.Body.ExecutionPayload.GasUsed), - Timestamp: fmt.Sprintf("%d", b.Body.ExecutionPayload.Timestamp), - ExtraData: hexutil.Encode(b.Body.ExecutionPayload.ExtraData), - BaseFeePerGas: baseFeePerGas, - BlockHash: hexutil.Encode(b.Body.ExecutionPayload.BlockHash), - Transactions: transactions, - Withdrawals: WithdrawalsFromConsensus(b.Body.ExecutionPayload.Withdrawals), - BlobGasUsed: fmt.Sprintf("%d", b.Body.ExecutionPayload.BlobGasUsed), - ExcessBlobGas: fmt.Sprintf("%d", b.Body.ExecutionPayload.ExcessBlobGas), + return ð.BlindedBeaconBlockElectra{ + Slot: primitives.Slot(slot), + ProposerIndex: primitives.ValidatorIndex(proposerIndex), + ParentRoot: parentRoot, + StateRoot: stateRoot, + Body: ð.BlindedBeaconBlockBodyElectra{ + RandaoReveal: randaoReveal, + Eth1Data: ð.Eth1Data{ + DepositRoot: depositRoot, + DepositCount: depositCount, + BlockHash: blockHash, }, - BLSToExecutionChanges: SignedBLSChangesFromConsensus(b.Body.BlsToExecutionChanges), + Graffiti: graffiti, + ProposerSlashings: proposerSlashings, + AttesterSlashings: attesterSlashings, + Attestations: atts, + Deposits: deposits, + VoluntaryExits: exits, + SyncAggregate: ð.SyncAggregate{ + SyncCommitteeBits: syncCommitteeBits, + SyncCommitteeSignature: syncCommitteeSig, + }, + ExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderDeneb{ + ParentHash: payloadParentHash, + FeeRecipient: payloadFeeRecipient, + StateRoot: payloadStateRoot, + ReceiptsRoot: payloadReceiptsRoot, + LogsBloom: payloadLogsBloom, + PrevRandao: payloadPrevRandao, + BlockNumber: payloadBlockNumber, + GasLimit: payloadGasLimit, + GasUsed: payloadGasUsed, + Timestamp: payloadTimestamp, + ExtraData: payloadExtraData, + BaseFeePerGas: payloadBaseFeePerGas, + BlockHash: payloadBlockHash, + TransactionsRoot: payloadTxsRoot, + WithdrawalsRoot: payloadWithdrawalsRoot, + BlobGasUsed: payloadBlobGasUsed, + ExcessBlobGas: payloadExcessBlobGas, + }, + BlsToExecutionChanges: blsChanges, BlobKzgCommitments: blobKzgCommitments, + ExecutionRequests: &enginev1.ExecutionRequests{ + Deposits: depositRequests, + Withdrawals: withdrawalRequests, + Consolidations: consolidationRequests, + }, }, }, nil } -func SignedBeaconBlockDenebFromConsensus(b *eth.SignedBeaconBlockDeneb) (*SignedBeaconBlockDeneb, error) { - block, err := BeaconBlockDenebFromConsensus(b.Block) - if err != nil { - return nil, err +func (b *BlindedBeaconBlockElectra) ToGeneric() (*eth.GenericBeaconBlock, error) { + if b == nil { + return nil, errNilValue } - return &SignedBeaconBlockDeneb{ - Message: block, - Signature: hexutil.Encode(b.Signature), - }, nil -} -func BeaconBlockContentsElectraFromConsensus(b *eth.BeaconBlockContentsElectra) (*BeaconBlockContentsElectra, error) { - block, err := BeaconBlockElectraFromConsensus(b.Block) + blindedBlock, err := b.ToConsensus() if err != nil { return nil, err } - proofs := make([]string, len(b.KzgProofs)) - for i, proof := range b.KzgProofs { - proofs[i] = hexutil.Encode(proof) - } - blbs := make([]string, len(b.Blobs)) - for i, blob := range b.Blobs { - blbs[i] = hexutil.Encode(blob) - } - return &BeaconBlockContentsElectra{ - Block: block, - KzgProofs: proofs, - Blobs: blbs, - }, nil + return ð.GenericBeaconBlock{Block: ð.GenericBeaconBlock_BlindedElectra{BlindedElectra: blindedBlock}, IsBlinded: true}, nil } func SignedBeaconBlockContentsElectraFromConsensus(b *eth.SignedBeaconBlockContentsElectra) (*SignedBeaconBlockContentsElectra, error) { @@ -2998,6 +3166,26 @@ func BlindedBeaconBlockElectraFromConsensus(b *eth.BlindedBeaconBlockElectra) (* }, nil } +func BeaconBlockContentsElectraFromConsensus(b *eth.BeaconBlockContentsElectra) (*BeaconBlockContentsElectra, error) { + block, err := BeaconBlockElectraFromConsensus(b.Block) + if err != nil { + return nil, err + } + proofs := make([]string, len(b.KzgProofs)) + for i, proof := range b.KzgProofs { + proofs[i] = hexutil.Encode(proof) + } + blbs := make([]string, len(b.Blobs)) + for i, blob := range b.Blobs { + blbs[i] = hexutil.Encode(blob) + } + return &BeaconBlockContentsElectra{ + Block: block, + KzgProofs: proofs, + Blobs: blbs, + }, nil +} + func ExecutionRequestsFromConsensus(er *enginev1.ExecutionRequests) *ExecutionRequests { return &ExecutionRequests{ Deposits: DepositRequestsFromConsensus(er.Deposits), @@ -3064,170 +3252,7 @@ func SignedBeaconBlockElectraFromConsensus(b *eth.SignedBeaconBlockElectra) (*Si }, nil } -func ExecutionPayloadFromConsensus(payload *enginev1.ExecutionPayload) (*ExecutionPayload, error) { - baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) - if err != nil { - return nil, err - } - transactions := make([]string, len(payload.Transactions)) - for i, tx := range payload.Transactions { - transactions[i] = hexutil.Encode(tx) - } - - return &ExecutionPayload{ - ParentHash: hexutil.Encode(payload.ParentHash), - FeeRecipient: hexutil.Encode(payload.FeeRecipient), - StateRoot: hexutil.Encode(payload.StateRoot), - ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), - LogsBloom: hexutil.Encode(payload.LogsBloom), - PrevRandao: hexutil.Encode(payload.PrevRandao), - BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), - GasLimit: fmt.Sprintf("%d", payload.GasLimit), - GasUsed: fmt.Sprintf("%d", payload.GasUsed), - Timestamp: fmt.Sprintf("%d", payload.Timestamp), - ExtraData: hexutil.Encode(payload.ExtraData), - BaseFeePerGas: baseFeePerGas, - BlockHash: hexutil.Encode(payload.BlockHash), - Transactions: transactions, - }, nil -} - -func ExecutionPayloadCapellaFromConsensus(payload *enginev1.ExecutionPayloadCapella) (*ExecutionPayloadCapella, error) { - baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) - if err != nil { - return nil, err - } - transactions := make([]string, len(payload.Transactions)) - for i, tx := range payload.Transactions { - transactions[i] = hexutil.Encode(tx) - } - - return &ExecutionPayloadCapella{ - ParentHash: hexutil.Encode(payload.ParentHash), - FeeRecipient: hexutil.Encode(payload.FeeRecipient), - StateRoot: hexutil.Encode(payload.StateRoot), - ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), - LogsBloom: hexutil.Encode(payload.LogsBloom), - PrevRandao: hexutil.Encode(payload.PrevRandao), - BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), - GasLimit: fmt.Sprintf("%d", payload.GasLimit), - GasUsed: fmt.Sprintf("%d", payload.GasUsed), - Timestamp: fmt.Sprintf("%d", payload.Timestamp), - ExtraData: hexutil.Encode(payload.ExtraData), - BaseFeePerGas: baseFeePerGas, - BlockHash: hexutil.Encode(payload.BlockHash), - Transactions: transactions, - Withdrawals: WithdrawalsFromConsensus(payload.Withdrawals), - }, nil -} - -func ExecutionPayloadDenebFromConsensus(payload *enginev1.ExecutionPayloadDeneb) (*ExecutionPayloadDeneb, error) { - baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) - if err != nil { - return nil, err - } - transactions := make([]string, len(payload.Transactions)) - for i, tx := range payload.Transactions { - transactions[i] = hexutil.Encode(tx) - } - - return &ExecutionPayloadDeneb{ - ParentHash: hexutil.Encode(payload.ParentHash), - FeeRecipient: hexutil.Encode(payload.FeeRecipient), - StateRoot: hexutil.Encode(payload.StateRoot), - ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), - LogsBloom: hexutil.Encode(payload.LogsBloom), - PrevRandao: hexutil.Encode(payload.PrevRandao), - BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), - GasLimit: fmt.Sprintf("%d", payload.GasLimit), - GasUsed: fmt.Sprintf("%d", payload.GasUsed), - Timestamp: fmt.Sprintf("%d", payload.Timestamp), - ExtraData: hexutil.Encode(payload.ExtraData), - BaseFeePerGas: baseFeePerGas, - BlockHash: hexutil.Encode(payload.BlockHash), - Transactions: transactions, - Withdrawals: WithdrawalsFromConsensus(payload.Withdrawals), - BlobGasUsed: fmt.Sprintf("%d", payload.BlobGasUsed), - ExcessBlobGas: fmt.Sprintf("%d", payload.ExcessBlobGas), - }, nil -} - -var ExecutionPayloadElectraFromConsensus = ExecutionPayloadDenebFromConsensus - -func ExecutionPayloadHeaderFromConsensus(payload *enginev1.ExecutionPayloadHeader) (*ExecutionPayloadHeader, error) { - baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) - if err != nil { - return nil, err - } - - return &ExecutionPayloadHeader{ - ParentHash: hexutil.Encode(payload.ParentHash), - FeeRecipient: hexutil.Encode(payload.FeeRecipient), - StateRoot: hexutil.Encode(payload.StateRoot), - ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), - LogsBloom: hexutil.Encode(payload.LogsBloom), - PrevRandao: hexutil.Encode(payload.PrevRandao), - BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), - GasLimit: fmt.Sprintf("%d", payload.GasLimit), - GasUsed: fmt.Sprintf("%d", payload.GasUsed), - Timestamp: fmt.Sprintf("%d", payload.Timestamp), - ExtraData: hexutil.Encode(payload.ExtraData), - BaseFeePerGas: baseFeePerGas, - BlockHash: hexutil.Encode(payload.BlockHash), - TransactionsRoot: hexutil.Encode(payload.TransactionsRoot), - }, nil -} - -func ExecutionPayloadHeaderCapellaFromConsensus(payload *enginev1.ExecutionPayloadHeaderCapella) (*ExecutionPayloadHeaderCapella, error) { - baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) - if err != nil { - return nil, err - } - - return &ExecutionPayloadHeaderCapella{ - ParentHash: hexutil.Encode(payload.ParentHash), - FeeRecipient: hexutil.Encode(payload.FeeRecipient), - StateRoot: hexutil.Encode(payload.StateRoot), - ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), - LogsBloom: hexutil.Encode(payload.LogsBloom), - PrevRandao: hexutil.Encode(payload.PrevRandao), - BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), - GasLimit: fmt.Sprintf("%d", payload.GasLimit), - GasUsed: fmt.Sprintf("%d", payload.GasUsed), - Timestamp: fmt.Sprintf("%d", payload.Timestamp), - ExtraData: hexutil.Encode(payload.ExtraData), - BaseFeePerGas: baseFeePerGas, - BlockHash: hexutil.Encode(payload.BlockHash), - TransactionsRoot: hexutil.Encode(payload.TransactionsRoot), - WithdrawalsRoot: hexutil.Encode(payload.WithdrawalsRoot), - }, nil -} - -func ExecutionPayloadHeaderDenebFromConsensus(payload *enginev1.ExecutionPayloadHeaderDeneb) (*ExecutionPayloadHeaderDeneb, error) { - baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) - if err != nil { - return nil, err - } - - return &ExecutionPayloadHeaderDeneb{ - ParentHash: hexutil.Encode(payload.ParentHash), - FeeRecipient: hexutil.Encode(payload.FeeRecipient), - StateRoot: hexutil.Encode(payload.StateRoot), - ReceiptsRoot: hexutil.Encode(payload.ReceiptsRoot), - LogsBloom: hexutil.Encode(payload.LogsBloom), - PrevRandao: hexutil.Encode(payload.PrevRandao), - BlockNumber: fmt.Sprintf("%d", payload.BlockNumber), - GasLimit: fmt.Sprintf("%d", payload.GasLimit), - GasUsed: fmt.Sprintf("%d", payload.GasUsed), - Timestamp: fmt.Sprintf("%d", payload.Timestamp), - ExtraData: hexutil.Encode(payload.ExtraData), - BaseFeePerGas: baseFeePerGas, - BlockHash: hexutil.Encode(payload.BlockHash), - TransactionsRoot: hexutil.Encode(payload.TransactionsRoot), - WithdrawalsRoot: hexutil.Encode(payload.WithdrawalsRoot), - BlobGasUsed: fmt.Sprintf("%d", payload.BlobGasUsed), - ExcessBlobGas: fmt.Sprintf("%d", payload.ExcessBlobGas), - }, nil -} - -var ExecutionPayloadHeaderElectraFromConsensus = ExecutionPayloadHeaderDenebFromConsensus +var ( + ExecutionPayloadElectraFromConsensus = ExecutionPayloadDenebFromConsensus + ExecutionPayloadHeaderElectraFromConsensus = ExecutionPayloadHeaderDenebFromConsensus +) diff --git a/api/server/structs/conversions_lightclient.go b/api/server/structs/conversions_lightclient.go index a0479f6e39f9..b519d3e85b07 100644 --- a/api/server/structs/conversions_lightclient.go +++ b/api/server/structs/conversions_lightclient.go @@ -124,10 +124,12 @@ func lightClientHeaderToJSON(header interfaces.LightClientHeader) (json.RawMessa var result any - switch v := header.Version(); v { - case version.Altair: + v := header.Version() + + switch { + case v == version.Altair: result = &LightClientHeader{Beacon: BeaconBlockHeaderFromConsensus(header.Beacon())} - case version.Capella: + case v == version.Capella: exInterface, err := header.Execution() if err != nil { return nil, err @@ -149,7 +151,7 @@ func lightClientHeaderToJSON(header interfaces.LightClientHeader) (json.RawMessa Execution: execution, ExecutionBranch: branchToJSON(executionBranch[:]), } - case version.Deneb: + case v == version.Deneb: exInterface, err := header.Execution() if err != nil { return nil, err @@ -171,14 +173,14 @@ func lightClientHeaderToJSON(header interfaces.LightClientHeader) (json.RawMessa Execution: execution, ExecutionBranch: branchToJSON(executionBranch[:]), } - case version.Electra: + case v >= version.Electra: exInterface, err := header.Execution() if err != nil { return nil, err } - ex, ok := exInterface.Proto().(*enginev1.ExecutionPayloadHeaderElectra) + ex, ok := exInterface.Proto().(*enginev1.ExecutionPayloadHeaderDeneb) if !ok { - return nil, fmt.Errorf("execution data is not %T", &enginev1.ExecutionPayloadHeaderElectra{}) + return nil, fmt.Errorf("execution data is not %T", &enginev1.ExecutionPayloadHeaderDeneb{}) } execution, err := ExecutionPayloadHeaderElectraFromConsensus(ex) if err != nil { diff --git a/beacon-chain/blockchain/execution_engine.go b/beacon-chain/blockchain/execution_engine.go index c95a928b2830..152626c5f16f 100644 --- a/beacon-chain/blockchain/execution_engine.go +++ b/beacon-chain/blockchain/execution_engine.go @@ -363,8 +363,10 @@ func (s *Service) getPayloadAttribute(ctx context.Context, st state.BeaconState, } var attr payloadattribute.Attributer - switch st.Version() { - case version.Deneb, version.Electra: + + v := st.Version() + switch { + case v >= version.Deneb: withdrawals, _, err := st.ExpectedWithdrawals() if err != nil { log.WithError(err).Error("Could not get expected withdrawals to get payload attribute") @@ -381,7 +383,7 @@ func (s *Service) getPayloadAttribute(ctx context.Context, st state.BeaconState, log.WithError(err).Error("Could not get payload attribute") return emptyAttri } - case version.Capella: + case v == version.Capella: withdrawals, _, err := st.ExpectedWithdrawals() if err != nil { log.WithError(err).Error("Could not get expected withdrawals to get payload attribute") @@ -397,7 +399,7 @@ func (s *Service) getPayloadAttribute(ctx context.Context, st state.BeaconState, log.WithError(err).Error("Could not get payload attribute") return emptyAttri } - case version.Bellatrix: + case v == version.Bellatrix: attr, err = payloadattribute.New(&enginev1.PayloadAttributes{ Timestamp: uint64(t.Unix()), PrevRandao: prevRando, diff --git a/beacon-chain/core/blocks/genesis.go b/beacon-chain/core/blocks/genesis.go index d3d687faa534..2b140909c1d7 100644 --- a/beacon-chain/core/blocks/genesis.go +++ b/beacon-chain/core/blocks/genesis.go @@ -198,7 +198,7 @@ func NewGenesisBlockForState(ctx context.Context, st state.BeaconState) (interfa SyncCommitteeBits: make([]byte, fieldparams.SyncCommitteeLength/8), SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength), }, - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), diff --git a/beacon-chain/core/blocks/withdrawals_test.go b/beacon-chain/core/blocks/withdrawals_test.go index 72e4bf7659a2..9a6f290d7556 100644 --- a/beacon-chain/core/blocks/withdrawals_test.go +++ b/beacon-chain/core/blocks/withdrawals_test.go @@ -1152,7 +1152,7 @@ func TestProcessWithdrawals(t *testing.T) { } st, err = state_native.InitializeFromProtoUnsafeElectra(spb) require.NoError(t, err) - p, err = consensusblocks.WrappedExecutionPayloadElectra(&enginev1.ExecutionPayloadElectra{Withdrawals: test.Args.Withdrawals}) + p, err = consensusblocks.WrappedExecutionPayloadDeneb(&enginev1.ExecutionPayloadDeneb{Withdrawals: test.Args.Withdrawals}) require.NoError(t, err) default: t.Fatalf("Add a beacon state setup for version %s", version.String(fork)) diff --git a/beacon-chain/core/electra/upgrade.go b/beacon-chain/core/electra/upgrade.go index acf6c6261bbb..47c3bf500c0a 100644 --- a/beacon-chain/core/electra/upgrade.go +++ b/beacon-chain/core/electra/upgrade.go @@ -240,7 +240,7 @@ func UpgradeToElectra(beaconState state.BeaconState) (state.BeaconState, error) InactivityScores: inactivityScores, CurrentSyncCommittee: currentSyncCommittee, NextSyncCommittee: nextSyncCommittee, - LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderElectra{ + LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: payloadHeader.ParentHash(), FeeRecipient: payloadHeader.FeeRecipient(), StateRoot: payloadHeader.StateRoot(), diff --git a/beacon-chain/core/electra/upgrade_test.go b/beacon-chain/core/electra/upgrade_test.go index c80aef5f1854..4c6ab89ef838 100644 --- a/beacon-chain/core/electra/upgrade_test.go +++ b/beacon-chain/core/electra/upgrade_test.go @@ -102,7 +102,7 @@ func TestUpgradeToElectra(t *testing.T) { header, err := mSt.LatestExecutionPayloadHeader() require.NoError(t, err) - protoHeader, ok := header.Proto().(*enginev1.ExecutionPayloadHeaderElectra) + protoHeader, ok := header.Proto().(*enginev1.ExecutionPayloadHeaderDeneb) require.Equal(t, true, ok) prevHeader, err := preForkState.LatestExecutionPayloadHeader() require.NoError(t, err) @@ -111,7 +111,7 @@ func TestUpgradeToElectra(t *testing.T) { wdRoot, err := prevHeader.WithdrawalsRoot() require.NoError(t, err) - wanted := &enginev1.ExecutionPayloadHeaderElectra{ + wanted := &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: prevHeader.ParentHash(), FeeRecipient: prevHeader.FeeRecipient(), StateRoot: prevHeader.StateRoot(), diff --git a/beacon-chain/core/light-client/lightclient_test.go b/beacon-chain/core/light-client/lightclient_test.go index 7585f597dfd1..ac687eef8abb 100644 --- a/beacon-chain/core/light-client/lightclient_test.go +++ b/beacon-chain/core/light-client/lightclient_test.go @@ -697,7 +697,7 @@ func TestLightClient_BlockToLightClientHeader(t *testing.T) { excessBlobGas, err := payload.ExcessBlobGas() require.NoError(t, err) - executionHeader := &v11.ExecutionPayloadHeaderElectra{ + executionHeader := &v11.ExecutionPayloadHeaderDeneb{ ParentHash: payload.ParentHash(), FeeRecipient: payload.FeeRecipient(), StateRoot: payload.StateRoot(), @@ -762,7 +762,7 @@ func TestLightClient_BlockToLightClientHeader(t *testing.T) { excessBlobGas, err := payload.ExcessBlobGas() require.NoError(t, err) - executionHeader := &v11.ExecutionPayloadHeaderElectra{ + executionHeader := &v11.ExecutionPayloadHeaderDeneb{ ParentHash: payload.ParentHash(), FeeRecipient: payload.FeeRecipient(), StateRoot: payload.StateRoot(), diff --git a/beacon-chain/core/time/slot_epoch_test.go b/beacon-chain/core/time/slot_epoch_test.go index 69fd32603267..48576d117780 100644 --- a/beacon-chain/core/time/slot_epoch_test.go +++ b/beacon-chain/core/time/slot_epoch_test.go @@ -1,6 +1,7 @@ package time_test import ( + "fmt" "testing" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/time" @@ -264,107 +265,64 @@ func TestAltairCompatible(t *testing.T) { } } -func TestCanUpgradeToCapella(t *testing.T) { - params.SetupTestConfigCleanup(t) - bc := params.BeaconConfig() - bc.CapellaForkEpoch = 5 - params.OverrideBeaconConfig(bc) - tests := []struct { - name string - slot primitives.Slot - want bool - }{ - { - name: "not epoch start", - slot: 1, - want: false, - }, - { - name: "not capella epoch", - slot: params.BeaconConfig().SlotsPerEpoch, - want: false, - }, - { - name: "capella epoch", - slot: primitives.Slot(params.BeaconConfig().CapellaForkEpoch) * params.BeaconConfig().SlotsPerEpoch, - want: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := time.CanUpgradeToCapella(tt.slot); got != tt.want { - t.Errorf("CanUpgradeToCapella() = %v, want %v", got, tt.want) - } - }) - } -} +func TestCanUpgradeTo(t *testing.T) { + beaconConfig := params.BeaconConfig() -func TestCanUpgradeToDeneb(t *testing.T) { - params.SetupTestConfigCleanup(t) - bc := params.BeaconConfig() - bc.DenebForkEpoch = 5 - params.OverrideBeaconConfig(bc) - tests := []struct { - name string - slot primitives.Slot - want bool + outerTestCases := []struct { + name string + forkEpoch *primitives.Epoch + upgradeFunc func(primitives.Slot) bool }{ { - name: "not epoch start", - slot: 1, - want: false, + name: "Capella", + forkEpoch: &beaconConfig.CapellaForkEpoch, + upgradeFunc: time.CanUpgradeToCapella, }, { - name: "not deneb epoch", - slot: params.BeaconConfig().SlotsPerEpoch, - want: false, + name: "Deneb", + forkEpoch: &beaconConfig.DenebForkEpoch, + upgradeFunc: time.CanUpgradeToDeneb, }, { - name: "deneb epoch", - slot: primitives.Slot(params.BeaconConfig().DenebForkEpoch) * params.BeaconConfig().SlotsPerEpoch, - want: true, + name: "Electra", + forkEpoch: &beaconConfig.ElectraForkEpoch, + upgradeFunc: time.CanUpgradeToElectra, }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := time.CanUpgradeToDeneb(tt.slot); got != tt.want { - t.Errorf("CanUpgradeToDeneb() = %v, want %v", got, tt.want) - } - }) - } -} -func TestCanUpgradeToElectra(t *testing.T) { - params.SetupTestConfigCleanup(t) - bc := params.BeaconConfig() - bc.ElectraForkEpoch = 5 - params.OverrideBeaconConfig(bc) - tests := []struct { - name string - slot primitives.Slot - want bool - }{ - { - name: "not epoch start", - slot: 1, - want: false, - }, - { - name: "not electra epoch", - slot: params.BeaconConfig().SlotsPerEpoch, - want: false, - }, - { - name: "electra epoch", - slot: primitives.Slot(params.BeaconConfig().ElectraForkEpoch) * params.BeaconConfig().SlotsPerEpoch, - want: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := time.CanUpgradeToElectra(tt.slot); got != tt.want { - t.Errorf("CanUpgradeToElectra() = %v, want %v", got, tt.want) - } - }) + for _, otc := range outerTestCases { + params.SetupTestConfigCleanup(t) + *otc.forkEpoch = 5 + params.OverrideBeaconConfig(beaconConfig) + + innerTestCases := []struct { + name string + slot primitives.Slot + want bool + }{ + { + name: "not epoch start", + slot: 1, + want: false, + }, + { + name: fmt.Sprintf("not %s epoch", otc.name), + slot: params.BeaconConfig().SlotsPerEpoch, + want: false, + }, + { + name: fmt.Sprintf("%s epoch", otc.name), + slot: primitives.Slot(*otc.forkEpoch) * params.BeaconConfig().SlotsPerEpoch, + want: true, + }, + } + + for _, itc := range innerTestCases { + t.Run(fmt.Sprintf("%s-%s", otc.name, itc.name), func(t *testing.T) { + if got := otc.upgradeFunc(itc.slot); got != itc.want { + t.Errorf("CanUpgradeTo%s() = %v, want %v", otc.name, got, itc.want) + } + }) + } } } diff --git a/beacon-chain/core/transition/transition.go b/beacon-chain/core/transition/transition.go index 0ffe051795e7..8297361b6302 100644 --- a/beacon-chain/core/transition/transition.go +++ b/beacon-chain/core/transition/transition.go @@ -298,7 +298,7 @@ func ProcessSlotsCore(ctx context.Context, span trace.Span, state state.BeaconSt func ProcessEpoch(ctx context.Context, state state.BeaconState) (state.BeaconState, error) { var err error if time.CanProcessEpoch(state) { - if state.Version() == version.Electra { + if state.Version() >= version.Electra { if err = electra.ProcessEpoch(ctx, state); err != nil { return nil, errors.Wrap(err, fmt.Sprintf("could not process %s epoch", version.String(state.Version()))) } @@ -322,9 +322,11 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta defer span.End() var err error + + slot := state.Slot() upgraded := false - if time.CanUpgradeToAltair(state.Slot()) { + if time.CanUpgradeToAltair(slot) { state, err = altair.UpgradeToAltair(ctx, state) if err != nil { tracing.AnnotateError(span, err) @@ -333,7 +335,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta upgraded = true } - if time.CanUpgradeToBellatrix(state.Slot()) { + if time.CanUpgradeToBellatrix(slot) { state, err = execution.UpgradeToBellatrix(state) if err != nil { tracing.AnnotateError(span, err) @@ -342,7 +344,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta upgraded = true } - if time.CanUpgradeToCapella(state.Slot()) { + if time.CanUpgradeToCapella(slot) { state, err = capella.UpgradeToCapella(state) if err != nil { tracing.AnnotateError(span, err) @@ -351,7 +353,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta upgraded = true } - if time.CanUpgradeToDeneb(state.Slot()) { + if time.CanUpgradeToDeneb(slot) { state, err = deneb.UpgradeToDeneb(state) if err != nil { tracing.AnnotateError(span, err) @@ -360,7 +362,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta upgraded = true } - if time.CanUpgradeToElectra(state.Slot()) { + if time.CanUpgradeToElectra(slot) { state, err = electra.UpgradeToElectra(state) if err != nil { tracing.AnnotateError(span, err) @@ -370,7 +372,7 @@ func UpgradeState(ctx context.Context, state state.BeaconState) (state.BeaconSta } if upgraded { - log.Debugf("upgraded state to %s", version.String(state.Version())) + log.WithField("version", version.String(state.Version())).Debug("Upgraded state to") } return state, nil diff --git a/beacon-chain/core/validators/slashing.go b/beacon-chain/core/validators/slashing.go index 1149ac78773a..14c72b1929c1 100644 --- a/beacon-chain/core/validators/slashing.go +++ b/beacon-chain/core/validators/slashing.go @@ -9,25 +9,35 @@ import ( // SlashingParamsPerVersion returns the slashing parameters for the given state version. func SlashingParamsPerVersion(v int) (slashingQuotient, proposerRewardQuotient, whistleblowerRewardQuotient uint64, err error) { cfg := params.BeaconConfig() - switch v { - case version.Phase0: - slashingQuotient = cfg.MinSlashingPenaltyQuotient + + if v >= version.Electra { + slashingQuotient = cfg.MinSlashingPenaltyQuotientElectra + proposerRewardQuotient = cfg.ProposerRewardQuotient + whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotientElectra + return + } + + if v >= version.Bellatrix { + slashingQuotient = cfg.MinSlashingPenaltyQuotientBellatrix proposerRewardQuotient = cfg.ProposerRewardQuotient whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotient - case version.Altair: + return + } + + if v >= version.Altair { slashingQuotient = cfg.MinSlashingPenaltyQuotientAltair proposerRewardQuotient = cfg.ProposerRewardQuotient whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotient - case version.Bellatrix, version.Capella, version.Deneb: - slashingQuotient = cfg.MinSlashingPenaltyQuotientBellatrix + return + } + + if v >= version.Phase0 { + slashingQuotient = cfg.MinSlashingPenaltyQuotient proposerRewardQuotient = cfg.ProposerRewardQuotient whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotient - case version.Electra: - slashingQuotient = cfg.MinSlashingPenaltyQuotientElectra - proposerRewardQuotient = cfg.ProposerRewardQuotient - whistleblowerRewardQuotient = cfg.WhistleBlowerRewardQuotientElectra - default: - err = errors.New("unknown state version") + return } + + err = errors.New("unknown state version") return } diff --git a/beacon-chain/db/kv/lightclient_test.go b/beacon-chain/db/kv/lightclient_test.go index ccfde1be0e08..6254f8e26054 100644 --- a/beacon-chain/db/kv/lightclient_test.go +++ b/beacon-chain/db/kv/lightclient_test.go @@ -122,7 +122,7 @@ func createUpdate(t *testing.T, v int) (interfaces.LightClientUpdate, error) { StateRoot: sampleRoot, BodyRoot: sampleRoot, }, - Execution: &enginev1.ExecutionPayloadHeaderElectra{ + Execution: &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), diff --git a/beacon-chain/db/kv/state_test.go b/beacon-chain/db/kv/state_test.go index 1a5848e24b64..6f2c279b152c 100644 --- a/beacon-chain/db/kv/state_test.go +++ b/beacon-chain/db/kv/state_test.go @@ -139,7 +139,7 @@ func TestState_CanSaveRetrieve(t *testing.T) { st, err := util.NewBeaconStateElectra() require.NoError(t, err) require.NoError(t, st.SetSlot(100)) - p, err := blocks.WrappedExecutionPayloadHeaderElectra(&enginev1.ExecutionPayloadHeaderElectra{ + p, err := blocks.WrappedExecutionPayloadHeaderDeneb(&enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), diff --git a/beacon-chain/execution/engine_client.go b/beacon-chain/execution/engine_client.go index dc0a3d8fafec..0bbd6bd92f47 100644 --- a/beacon-chain/execution/engine_client.go +++ b/beacon-chain/execution/engine_client.go @@ -631,43 +631,7 @@ func fullPayloadFromPayloadBody( return nil, errors.New("execution block and header cannot be nil") } - switch bVersion { - case version.Bellatrix: - return blocks.WrappedExecutionPayload(&pb.ExecutionPayload{ - ParentHash: header.ParentHash(), - FeeRecipient: header.FeeRecipient(), - StateRoot: header.StateRoot(), - ReceiptsRoot: header.ReceiptsRoot(), - LogsBloom: header.LogsBloom(), - PrevRandao: header.PrevRandao(), - BlockNumber: header.BlockNumber(), - GasLimit: header.GasLimit(), - GasUsed: header.GasUsed(), - Timestamp: header.Timestamp(), - ExtraData: header.ExtraData(), - BaseFeePerGas: header.BaseFeePerGas(), - BlockHash: header.BlockHash(), - Transactions: pb.RecastHexutilByteSlice(body.Transactions), - }) - case version.Capella: - return blocks.WrappedExecutionPayloadCapella(&pb.ExecutionPayloadCapella{ - ParentHash: header.ParentHash(), - FeeRecipient: header.FeeRecipient(), - StateRoot: header.StateRoot(), - ReceiptsRoot: header.ReceiptsRoot(), - LogsBloom: header.LogsBloom(), - PrevRandao: header.PrevRandao(), - BlockNumber: header.BlockNumber(), - GasLimit: header.GasLimit(), - GasUsed: header.GasUsed(), - Timestamp: header.Timestamp(), - ExtraData: header.ExtraData(), - BaseFeePerGas: header.BaseFeePerGas(), - BlockHash: header.BlockHash(), - Transactions: pb.RecastHexutilByteSlice(body.Transactions), - Withdrawals: body.Withdrawals, - }) // We can't get the block value and don't care about the block value for this instance - case version.Deneb, version.Electra: + if bVersion >= version.Deneb { ebg, err := header.ExcessBlobGas() if err != nil { return nil, errors.Wrap(err, "unable to extract ExcessBlobGas attribute from execution payload header") @@ -696,9 +660,48 @@ func fullPayloadFromPayloadBody( ExcessBlobGas: ebg, BlobGasUsed: bgu, }) // We can't get the block value and don't care about the block value for this instance - default: - return nil, fmt.Errorf("unknown execution block version for payload %d", bVersion) } + + if bVersion >= version.Capella { + return blocks.WrappedExecutionPayloadCapella(&pb.ExecutionPayloadCapella{ + ParentHash: header.ParentHash(), + FeeRecipient: header.FeeRecipient(), + StateRoot: header.StateRoot(), + ReceiptsRoot: header.ReceiptsRoot(), + LogsBloom: header.LogsBloom(), + PrevRandao: header.PrevRandao(), + BlockNumber: header.BlockNumber(), + GasLimit: header.GasLimit(), + GasUsed: header.GasUsed(), + Timestamp: header.Timestamp(), + ExtraData: header.ExtraData(), + BaseFeePerGas: header.BaseFeePerGas(), + BlockHash: header.BlockHash(), + Transactions: pb.RecastHexutilByteSlice(body.Transactions), + Withdrawals: body.Withdrawals, + }) // We can't get the block value and don't care about the block value for this instance + } + + if bVersion >= version.Bellatrix { + return blocks.WrappedExecutionPayload(&pb.ExecutionPayload{ + ParentHash: header.ParentHash(), + FeeRecipient: header.FeeRecipient(), + StateRoot: header.StateRoot(), + ReceiptsRoot: header.ReceiptsRoot(), + LogsBloom: header.LogsBloom(), + PrevRandao: header.PrevRandao(), + BlockNumber: header.BlockNumber(), + GasLimit: header.GasLimit(), + GasUsed: header.GasUsed(), + Timestamp: header.Timestamp(), + ExtraData: header.ExtraData(), + BaseFeePerGas: header.BaseFeePerGas(), + BlockHash: header.BlockHash(), + Transactions: pb.RecastHexutilByteSlice(body.Transactions), + }) + } + + return nil, fmt.Errorf("unknown execution block version for payload %d", bVersion) } // Handles errors received from the RPC server according to the specification. @@ -790,9 +793,8 @@ func tDStringToUint256(td string) (*uint256.Int, error) { } func EmptyExecutionPayload(v int) (proto.Message, error) { - switch v { - case version.Bellatrix: - return &pb.ExecutionPayload{ + if v >= version.Deneb { + return &pb.ExecutionPayloadDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), @@ -803,8 +805,11 @@ func EmptyExecutionPayload(v int) (proto.Message, error) { BaseFeePerGas: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, fieldparams.RootLength), Transactions: make([][]byte, 0), + Withdrawals: make([]*pb.Withdrawal, 0), }, nil - case version.Capella: + } + + if v >= version.Capella { return &pb.ExecutionPayloadCapella{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), @@ -818,8 +823,10 @@ func EmptyExecutionPayload(v int) (proto.Message, error) { Transactions: make([][]byte, 0), Withdrawals: make([]*pb.Withdrawal, 0), }, nil - case version.Deneb, version.Electra: - return &pb.ExecutionPayloadDeneb{ + } + + if v >= version.Bellatrix { + return &pb.ExecutionPayload{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), @@ -830,29 +837,15 @@ func EmptyExecutionPayload(v int) (proto.Message, error) { BaseFeePerGas: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, fieldparams.RootLength), Transactions: make([][]byte, 0), - Withdrawals: make([]*pb.Withdrawal, 0), }, nil - default: - return nil, errors.Wrapf(ErrUnsupportedVersion, "version=%s", version.String(v)) } + + return nil, errors.Wrapf(ErrUnsupportedVersion, "version=%s", version.String(v)) } func EmptyExecutionPayloadHeader(v int) (proto.Message, error) { - switch v { - case version.Bellatrix: - return &pb.ExecutionPayloadHeader{ - ParentHash: make([]byte, fieldparams.RootLength), - FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), - StateRoot: make([]byte, fieldparams.RootLength), - ReceiptsRoot: make([]byte, fieldparams.RootLength), - LogsBloom: make([]byte, fieldparams.LogsBloomLength), - PrevRandao: make([]byte, fieldparams.RootLength), - ExtraData: make([]byte, 0), - BaseFeePerGas: make([]byte, fieldparams.RootLength), - BlockHash: make([]byte, fieldparams.RootLength), - }, nil - case version.Capella: - return &pb.ExecutionPayloadHeaderCapella{ + if v >= version.Deneb { + return &pb.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), @@ -865,8 +858,10 @@ func EmptyExecutionPayloadHeader(v int) (proto.Message, error) { TransactionsRoot: make([]byte, fieldparams.RootLength), WithdrawalsRoot: make([]byte, fieldparams.RootLength), }, nil - case version.Deneb, version.Electra: - return &pb.ExecutionPayloadHeaderDeneb{ + } + + if v >= version.Capella { + return &pb.ExecutionPayloadHeaderCapella{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), @@ -879,9 +874,23 @@ func EmptyExecutionPayloadHeader(v int) (proto.Message, error) { TransactionsRoot: make([]byte, fieldparams.RootLength), WithdrawalsRoot: make([]byte, fieldparams.RootLength), }, nil - default: - return nil, errors.Wrapf(ErrUnsupportedVersion, "version=%s", version.String(v)) } + + if v >= version.Bellatrix { + return &pb.ExecutionPayloadHeader{ + ParentHash: make([]byte, fieldparams.RootLength), + FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), + StateRoot: make([]byte, fieldparams.RootLength), + ReceiptsRoot: make([]byte, fieldparams.RootLength), + LogsBloom: make([]byte, fieldparams.LogsBloomLength), + PrevRandao: make([]byte, fieldparams.RootLength), + ExtraData: make([]byte, 0), + BaseFeePerGas: make([]byte, fieldparams.RootLength), + BlockHash: make([]byte, fieldparams.RootLength), + }, nil + } + + return nil, errors.Wrapf(ErrUnsupportedVersion, "version=%s", version.String(v)) } func toBlockNumArg(number *big.Int) string { diff --git a/beacon-chain/operations/attestations/kv/aggregated.go b/beacon-chain/operations/attestations/kv/aggregated.go index cc1319eb4f67..32d329dd1f4f 100644 --- a/beacon-chain/operations/attestations/kv/aggregated.go +++ b/beacon-chain/operations/attestations/kv/aggregated.go @@ -236,7 +236,7 @@ func (c *AttCaches) AggregatedAttestationsBySlotIndexElectra( c.aggregatedAttLock.RLock() defer c.aggregatedAttLock.RUnlock() for _, as := range c.aggregatedAtt { - if as[0].Version() == version.Electra && slot == as[0].GetData().Slot && as[0].CommitteeBitsVal().BitAt(uint64(committeeIndex)) { + if as[0].Version() >= version.Electra && slot == as[0].GetData().Slot && as[0].CommitteeBitsVal().BitAt(uint64(committeeIndex)) { for _, a := range as { att, ok := a.(*ethpb.AttestationElectra) // This will never fail in practice because we asserted the version diff --git a/beacon-chain/operations/attestations/kv/unaggregated.go b/beacon-chain/operations/attestations/kv/unaggregated.go index 6bf6cb888c75..bbaabbd306c8 100644 --- a/beacon-chain/operations/attestations/kv/unaggregated.go +++ b/beacon-chain/operations/attestations/kv/unaggregated.go @@ -115,7 +115,7 @@ func (c *AttCaches) UnaggregatedAttestationsBySlotIndexElectra( unAggregatedAtts := c.unAggregatedAtt for _, a := range unAggregatedAtts { - if a.Version() == version.Electra && slot == a.GetData().Slot && a.CommitteeBitsVal().BitAt(uint64(committeeIndex)) { + if a.Version() >= version.Electra && slot == a.GetData().Slot && a.CommitteeBitsVal().BitAt(uint64(committeeIndex)) { att, ok := a.(*ethpb.AttestationElectra) // This will never fail in practice because we asserted the version if ok { diff --git a/beacon-chain/p2p/types/object_mapping.go b/beacon-chain/p2p/types/object_mapping.go index e8646b34ee7a..21c9a4c94636 100644 --- a/beacon-chain/p2p/types/object_mapping.go +++ b/beacon-chain/p2p/types/object_mapping.go @@ -67,7 +67,7 @@ func InitializeDataMaps() { }, bytesutil.ToBytes4(params.BeaconConfig().ElectraForkVersion): func() (interfaces.ReadOnlySignedBeaconBlock, error) { return blocks.NewSignedBeaconBlock( - ðpb.SignedBeaconBlockElectra{Block: ðpb.BeaconBlockElectra{Body: ðpb.BeaconBlockBodyElectra{ExecutionPayload: &enginev1.ExecutionPayloadElectra{}}}}, + ðpb.SignedBeaconBlockElectra{Block: ðpb.BeaconBlockElectra{Body: ðpb.BeaconBlockBodyElectra{ExecutionPayload: &enginev1.ExecutionPayloadDeneb{}}}}, ) }, } diff --git a/beacon-chain/rpc/eth/light-client/handlers_test.go b/beacon-chain/rpc/eth/light-client/handlers_test.go index d2aaa2209890..87943b87d2e7 100644 --- a/beacon-chain/rpc/eth/light-client/handlers_test.go +++ b/beacon-chain/rpc/eth/light-client/handlers_test.go @@ -1821,7 +1821,7 @@ func createUpdate(t *testing.T, v int) (interfaces.LightClientUpdate, error) { StateRoot: sampleRoot, BodyRoot: sampleRoot, }, - Execution: &enginev1.ExecutionPayloadHeaderElectra{ + Execution: &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/construct_generic_block.go b/beacon-chain/rpc/prysm/v1alpha1/validator/construct_generic_block.go index a4510e69eead..7576c9f6a297 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/construct_generic_block.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/construct_generic_block.go @@ -26,34 +26,44 @@ func (vs *Server) constructGenericBeaconBlock(sBlk interfaces.SignedBeaconBlock, bidStr := primitives.WeiToBigInt(winningBid).String() switch sBlk.Version() { - case version.Electra: - return vs.constructElectraBlock(blockProto, isBlinded, bidStr, blobsBundle), nil - case version.Deneb: - return vs.constructDenebBlock(blockProto, isBlinded, bidStr, blobsBundle), nil - case version.Capella: - return vs.constructCapellaBlock(blockProto, isBlinded, bidStr), nil - case version.Bellatrix: - return vs.constructBellatrixBlock(blockProto, isBlinded, bidStr), nil - case version.Altair: - return vs.constructAltairBlock(blockProto), nil case version.Phase0: return vs.constructPhase0Block(blockProto), nil + case version.Altair: + return vs.constructAltairBlock(blockProto), nil + case version.Bellatrix: + return vs.constructBellatrixBlock(blockProto, isBlinded, bidStr), nil + case version.Capella: + return vs.constructCapellaBlock(blockProto, isBlinded, bidStr), nil + case version.Deneb: + return vs.constructDenebBlock(blockProto, isBlinded, bidStr, blobsBundle), nil + case version.Electra: + return vs.constructElectraBlock(blockProto, isBlinded, bidStr, blobsBundle), nil default: return nil, fmt.Errorf("unknown block version: %d", sBlk.Version()) } } // Helper functions for constructing blocks for each version -func (vs *Server) constructElectraBlock(blockProto proto.Message, isBlinded bool, payloadValue string, bundle *enginev1.BlobsBundle) *ethpb.GenericBeaconBlock { +func (vs *Server) constructPhase0Block(pb proto.Message) *ethpb.GenericBeaconBlock { + return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Phase0{Phase0: pb.(*ethpb.BeaconBlock)}} +} + +func (vs *Server) constructAltairBlock(pb proto.Message) *ethpb.GenericBeaconBlock { + return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Altair{Altair: pb.(*ethpb.BeaconBlockAltair)}} +} + +func (vs *Server) constructBellatrixBlock(pb proto.Message, isBlinded bool, payloadValue string) *ethpb.GenericBeaconBlock { if isBlinded { - return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_BlindedElectra{BlindedElectra: blockProto.(*ethpb.BlindedBeaconBlockElectra)}, IsBlinded: true, PayloadValue: payloadValue} + return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_BlindedBellatrix{BlindedBellatrix: pb.(*ethpb.BlindedBeaconBlockBellatrix)}, IsBlinded: true, PayloadValue: payloadValue} } - electraContents := ðpb.BeaconBlockContentsElectra{Block: blockProto.(*ethpb.BeaconBlockElectra)} - if bundle != nil { - electraContents.KzgProofs = bundle.Proofs - electraContents.Blobs = bundle.Blobs + return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Bellatrix{Bellatrix: pb.(*ethpb.BeaconBlockBellatrix)}, IsBlinded: false, PayloadValue: payloadValue} +} + +func (vs *Server) constructCapellaBlock(pb proto.Message, isBlinded bool, payloadValue string) *ethpb.GenericBeaconBlock { + if isBlinded { + return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_BlindedCapella{BlindedCapella: pb.(*ethpb.BlindedBeaconBlockCapella)}, IsBlinded: true, PayloadValue: payloadValue} } - return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Electra{Electra: electraContents}, IsBlinded: false, PayloadValue: payloadValue} + return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Capella{Capella: pb.(*ethpb.BeaconBlockCapella)}, IsBlinded: false, PayloadValue: payloadValue} } func (vs *Server) constructDenebBlock(blockProto proto.Message, isBlinded bool, payloadValue string, bundle *enginev1.BlobsBundle) *ethpb.GenericBeaconBlock { @@ -68,24 +78,14 @@ func (vs *Server) constructDenebBlock(blockProto proto.Message, isBlinded bool, return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Deneb{Deneb: denebContents}, IsBlinded: false, PayloadValue: payloadValue} } -func (vs *Server) constructCapellaBlock(pb proto.Message, isBlinded bool, payloadValue string) *ethpb.GenericBeaconBlock { +func (vs *Server) constructElectraBlock(blockProto proto.Message, isBlinded bool, payloadValue string, bundle *enginev1.BlobsBundle) *ethpb.GenericBeaconBlock { if isBlinded { - return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_BlindedCapella{BlindedCapella: pb.(*ethpb.BlindedBeaconBlockCapella)}, IsBlinded: true, PayloadValue: payloadValue} + return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_BlindedElectra{BlindedElectra: blockProto.(*ethpb.BlindedBeaconBlockElectra)}, IsBlinded: true, PayloadValue: payloadValue} } - return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Capella{Capella: pb.(*ethpb.BeaconBlockCapella)}, IsBlinded: false, PayloadValue: payloadValue} -} - -func (vs *Server) constructBellatrixBlock(pb proto.Message, isBlinded bool, payloadValue string) *ethpb.GenericBeaconBlock { - if isBlinded { - return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_BlindedBellatrix{BlindedBellatrix: pb.(*ethpb.BlindedBeaconBlockBellatrix)}, IsBlinded: true, PayloadValue: payloadValue} + electraContents := ðpb.BeaconBlockContentsElectra{Block: blockProto.(*ethpb.BeaconBlockElectra)} + if bundle != nil { + electraContents.KzgProofs = bundle.Proofs + electraContents.Blobs = bundle.Blobs } - return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Bellatrix{Bellatrix: pb.(*ethpb.BeaconBlockBellatrix)}, IsBlinded: false, PayloadValue: payloadValue} -} - -func (vs *Server) constructAltairBlock(pb proto.Message) *ethpb.GenericBeaconBlock { - return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Altair{Altair: pb.(*ethpb.BeaconBlockAltair)}} -} - -func (vs *Server) constructPhase0Block(pb proto.Message) *ethpb.GenericBeaconBlock { - return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Phase0{Phase0: pb.(*ethpb.BeaconBlock)}} + return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Electra{Electra: electraContents}, IsBlinded: false, PayloadValue: payloadValue} } diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go index 4ce0ff683467..82f31973ba3e 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go @@ -617,7 +617,7 @@ func TestServer_GetBeaconBlock_Electra(t *testing.T) { Graffiti: genesis.Block.Body.Graffiti, Eth1Data: genesis.Block.Body.Eth1Data, SyncAggregate: ðpb.SyncAggregate{SyncCommitteeBits: scBits[:], SyncCommitteeSignature: make([]byte, 96)}, - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: make([]byte, fieldparams.RootLength), @@ -646,7 +646,7 @@ func TestServer_GetBeaconBlock_Electra(t *testing.T) { require.NoError(t, err) timeStamp, err := slots.ToTime(beaconState.GenesisTime(), electraSlot+1) require.NoError(t, err) - payload := &enginev1.ExecutionPayloadElectra{ + payload := &enginev1.ExecutionPayloadDeneb{ Timestamp: uint64(timeStamp.Unix()), ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), diff --git a/beacon-chain/state/state-native/getters_payload_header.go b/beacon-chain/state/state-native/getters_payload_header.go index a3b156b3ead8..d269058ade8a 100644 --- a/beacon-chain/state/state-native/getters_payload_header.go +++ b/beacon-chain/state/state-native/getters_payload_header.go @@ -17,14 +17,17 @@ func (b *BeaconState) LatestExecutionPayloadHeader() (interfaces.ExecutionData, b.lock.RLock() defer b.lock.RUnlock() - switch b.version { - case version.Bellatrix: - return blocks.WrappedExecutionPayloadHeader(b.latestExecutionPayloadHeader.Copy()) - case version.Capella: - return blocks.WrappedExecutionPayloadHeaderCapella(b.latestExecutionPayloadHeaderCapella.Copy()) - case version.Deneb, version.Electra: + if b.version >= version.Deneb { return blocks.WrappedExecutionPayloadHeaderDeneb(b.latestExecutionPayloadHeaderDeneb.Copy()) - default: - return nil, fmt.Errorf("unsupported version (%s) for latest execution payload header", version.String(b.version)) } + + if b.version >= version.Capella { + return blocks.WrappedExecutionPayloadHeaderCapella(b.latestExecutionPayloadHeaderCapella.Copy()) + } + + if b.version >= version.Bellatrix { + return blocks.WrappedExecutionPayloadHeader(b.latestExecutionPayloadHeader.Copy()) + } + + return nil, fmt.Errorf("unsupported version (%s) for latest execution payload header", version.String(b.version)) } diff --git a/beacon-chain/state/state-native/setters_eth1_test.go b/beacon-chain/state/state-native/setters_eth1_test.go index a42a93c14eda..ccfa745f6b5b 100644 --- a/beacon-chain/state/state-native/setters_eth1_test.go +++ b/beacon-chain/state/state-native/setters_eth1_test.go @@ -5,7 +5,6 @@ import ( state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v5/config/params" - eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/require" ) @@ -32,7 +31,7 @@ func BenchmarkAppendEth1DataVotes(b *testing.B) { ref := st.Copy() for i := 0; i < b.N; i++ { - err := ref.AppendEth1DataVotes(ð.Eth1Data{DepositCount: uint64(i)}) + err := ref.AppendEth1DataVotes(ðpb.Eth1Data{DepositCount: uint64(i)}) require.NoError(b, err) ref = st.Copy() } diff --git a/beacon-chain/state/state-native/setters_payload_header_test.go b/beacon-chain/state/state-native/setters_payload_header_test.go index b9f806591815..74dda536a19c 100644 --- a/beacon-chain/state/state-native/setters_payload_header_test.go +++ b/beacon-chain/state/state-native/setters_payload_header_test.go @@ -35,7 +35,7 @@ func TestSetLatestExecutionPayloadHeader(t *testing.T) { }(), func() interfaces.ExecutionData { e := util.NewBeaconBlockElectra().Block.Body.ExecutionPayload - ee, err := blocks.WrappedExecutionPayloadElectra(e) + ee, err := blocks.WrappedExecutionPayloadDeneb(e) require.NoError(t, err) return ee }(), diff --git a/beacon-chain/state/state-native/spec_parameters.go b/beacon-chain/state/state-native/spec_parameters.go index 7c955e92c1d2..36c8fe3c2cda 100644 --- a/beacon-chain/state/state-native/spec_parameters.go +++ b/beacon-chain/state/state-native/spec_parameters.go @@ -6,25 +6,33 @@ import ( ) func (b *BeaconState) ProportionalSlashingMultiplier() (uint64, error) { - switch b.version { - case version.Bellatrix, version.Capella, version.Deneb, version.Electra: + if b.version >= version.Bellatrix { return params.BeaconConfig().ProportionalSlashingMultiplierBellatrix, nil - case version.Altair: + } + + if b.version == version.Altair { return params.BeaconConfig().ProportionalSlashingMultiplierAltair, nil - case version.Phase0: + } + + if b.version == version.Phase0 { return params.BeaconConfig().ProportionalSlashingMultiplier, nil } + return 0, errNotSupported("ProportionalSlashingMultiplier", b.version) } func (b *BeaconState) InactivityPenaltyQuotient() (uint64, error) { - switch b.version { - case version.Bellatrix, version.Capella, version.Deneb, version.Electra: + if b.version >= version.Bellatrix { return params.BeaconConfig().InactivityPenaltyQuotientBellatrix, nil - case version.Altair: + } + + if b.version == version.Altair { return params.BeaconConfig().InactivityPenaltyQuotientAltair, nil - case version.Phase0: + } + + if b.version == version.Phase0 { return params.BeaconConfig().InactivityPenaltyQuotient, nil } + return 0, errNotSupported("InactivityPenaltyQuotient", b.version) } diff --git a/beacon-chain/state/state-native/state_trie.go b/beacon-chain/state/state-native/state_trie.go index 66f2fbf89d88..19809c934b86 100644 --- a/beacon-chain/state/state-native/state_trie.go +++ b/beacon-chain/state/state-native/state_trie.go @@ -25,90 +25,88 @@ import ( "google.golang.org/protobuf/proto" ) -var phase0Fields = []types.FieldIndex{ - types.GenesisTime, - types.GenesisValidatorsRoot, - types.Slot, - types.Fork, - types.LatestBlockHeader, - types.BlockRoots, - types.StateRoots, - types.HistoricalRoots, - types.Eth1Data, - types.Eth1DataVotes, - types.Eth1DepositIndex, - types.Validators, - types.Balances, - types.RandaoMixes, - types.Slashings, - types.PreviousEpochAttestations, - types.CurrentEpochAttestations, - types.JustificationBits, - types.PreviousJustifiedCheckpoint, - types.CurrentJustifiedCheckpoint, - types.FinalizedCheckpoint, -} - -var altairFields = []types.FieldIndex{ - types.GenesisTime, - types.GenesisValidatorsRoot, - types.Slot, - types.Fork, - types.LatestBlockHeader, - types.BlockRoots, - types.StateRoots, - types.HistoricalRoots, - types.Eth1Data, - types.Eth1DataVotes, - types.Eth1DepositIndex, - types.Validators, - types.Balances, - types.RandaoMixes, - types.Slashings, - types.PreviousEpochParticipationBits, - types.CurrentEpochParticipationBits, - types.JustificationBits, - types.PreviousJustifiedCheckpoint, - types.CurrentJustifiedCheckpoint, - types.FinalizedCheckpoint, - types.InactivityScores, - types.CurrentSyncCommittee, - types.NextSyncCommittee, -} - -var bellatrixFields = append(altairFields, types.LatestExecutionPayloadHeader) - -var capellaFields = append( - altairFields, - types.LatestExecutionPayloadHeaderCapella, - types.NextWithdrawalIndex, - types.NextWithdrawalValidatorIndex, - types.HistoricalSummaries, -) - -var denebFields = append( - altairFields, - types.LatestExecutionPayloadHeaderDeneb, - types.NextWithdrawalIndex, - types.NextWithdrawalValidatorIndex, - types.HistoricalSummaries, -) - -var electraFields = append( - altairFields, - types.LatestExecutionPayloadHeaderDeneb, - types.NextWithdrawalIndex, - types.NextWithdrawalValidatorIndex, - types.HistoricalSummaries, - types.DepositRequestsStartIndex, - types.DepositBalanceToConsume, - types.ExitBalanceToConsume, - types.EarliestExitEpoch, - types.ConsolidationBalanceToConsume, - types.EarliestConsolidationEpoch, - types.PendingDeposits, - types.PendingPartialWithdrawals, - types.PendingConsolidations, +var ( + phase0Fields = []types.FieldIndex{ + types.GenesisTime, + types.GenesisValidatorsRoot, + types.Slot, + types.Fork, + types.LatestBlockHeader, + types.BlockRoots, + types.StateRoots, + types.HistoricalRoots, + types.Eth1Data, + types.Eth1DataVotes, + types.Eth1DepositIndex, + types.Validators, + types.Balances, + types.RandaoMixes, + types.Slashings, + types.PreviousEpochAttestations, + types.CurrentEpochAttestations, + types.JustificationBits, + types.PreviousJustifiedCheckpoint, + types.CurrentJustifiedCheckpoint, + types.FinalizedCheckpoint, + } + + altairFields = []types.FieldIndex{ + types.GenesisTime, + types.GenesisValidatorsRoot, + types.Slot, + types.Fork, + types.LatestBlockHeader, + types.BlockRoots, + types.StateRoots, + types.HistoricalRoots, + types.Eth1Data, + types.Eth1DataVotes, + types.Eth1DepositIndex, + types.Validators, + types.Balances, + types.RandaoMixes, + types.Slashings, + types.PreviousEpochParticipationBits, + types.CurrentEpochParticipationBits, + types.JustificationBits, + types.PreviousJustifiedCheckpoint, + types.CurrentJustifiedCheckpoint, + types.FinalizedCheckpoint, + types.InactivityScores, + types.CurrentSyncCommittee, + types.NextSyncCommittee, + } + + bellatrixFields = append(altairFields, types.LatestExecutionPayloadHeader) + + capellaFields = append( + altairFields, + types.LatestExecutionPayloadHeaderCapella, + types.NextWithdrawalIndex, + types.NextWithdrawalValidatorIndex, + types.HistoricalSummaries, + ) + + denebFields = append( + altairFields, + types.LatestExecutionPayloadHeaderDeneb, + types.NextWithdrawalIndex, + types.NextWithdrawalValidatorIndex, + types.HistoricalSummaries, + ) + + electraFields = append( + denebFields, + types.DepositRequestsStartIndex, + types.DepositBalanceToConsume, + types.ExitBalanceToConsume, + types.EarliestExitEpoch, + types.ConsolidationBalanceToConsume, + types.EarliestConsolidationEpoch, + types.PendingDeposits, + types.PendingPartialWithdrawals, + types.PendingConsolidations, + ) ) const ( diff --git a/consensus-types/blocks/execution.go b/consensus-types/blocks/execution.go index 0c75f1d43128..919deb0335d5 100644 --- a/consensus-types/blocks/execution.go +++ b/consensus-types/blocks/execution.go @@ -864,8 +864,6 @@ func WrappedExecutionPayloadHeaderDeneb(p *enginev1.ExecutionPayloadHeaderDeneb) return w, nil } -var WrappedExecutionPayloadHeaderElectra = WrappedExecutionPayloadHeaderDeneb - // IsNil checks if the underlying data is nil. func (e executionPayloadHeaderDeneb) IsNil() bool { return e.p == nil @@ -1024,8 +1022,6 @@ func WrappedExecutionPayloadDeneb(p *enginev1.ExecutionPayloadDeneb) (interfaces return w, nil } -var WrappedExecutionPayloadElectra = WrappedExecutionPayloadDeneb - // IsNil checks if the underlying data is nil. func (e executionPayloadDeneb) IsNil() bool { return e.p == nil diff --git a/consensus-types/blocks/factory.go b/consensus-types/blocks/factory.go index 37aa22a410dc..0304365d93f4 100644 --- a/consensus-types/blocks/factory.go +++ b/consensus-types/blocks/factory.go @@ -472,7 +472,7 @@ func BuildSignedBeaconBlockFromExecutionPayload(blk interfaces.ReadOnlySignedBea Signature: sig[:], } case version.Electra: - p, ok := payload.(*enginev1.ExecutionPayloadElectra) + p, ok := payload.(*enginev1.ExecutionPayloadDeneb) if !ok { return nil, errors.New("payload not of Electra type") } diff --git a/consensus-types/blocks/getters.go b/consensus-types/blocks/getters.go index 4aef3478baef..b37f333990f6 100644 --- a/consensus-types/blocks/getters.go +++ b/consensus-types/blocks/getters.go @@ -153,7 +153,7 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.ReadOnlySignedBeaconBlock, e } if b.version >= version.Electra { - p, ok := payload.Proto().(*enginev1.ExecutionPayloadElectra) + p, ok := payload.Proto().(*enginev1.ExecutionPayloadDeneb) if !ok { return nil, fmt.Errorf("%T is not an execution payload header of Deneb version", p) } @@ -1103,14 +1103,15 @@ func (b *BeaconBlockBody) BLSToExecutionChanges() ([]*eth.SignedBLSToExecutionCh // BlobKzgCommitments returns the blob kzg commitments in the block. func (b *BeaconBlockBody) BlobKzgCommitments() ([][]byte, error) { - switch b.version { - case version.Phase0, version.Altair, version.Bellatrix, version.Capella: - return nil, consensus_types.ErrNotSupported("BlobKzgCommitments", b.version) - case version.Deneb, version.Electra: + if b.version >= version.Deneb { return b.blobKzgCommitments, nil - default: - return nil, errIncorrectBlockVersion } + + if b.version >= version.Phase0 { + return nil, consensus_types.ErrNotSupported("BlobKzgCommitments", b.version) + } + + return nil, errIncorrectBlockVersion } // ExecutionRequests returns the execution requests diff --git a/consensus-types/blocks/getters_test.go b/consensus-types/blocks/getters_test.go index 6be8940e7b6f..29cc86644d88 100644 --- a/consensus-types/blocks/getters_test.go +++ b/consensus-types/blocks/getters_test.go @@ -613,7 +613,7 @@ func hydrateBeaconBlockBodyElectra() *eth.BeaconBlockBodyElectra { SyncCommitteeBits: make([]byte, fieldparams.SyncAggregateSyncCommitteeBytesLength), SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength), }, - ExecutionPayload: &pb.ExecutionPayloadElectra{ + ExecutionPayload: &pb.ExecutionPayloadDeneb{ ParentHash: make([]byte, fieldparams.RootLength), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, fieldparams.RootLength), diff --git a/consensus-types/blocks/proto.go b/consensus-types/blocks/proto.go index 1cb29d535e2d..d3191448978a 100644 --- a/consensus-types/blocks/proto.go +++ b/consensus-types/blocks/proto.go @@ -510,10 +510,10 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { }, nil case version.Electra: if b.IsBlinded() { - var ph *enginev1.ExecutionPayloadHeaderElectra + var ph *enginev1.ExecutionPayloadHeaderDeneb var ok bool if b.executionPayloadHeader != nil { - ph, ok = b.executionPayloadHeader.Proto().(*enginev1.ExecutionPayloadHeaderElectra) + ph, ok = b.executionPayloadHeader.Proto().(*enginev1.ExecutionPayloadHeaderDeneb) if !ok { return nil, errPayloadHeaderWrongType } @@ -534,10 +534,10 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { ExecutionRequests: b.executionRequests, }, nil } - var p *enginev1.ExecutionPayloadElectra + var p *enginev1.ExecutionPayloadDeneb var ok bool if b.executionPayload != nil { - p, ok = b.executionPayload.Proto().(*enginev1.ExecutionPayloadElectra) + p, ok = b.executionPayload.Proto().(*enginev1.ExecutionPayloadDeneb) if !ok { return nil, errPayloadWrongType } @@ -563,6 +563,10 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { } } +// ---------------------------------------------------------------------------- +// Phase 0 +// ---------------------------------------------------------------------------- + func initSignedBlockFromProtoPhase0(pb *eth.SignedBeaconBlock) (*SignedBeaconBlock, error) { if pb == nil { return nil, errNilBlock @@ -580,85 +584,121 @@ func initSignedBlockFromProtoPhase0(pb *eth.SignedBeaconBlock) (*SignedBeaconBlo return b, nil } -func initSignedBlockFromProtoAltair(pb *eth.SignedBeaconBlockAltair) (*SignedBeaconBlock, error) { +func initBlockFromProtoPhase0(pb *eth.BeaconBlock) (*BeaconBlock, error) { if pb == nil { return nil, errNilBlock } - block, err := initBlockFromProtoAltair(pb.Block) + body, err := initBlockBodyFromProtoPhase0(pb.Body) if err != nil { return nil, err } - b := &SignedBeaconBlock{ - version: version.Altair, - block: block, - signature: bytesutil.ToBytes96(pb.Signature), + b := &BeaconBlock{ + version: version.Phase0, + slot: pb.Slot, + proposerIndex: pb.ProposerIndex, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), + body: body, } return b, nil } -func initSignedBlockFromProtoBellatrix(pb *eth.SignedBeaconBlockBellatrix) (*SignedBeaconBlock, error) { +func initBlockBodyFromProtoPhase0(pb *eth.BeaconBlockBody) (*BeaconBlockBody, error) { if pb == nil { - return nil, errNilBlock + return nil, errNilBlockBody } - block, err := initBlockFromProtoBellatrix(pb.Block) - if err != nil { - return nil, err - } - b := &SignedBeaconBlock{ - version: version.Bellatrix, - block: block, - signature: bytesutil.ToBytes96(pb.Signature), + b := &BeaconBlockBody{ + version: version.Phase0, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), + eth1Data: pb.Eth1Data, + graffiti: bytesutil.ToBytes32(pb.Graffiti), + proposerSlashings: pb.ProposerSlashings, + attesterSlashings: pb.AttesterSlashings, + attestations: pb.Attestations, + deposits: pb.Deposits, + voluntaryExits: pb.VoluntaryExits, } return b, nil } -func initSignedBlockFromProtoCapella(pb *eth.SignedBeaconBlockCapella) (*SignedBeaconBlock, error) { +// ---------------------------------------------------------------------------- +// Altair +// ---------------------------------------------------------------------------- + +func initSignedBlockFromProtoAltair(pb *eth.SignedBeaconBlockAltair) (*SignedBeaconBlock, error) { if pb == nil { return nil, errNilBlock } - block, err := initBlockFromProtoCapella(pb.Block) + block, err := initBlockFromProtoAltair(pb.Block) if err != nil { return nil, err } b := &SignedBeaconBlock{ - version: version.Capella, + version: version.Altair, block: block, signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } -func initSignedBlockFromProtoDeneb(pb *eth.SignedBeaconBlockDeneb) (*SignedBeaconBlock, error) { +func initBlockFromProtoAltair(pb *eth.BeaconBlockAltair) (*BeaconBlock, error) { if pb == nil { return nil, errNilBlock } - block, err := initBlockFromProtoDeneb(pb.Block) + body, err := initBlockBodyFromProtoAltair(pb.Body) if err != nil { return nil, err } - b := &SignedBeaconBlock{ - version: version.Deneb, - block: block, - signature: bytesutil.ToBytes96(pb.Signature), + b := &BeaconBlock{ + version: version.Altair, + slot: pb.Slot, + proposerIndex: pb.ProposerIndex, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), + body: body, } return b, nil } -func initSignedBlockFromProtoElectra(pb *eth.SignedBeaconBlockElectra) (*SignedBeaconBlock, error) { +func initBlockBodyFromProtoAltair(pb *eth.BeaconBlockBodyAltair) (*BeaconBlockBody, error) { + if pb == nil { + return nil, errNilBlockBody + } + + b := &BeaconBlockBody{ + version: version.Altair, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), + eth1Data: pb.Eth1Data, + graffiti: bytesutil.ToBytes32(pb.Graffiti), + proposerSlashings: pb.ProposerSlashings, + attesterSlashings: pb.AttesterSlashings, + attestations: pb.Attestations, + deposits: pb.Deposits, + voluntaryExits: pb.VoluntaryExits, + syncAggregate: pb.SyncAggregate, + } + return b, nil +} + +// ---------------------------------------------------------------------------- +// Bellatrix +// ---------------------------------------------------------------------------- + +func initSignedBlockFromProtoBellatrix(pb *eth.SignedBeaconBlockBellatrix) (*SignedBeaconBlock, error) { if pb == nil { return nil, errNilBlock } - block, err := initBlockFromProtoElectra(pb.Block) + block, err := initBlockFromProtoBellatrix(pb.Block) if err != nil { return nil, err } b := &SignedBeaconBlock{ - version: version.Electra, + version: version.Bellatrix, block: block, signature: bytesutil.ToBytes96(pb.Signature), } @@ -682,128 +722,147 @@ func initBlindedSignedBlockFromProtoBellatrix(pb *eth.SignedBlindedBeaconBlockBe return b, nil } -func initBlindedSignedBlockFromProtoCapella(pb *eth.SignedBlindedBeaconBlockCapella) (*SignedBeaconBlock, error) { +func initBlockFromProtoBellatrix(pb *eth.BeaconBlockBellatrix) (*BeaconBlock, error) { if pb == nil { return nil, errNilBlock } - block, err := initBlindedBlockFromProtoCapella(pb.Block) + body, err := initBlockBodyFromProtoBellatrix(pb.Body) if err != nil { return nil, err } - b := &SignedBeaconBlock{ - version: version.Capella, - block: block, - signature: bytesutil.ToBytes96(pb.Signature), + b := &BeaconBlock{ + version: version.Bellatrix, + slot: pb.Slot, + proposerIndex: pb.ProposerIndex, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), + body: body, } return b, nil } -func initBlindedSignedBlockFromProtoDeneb(pb *eth.SignedBlindedBeaconBlockDeneb) (*SignedBeaconBlock, error) { +func initBlindedBlockFromProtoBellatrix(pb *eth.BlindedBeaconBlockBellatrix) (*BeaconBlock, error) { if pb == nil { return nil, errNilBlock } - block, err := initBlindedBlockFromProtoDeneb(pb.Message) + body, err := initBlindedBlockBodyFromProtoBellatrix(pb.Body) if err != nil { return nil, err } - b := &SignedBeaconBlock{ - version: version.Deneb, - block: block, - signature: bytesutil.ToBytes96(pb.Signature), + b := &BeaconBlock{ + version: version.Bellatrix, + slot: pb.Slot, + proposerIndex: pb.ProposerIndex, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), + body: body, } return b, nil } -func initBlindedSignedBlockFromProtoElectra(pb *eth.SignedBlindedBeaconBlockElectra) (*SignedBeaconBlock, error) { +func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconBlockBody, error) { if pb == nil { - return nil, errNilBlock + return nil, errNilBlockBody } - block, err := initBlindedBlockFromProtoElectra(pb.Message) - if err != nil { + p, err := WrappedExecutionPayload(pb.ExecutionPayload) + // We allow the payload to be nil + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } - b := &SignedBeaconBlock{ - version: version.Electra, - block: block, - signature: bytesutil.ToBytes96(pb.Signature), + b := &BeaconBlockBody{ + version: version.Bellatrix, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), + eth1Data: pb.Eth1Data, + graffiti: bytesutil.ToBytes32(pb.Graffiti), + proposerSlashings: pb.ProposerSlashings, + attesterSlashings: pb.AttesterSlashings, + attestations: pb.Attestations, + deposits: pb.Deposits, + voluntaryExits: pb.VoluntaryExits, + syncAggregate: pb.SyncAggregate, + executionPayload: p, } return b, nil } -func initBlockFromProtoPhase0(pb *eth.BeaconBlock) (*BeaconBlock, error) { +func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellatrix) (*BeaconBlockBody, error) { if pb == nil { - return nil, errNilBlock + return nil, errNilBlockBody } - body, err := initBlockBodyFromProtoPhase0(pb.Body) - if err != nil { + ph, err := WrappedExecutionPayloadHeader(pb.ExecutionPayloadHeader) + // We allow the payload to be nil + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } - b := &BeaconBlock{ - version: version.Phase0, - slot: pb.Slot, - proposerIndex: pb.ProposerIndex, - parentRoot: bytesutil.ToBytes32(pb.ParentRoot), - stateRoot: bytesutil.ToBytes32(pb.StateRoot), - body: body, + b := &BeaconBlockBody{ + version: version.Bellatrix, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), + eth1Data: pb.Eth1Data, + graffiti: bytesutil.ToBytes32(pb.Graffiti), + proposerSlashings: pb.ProposerSlashings, + attesterSlashings: pb.AttesterSlashings, + attestations: pb.Attestations, + deposits: pb.Deposits, + voluntaryExits: pb.VoluntaryExits, + syncAggregate: pb.SyncAggregate, + executionPayloadHeader: ph, } return b, nil } -func initBlockFromProtoAltair(pb *eth.BeaconBlockAltair) (*BeaconBlock, error) { +// ---------------------------------------------------------------------------- +// Capella +// ---------------------------------------------------------------------------- + +func initSignedBlockFromProtoCapella(pb *eth.SignedBeaconBlockCapella) (*SignedBeaconBlock, error) { if pb == nil { return nil, errNilBlock } - body, err := initBlockBodyFromProtoAltair(pb.Body) + block, err := initBlockFromProtoCapella(pb.Block) if err != nil { return nil, err } - b := &BeaconBlock{ - version: version.Altair, - slot: pb.Slot, - proposerIndex: pb.ProposerIndex, - parentRoot: bytesutil.ToBytes32(pb.ParentRoot), - stateRoot: bytesutil.ToBytes32(pb.StateRoot), - body: body, + b := &SignedBeaconBlock{ + version: version.Capella, + block: block, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } -func initBlockFromProtoBellatrix(pb *eth.BeaconBlockBellatrix) (*BeaconBlock, error) { +func initBlindedSignedBlockFromProtoCapella(pb *eth.SignedBlindedBeaconBlockCapella) (*SignedBeaconBlock, error) { if pb == nil { return nil, errNilBlock } - body, err := initBlockBodyFromProtoBellatrix(pb.Body) + block, err := initBlindedBlockFromProtoCapella(pb.Block) if err != nil { return nil, err } - b := &BeaconBlock{ - version: version.Bellatrix, - slot: pb.Slot, - proposerIndex: pb.ProposerIndex, - parentRoot: bytesutil.ToBytes32(pb.ParentRoot), - stateRoot: bytesutil.ToBytes32(pb.StateRoot), - body: body, + b := &SignedBeaconBlock{ + version: version.Capella, + block: block, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } -func initBlindedBlockFromProtoBellatrix(pb *eth.BlindedBeaconBlockBellatrix) (*BeaconBlock, error) { +func initBlockFromProtoCapella(pb *eth.BeaconBlockCapella) (*BeaconBlock, error) { if pb == nil { return nil, errNilBlock } - body, err := initBlindedBlockBodyFromProtoBellatrix(pb.Body) + body, err := initBlockBodyFromProtoCapella(pb.Body) if err != nil { return nil, err } b := &BeaconBlock{ - version: version.Bellatrix, + version: version.Capella, slot: pb.Slot, proposerIndex: pb.ProposerIndex, parentRoot: bytesutil.ToBytes32(pb.ParentRoot), @@ -813,12 +872,12 @@ func initBlindedBlockFromProtoBellatrix(pb *eth.BlindedBeaconBlockBellatrix) (*B return b, nil } -func initBlockFromProtoCapella(pb *eth.BeaconBlockCapella) (*BeaconBlock, error) { +func initBlindedBlockFromProtoCapella(pb *eth.BlindedBeaconBlockCapella) (*BeaconBlock, error) { if pb == nil { return nil, errNilBlock } - body, err := initBlockBodyFromProtoCapella(pb.Body) + body, err := initBlindedBlockBodyFromProtoCapella(pb.Body) if err != nil { return nil, err } @@ -833,72 +892,104 @@ func initBlockFromProtoCapella(pb *eth.BeaconBlockCapella) (*BeaconBlock, error) return b, nil } -func initBlockFromProtoDeneb(pb *eth.BeaconBlockDeneb) (*BeaconBlock, error) { +func initBlockBodyFromProtoCapella(pb *eth.BeaconBlockBodyCapella) (*BeaconBlockBody, error) { if pb == nil { - return nil, errNilBlock + return nil, errNilBlockBody } - body, err := initBlockBodyFromProtoDeneb(pb.Body) - if err != nil { + p, err := WrappedExecutionPayloadCapella(pb.ExecutionPayload) + // We allow the payload to be nil + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } - b := &BeaconBlock{ - version: version.Deneb, - slot: pb.Slot, - proposerIndex: pb.ProposerIndex, - parentRoot: bytesutil.ToBytes32(pb.ParentRoot), - stateRoot: bytesutil.ToBytes32(pb.StateRoot), - body: body, + b := &BeaconBlockBody{ + version: version.Capella, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), + eth1Data: pb.Eth1Data, + graffiti: bytesutil.ToBytes32(pb.Graffiti), + proposerSlashings: pb.ProposerSlashings, + attesterSlashings: pb.AttesterSlashings, + attestations: pb.Attestations, + deposits: pb.Deposits, + voluntaryExits: pb.VoluntaryExits, + syncAggregate: pb.SyncAggregate, + executionPayload: p, + blsToExecutionChanges: pb.BlsToExecutionChanges, } return b, nil } -func initBlockFromProtoElectra(pb *eth.BeaconBlockElectra) (*BeaconBlock, error) { +func initBlindedBlockBodyFromProtoCapella(pb *eth.BlindedBeaconBlockBodyCapella) (*BeaconBlockBody, error) { + if pb == nil { + return nil, errNilBlockBody + } + + ph, err := WrappedExecutionPayloadHeaderCapella(pb.ExecutionPayloadHeader) + // We allow the payload to be nil + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { + return nil, err + } + b := &BeaconBlockBody{ + version: version.Capella, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), + eth1Data: pb.Eth1Data, + graffiti: bytesutil.ToBytes32(pb.Graffiti), + proposerSlashings: pb.ProposerSlashings, + attesterSlashings: pb.AttesterSlashings, + attestations: pb.Attestations, + deposits: pb.Deposits, + voluntaryExits: pb.VoluntaryExits, + syncAggregate: pb.SyncAggregate, + executionPayloadHeader: ph, + blsToExecutionChanges: pb.BlsToExecutionChanges, + } + return b, nil +} + +// ---------------------------------------------------------------------------- +// Deneb +// ---------------------------------------------------------------------------- + +func initSignedBlockFromProtoDeneb(pb *eth.SignedBeaconBlockDeneb) (*SignedBeaconBlock, error) { if pb == nil { return nil, errNilBlock } - body, err := initBlockBodyFromProtoElectra(pb.Body) + block, err := initBlockFromProtoDeneb(pb.Block) if err != nil { return nil, err } - b := &BeaconBlock{ - version: version.Electra, - slot: pb.Slot, - proposerIndex: pb.ProposerIndex, - parentRoot: bytesutil.ToBytes32(pb.ParentRoot), - stateRoot: bytesutil.ToBytes32(pb.StateRoot), - body: body, + b := &SignedBeaconBlock{ + version: version.Deneb, + block: block, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } -func initBlindedBlockFromProtoCapella(pb *eth.BlindedBeaconBlockCapella) (*BeaconBlock, error) { +func initBlindedSignedBlockFromProtoDeneb(pb *eth.SignedBlindedBeaconBlockDeneb) (*SignedBeaconBlock, error) { if pb == nil { return nil, errNilBlock } - body, err := initBlindedBlockBodyFromProtoCapella(pb.Body) + block, err := initBlindedBlockFromProtoDeneb(pb.Message) if err != nil { return nil, err } - b := &BeaconBlock{ - version: version.Capella, - slot: pb.Slot, - proposerIndex: pb.ProposerIndex, - parentRoot: bytesutil.ToBytes32(pb.ParentRoot), - stateRoot: bytesutil.ToBytes32(pb.StateRoot), - body: body, + b := &SignedBeaconBlock{ + version: version.Deneb, + block: block, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } -func initBlindedBlockFromProtoDeneb(pb *eth.BlindedBeaconBlockDeneb) (*BeaconBlock, error) { +func initBlockFromProtoDeneb(pb *eth.BeaconBlockDeneb) (*BeaconBlock, error) { if pb == nil { return nil, errNilBlock } - body, err := initBlindedBlockBodyFromProtoDeneb(pb.Body) + body, err := initBlockBodyFromProtoDeneb(pb.Body) if err != nil { return nil, err } @@ -913,17 +1004,17 @@ func initBlindedBlockFromProtoDeneb(pb *eth.BlindedBeaconBlockDeneb) (*BeaconBlo return b, nil } -func initBlindedBlockFromProtoElectra(pb *eth.BlindedBeaconBlockElectra) (*BeaconBlock, error) { +func initBlindedBlockFromProtoDeneb(pb *eth.BlindedBeaconBlockDeneb) (*BeaconBlock, error) { if pb == nil { return nil, errNilBlock } - body, err := initBlindedBlockBodyFromProtoElectra(pb.Body) + body, err := initBlindedBlockBodyFromProtoDeneb(pb.Body) if err != nil { return nil, err } b := &BeaconBlock{ - version: version.Electra, + version: version.Deneb, slot: pb.Slot, proposerIndex: pb.ProposerIndex, parentRoot: bytesutil.ToBytes32(pb.ParentRoot), @@ -933,83 +1024,46 @@ func initBlindedBlockFromProtoElectra(pb *eth.BlindedBeaconBlockElectra) (*Beaco return b, nil } -func initBlockBodyFromProtoPhase0(pb *eth.BeaconBlockBody) (*BeaconBlockBody, error) { - if pb == nil { - return nil, errNilBlockBody - } - - b := &BeaconBlockBody{ - version: version.Phase0, - randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), - eth1Data: pb.Eth1Data, - graffiti: bytesutil.ToBytes32(pb.Graffiti), - proposerSlashings: pb.ProposerSlashings, - attesterSlashings: pb.AttesterSlashings, - attestations: pb.Attestations, - deposits: pb.Deposits, - voluntaryExits: pb.VoluntaryExits, - } - return b, nil -} - -func initBlockBodyFromProtoAltair(pb *eth.BeaconBlockBodyAltair) (*BeaconBlockBody, error) { - if pb == nil { - return nil, errNilBlockBody - } - - b := &BeaconBlockBody{ - version: version.Altair, - randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), - eth1Data: pb.Eth1Data, - graffiti: bytesutil.ToBytes32(pb.Graffiti), - proposerSlashings: pb.ProposerSlashings, - attesterSlashings: pb.AttesterSlashings, - attestations: pb.Attestations, - deposits: pb.Deposits, - voluntaryExits: pb.VoluntaryExits, - syncAggregate: pb.SyncAggregate, - } - return b, nil -} - -func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconBlockBody, error) { +func initBlockBodyFromProtoDeneb(pb *eth.BeaconBlockBodyDeneb) (*BeaconBlockBody, error) { if pb == nil { return nil, errNilBlockBody } - p, err := WrappedExecutionPayload(pb.ExecutionPayload) + p, err := WrappedExecutionPayloadDeneb(pb.ExecutionPayload) // We allow the payload to be nil if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ - version: version.Bellatrix, - randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), - eth1Data: pb.Eth1Data, - graffiti: bytesutil.ToBytes32(pb.Graffiti), - proposerSlashings: pb.ProposerSlashings, - attesterSlashings: pb.AttesterSlashings, - attestations: pb.Attestations, - deposits: pb.Deposits, - voluntaryExits: pb.VoluntaryExits, - syncAggregate: pb.SyncAggregate, - executionPayload: p, + version: version.Deneb, + randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), + eth1Data: pb.Eth1Data, + graffiti: bytesutil.ToBytes32(pb.Graffiti), + proposerSlashings: pb.ProposerSlashings, + attesterSlashings: pb.AttesterSlashings, + attestations: pb.Attestations, + deposits: pb.Deposits, + voluntaryExits: pb.VoluntaryExits, + syncAggregate: pb.SyncAggregate, + executionPayload: p, + blsToExecutionChanges: pb.BlsToExecutionChanges, + blobKzgCommitments: pb.BlobKzgCommitments, } return b, nil } -func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellatrix) (*BeaconBlockBody, error) { +func initBlindedBlockBodyFromProtoDeneb(pb *eth.BlindedBeaconBlockBodyDeneb) (*BeaconBlockBody, error) { if pb == nil { return nil, errNilBlockBody } - ph, err := WrappedExecutionPayloadHeader(pb.ExecutionPayloadHeader) + ph, err := WrappedExecutionPayloadHeaderDeneb(pb.ExecutionPayloadHeader) // We allow the payload to be nil if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ - version: version.Bellatrix, + version: version.Deneb, randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), eth1Data: pb.Eth1Data, graffiti: bytesutil.ToBytes32(pb.Graffiti), @@ -1020,116 +1074,86 @@ func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellat voluntaryExits: pb.VoluntaryExits, syncAggregate: pb.SyncAggregate, executionPayloadHeader: ph, + blsToExecutionChanges: pb.BlsToExecutionChanges, + blobKzgCommitments: pb.BlobKzgCommitments, } return b, nil } -func initBlockBodyFromProtoCapella(pb *eth.BeaconBlockBodyCapella) (*BeaconBlockBody, error) { +// ---------------------------------------------------------------------------- +// Electra +// ---------------------------------------------------------------------------- + +func initSignedBlockFromProtoElectra(pb *eth.SignedBeaconBlockElectra) (*SignedBeaconBlock, error) { if pb == nil { - return nil, errNilBlockBody + return nil, errNilBlock } - p, err := WrappedExecutionPayloadCapella(pb.ExecutionPayload) - // We allow the payload to be nil - if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { + block, err := initBlockFromProtoElectra(pb.Block) + if err != nil { return nil, err } - b := &BeaconBlockBody{ - version: version.Capella, - randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), - eth1Data: pb.Eth1Data, - graffiti: bytesutil.ToBytes32(pb.Graffiti), - proposerSlashings: pb.ProposerSlashings, - attesterSlashings: pb.AttesterSlashings, - attestations: pb.Attestations, - deposits: pb.Deposits, - voluntaryExits: pb.VoluntaryExits, - syncAggregate: pb.SyncAggregate, - executionPayload: p, - blsToExecutionChanges: pb.BlsToExecutionChanges, + b := &SignedBeaconBlock{ + version: version.Electra, + block: block, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } -func initBlindedBlockBodyFromProtoCapella(pb *eth.BlindedBeaconBlockBodyCapella) (*BeaconBlockBody, error) { +func initBlindedSignedBlockFromProtoElectra(pb *eth.SignedBlindedBeaconBlockElectra) (*SignedBeaconBlock, error) { if pb == nil { - return nil, errNilBlockBody + return nil, errNilBlock } - ph, err := WrappedExecutionPayloadHeaderCapella(pb.ExecutionPayloadHeader) - // We allow the payload to be nil - if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { + block, err := initBlindedBlockFromProtoElectra(pb.Message) + if err != nil { return nil, err } - b := &BeaconBlockBody{ - version: version.Capella, - randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), - eth1Data: pb.Eth1Data, - graffiti: bytesutil.ToBytes32(pb.Graffiti), - proposerSlashings: pb.ProposerSlashings, - attesterSlashings: pb.AttesterSlashings, - attestations: pb.Attestations, - deposits: pb.Deposits, - voluntaryExits: pb.VoluntaryExits, - syncAggregate: pb.SyncAggregate, - executionPayloadHeader: ph, - blsToExecutionChanges: pb.BlsToExecutionChanges, + b := &SignedBeaconBlock{ + version: version.Electra, + block: block, + signature: bytesutil.ToBytes96(pb.Signature), } return b, nil } -func initBlockBodyFromProtoDeneb(pb *eth.BeaconBlockBodyDeneb) (*BeaconBlockBody, error) { +func initBlockFromProtoElectra(pb *eth.BeaconBlockElectra) (*BeaconBlock, error) { if pb == nil { - return nil, errNilBlockBody + return nil, errNilBlock } - p, err := WrappedExecutionPayloadDeneb(pb.ExecutionPayload) - // We allow the payload to be nil - if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { + body, err := initBlockBodyFromProtoElectra(pb.Body) + if err != nil { return nil, err } - b := &BeaconBlockBody{ - version: version.Deneb, - randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), - eth1Data: pb.Eth1Data, - graffiti: bytesutil.ToBytes32(pb.Graffiti), - proposerSlashings: pb.ProposerSlashings, - attesterSlashings: pb.AttesterSlashings, - attestations: pb.Attestations, - deposits: pb.Deposits, - voluntaryExits: pb.VoluntaryExits, - syncAggregate: pb.SyncAggregate, - executionPayload: p, - blsToExecutionChanges: pb.BlsToExecutionChanges, - blobKzgCommitments: pb.BlobKzgCommitments, + b := &BeaconBlock{ + version: version.Electra, + slot: pb.Slot, + proposerIndex: pb.ProposerIndex, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), + body: body, } return b, nil } -func initBlindedBlockBodyFromProtoDeneb(pb *eth.BlindedBeaconBlockBodyDeneb) (*BeaconBlockBody, error) { +func initBlindedBlockFromProtoElectra(pb *eth.BlindedBeaconBlockElectra) (*BeaconBlock, error) { if pb == nil { - return nil, errNilBlockBody + return nil, errNilBlock } - ph, err := WrappedExecutionPayloadHeaderDeneb(pb.ExecutionPayloadHeader) - // We allow the payload to be nil - if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { + body, err := initBlindedBlockBodyFromProtoElectra(pb.Body) + if err != nil { return nil, err } - b := &BeaconBlockBody{ - version: version.Deneb, - randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal), - eth1Data: pb.Eth1Data, - graffiti: bytesutil.ToBytes32(pb.Graffiti), - proposerSlashings: pb.ProposerSlashings, - attesterSlashings: pb.AttesterSlashings, - attestations: pb.Attestations, - deposits: pb.Deposits, - voluntaryExits: pb.VoluntaryExits, - syncAggregate: pb.SyncAggregate, - executionPayloadHeader: ph, - blsToExecutionChanges: pb.BlsToExecutionChanges, - blobKzgCommitments: pb.BlobKzgCommitments, + b := &BeaconBlock{ + version: version.Electra, + slot: pb.Slot, + proposerIndex: pb.ProposerIndex, + parentRoot: bytesutil.ToBytes32(pb.ParentRoot), + stateRoot: bytesutil.ToBytes32(pb.StateRoot), + body: body, } return b, nil } @@ -1139,7 +1163,7 @@ func initBlockBodyFromProtoElectra(pb *eth.BeaconBlockBodyElectra) (*BeaconBlock return nil, errNilBlockBody } - p, err := WrappedExecutionPayloadElectra(pb.ExecutionPayload) + p, err := WrappedExecutionPayloadDeneb(pb.ExecutionPayload) // We allow the payload to be nil if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err @@ -1172,7 +1196,7 @@ func initBlindedBlockBodyFromProtoElectra(pb *eth.BlindedBeaconBlockBodyElectra) return nil, errNilBlockBody } - ph, err := WrappedExecutionPayloadHeaderElectra(pb.ExecutionPayloadHeader) + ph, err := WrappedExecutionPayloadHeaderDeneb(pb.ExecutionPayloadHeader) // We allow the payload to be nil if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err diff --git a/proto/engine/v1/electra.go b/proto/engine/v1/electra.go index c6e3af5554ab..5c619414691c 100644 --- a/proto/engine/v1/electra.go +++ b/proto/engine/v1/electra.go @@ -8,9 +8,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/config/params" ) -type ExecutionPayloadElectra = ExecutionPayloadDeneb -type ExecutionPayloadHeaderElectra = ExecutionPayloadHeaderDeneb - var ( drExample = &DepositRequest{} drSize = drExample.SizeSSZ() diff --git a/proto/prysm/v1alpha1/beacon_block.go b/proto/prysm/v1alpha1/beacon_block.go index 1f14849e79f4..7e71f50754a9 100644 --- a/proto/prysm/v1alpha1/beacon_block.go +++ b/proto/prysm/v1alpha1/beacon_block.go @@ -5,6 +5,10 @@ import ( enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" ) +// ---------------------------------------------------------------------------- +// Phase 0 +// ---------------------------------------------------------------------------- + // Copy -- func (sigBlock *SignedBeaconBlock) Copy() *SignedBeaconBlock { if sigBlock == nil { @@ -47,6 +51,107 @@ func (body *BeaconBlockBody) Copy() *BeaconBlockBody { } } +// Copy -- +func (data *Eth1Data) Copy() *Eth1Data { + if data == nil { + return nil + } + return &Eth1Data{ + DepositRoot: bytesutil.SafeCopyBytes(data.DepositRoot), + DepositCount: data.DepositCount, + BlockHash: bytesutil.SafeCopyBytes(data.BlockHash), + } +} + +// Copy -- +func (slashing *ProposerSlashing) Copy() *ProposerSlashing { + if slashing == nil { + return nil + } + return &ProposerSlashing{ + Header_1: slashing.Header_1.Copy(), + Header_2: slashing.Header_2.Copy(), + } +} + +// Copy -- +func (header *SignedBeaconBlockHeader) Copy() *SignedBeaconBlockHeader { + if header == nil { + return nil + } + return &SignedBeaconBlockHeader{ + Header: header.Header.Copy(), + Signature: bytesutil.SafeCopyBytes(header.Signature), + } +} + +// Copy -- +func (header *BeaconBlockHeader) Copy() *BeaconBlockHeader { + if header == nil { + return nil + } + parentRoot := bytesutil.SafeCopyBytes(header.ParentRoot) + stateRoot := bytesutil.SafeCopyBytes(header.StateRoot) + bodyRoot := bytesutil.SafeCopyBytes(header.BodyRoot) + return &BeaconBlockHeader{ + Slot: header.Slot, + ProposerIndex: header.ProposerIndex, + ParentRoot: parentRoot, + StateRoot: stateRoot, + BodyRoot: bodyRoot, + } +} + +// Copy -- +func (deposit *Deposit) Copy() *Deposit { + if deposit == nil { + return nil + } + return &Deposit{ + Proof: bytesutil.SafeCopy2dBytes(deposit.Proof), + Data: deposit.Data.Copy(), + } +} + +// Copy -- +func (depData *Deposit_Data) Copy() *Deposit_Data { + if depData == nil { + return nil + } + return &Deposit_Data{ + PublicKey: bytesutil.SafeCopyBytes(depData.PublicKey), + WithdrawalCredentials: bytesutil.SafeCopyBytes(depData.WithdrawalCredentials), + Amount: depData.Amount, + Signature: bytesutil.SafeCopyBytes(depData.Signature), + } +} + +// Copy -- +func (exit *SignedVoluntaryExit) Copy() *SignedVoluntaryExit { + if exit == nil { + return nil + } + return &SignedVoluntaryExit{ + Exit: exit.Exit.Copy(), + Signature: bytesutil.SafeCopyBytes(exit.Signature), + } +} + +// Copy -- +func (exit *VoluntaryExit) Copy() *VoluntaryExit { + if exit == nil { + return nil + } + return &VoluntaryExit{ + Epoch: exit.Epoch, + ValidatorIndex: exit.ValidatorIndex, + } +} + +// ---------------------------------------------------------------------------- +// Altair +// ---------------------------------------------------------------------------- + // Copy -- func (sigBlock *SignedBeaconBlockAltair) Copy() *SignedBeaconBlockAltair { if sigBlock == nil { @@ -90,6 +195,32 @@ func (body *BeaconBlockBodyAltair) Copy() *BeaconBlockBodyAltair { } } +// Copy -- +func (a *SyncAggregate) Copy() *SyncAggregate { + if a == nil { + return nil + } + return &SyncAggregate{ + SyncCommitteeBits: bytesutil.SafeCopyBytes(a.SyncCommitteeBits), + SyncCommitteeSignature: bytesutil.SafeCopyBytes(a.SyncCommitteeSignature), + } +} + +// Copy -- +func (summary *HistoricalSummary) Copy() *HistoricalSummary { + if summary == nil { + return nil + } + return &HistoricalSummary{ + BlockSummaryRoot: bytesutil.SafeCopyBytes(summary.BlockSummaryRoot), + StateSummaryRoot: bytesutil.SafeCopyBytes(summary.StateSummaryRoot), + } +} + +// ---------------------------------------------------------------------------- +// Bellatrix +// ---------------------------------------------------------------------------- + // Copy -- func (sigBlock *SignedBeaconBlockBellatrix) Copy() *SignedBeaconBlockBellatrix { if sigBlock == nil { @@ -134,6 +265,54 @@ func (body *BeaconBlockBodyBellatrix) Copy() *BeaconBlockBodyBellatrix { } } +// Copy -- +func (sigBlock *SignedBlindedBeaconBlockBellatrix) Copy() *SignedBlindedBeaconBlockBellatrix { + if sigBlock == nil { + return nil + } + return &SignedBlindedBeaconBlockBellatrix{ + Block: sigBlock.Block.Copy(), + Signature: bytesutil.SafeCopyBytes(sigBlock.Signature), + } +} + +// Copy -- +func (block *BlindedBeaconBlockBellatrix) Copy() *BlindedBeaconBlockBellatrix { + if block == nil { + return nil + } + return &BlindedBeaconBlockBellatrix{ + Slot: block.Slot, + ProposerIndex: block.ProposerIndex, + ParentRoot: bytesutil.SafeCopyBytes(block.ParentRoot), + StateRoot: bytesutil.SafeCopyBytes(block.StateRoot), + Body: block.Body.Copy(), + } +} + +// Copy -- +func (body *BlindedBeaconBlockBodyBellatrix) Copy() *BlindedBeaconBlockBodyBellatrix { + if body == nil { + return nil + } + return &BlindedBeaconBlockBodyBellatrix{ + RandaoReveal: bytesutil.SafeCopyBytes(body.RandaoReveal), + Eth1Data: body.Eth1Data.Copy(), + Graffiti: bytesutil.SafeCopyBytes(body.Graffiti), + ProposerSlashings: CopySlice(body.ProposerSlashings), + AttesterSlashings: CopySlice(body.AttesterSlashings), + Attestations: CopySlice(body.Attestations), + Deposits: CopySlice(body.Deposits), + VoluntaryExits: CopySlice(body.VoluntaryExits), + SyncAggregate: body.SyncAggregate.Copy(), + ExecutionPayloadHeader: body.ExecutionPayloadHeader.Copy(), + } +} + +// ---------------------------------------------------------------------------- +// Capella +// ---------------------------------------------------------------------------- + // Copy -- func (sigBlock *SignedBeaconBlockCapella) Copy() *SignedBeaconBlockCapella { if sigBlock == nil { @@ -225,68 +404,49 @@ func (body *BlindedBeaconBlockBodyCapella) Copy() *BlindedBeaconBlockBodyCapella } // Copy -- -func (sigBlock *SignedBlindedBeaconBlockDeneb) Copy() *SignedBlindedBeaconBlockDeneb { - if sigBlock == nil { +func (change *SignedBLSToExecutionChange) Copy() *SignedBLSToExecutionChange { + if change == nil { return nil } - return &SignedBlindedBeaconBlockDeneb{ - Message: sigBlock.Message.Copy(), - Signature: bytesutil.SafeCopyBytes(sigBlock.Signature), + return &SignedBLSToExecutionChange{ + Message: change.Message.Copy(), + Signature: bytesutil.SafeCopyBytes(change.Signature), } } // Copy -- -func (block *BlindedBeaconBlockDeneb) Copy() *BlindedBeaconBlockDeneb { - if block == nil { +func (change *BLSToExecutionChange) Copy() *BLSToExecutionChange { + if change == nil { return nil } - return &BlindedBeaconBlockDeneb{ - Slot: block.Slot, - ProposerIndex: block.ProposerIndex, - ParentRoot: bytesutil.SafeCopyBytes(block.ParentRoot), - StateRoot: bytesutil.SafeCopyBytes(block.StateRoot), - Body: block.Body.Copy(), + return &BLSToExecutionChange{ + ValidatorIndex: change.ValidatorIndex, + FromBlsPubkey: bytesutil.SafeCopyBytes(change.FromBlsPubkey), + ToExecutionAddress: bytesutil.SafeCopyBytes(change.ToExecutionAddress), } } -// Copy -- -func (body *BlindedBeaconBlockBodyDeneb) Copy() *BlindedBeaconBlockBodyDeneb { - if body == nil { - return nil - } - return &BlindedBeaconBlockBodyDeneb{ - RandaoReveal: bytesutil.SafeCopyBytes(body.RandaoReveal), - Eth1Data: body.Eth1Data.Copy(), - Graffiti: bytesutil.SafeCopyBytes(body.Graffiti), - ProposerSlashings: CopySlice(body.ProposerSlashings), - AttesterSlashings: CopySlice(body.AttesterSlashings), - Attestations: CopySlice(body.Attestations), - Deposits: CopySlice(body.Deposits), - VoluntaryExits: CopySlice(body.VoluntaryExits), - SyncAggregate: body.SyncAggregate.Copy(), - ExecutionPayloadHeader: body.ExecutionPayloadHeader.Copy(), - BlsToExecutionChanges: CopySlice(body.BlsToExecutionChanges), - BlobKzgCommitments: CopyBlobKZGs(body.BlobKzgCommitments), - } -} +// ---------------------------------------------------------------------------- +// Deneb +// ---------------------------------------------------------------------------- // Copy -- -func (sigBlock *SignedBlindedBeaconBlockElectra) Copy() *SignedBlindedBeaconBlockElectra { +func (sigBlock *SignedBlindedBeaconBlockDeneb) Copy() *SignedBlindedBeaconBlockDeneb { if sigBlock == nil { return nil } - return &SignedBlindedBeaconBlockElectra{ + return &SignedBlindedBeaconBlockDeneb{ Message: sigBlock.Message.Copy(), Signature: bytesutil.SafeCopyBytes(sigBlock.Signature), } } // Copy -- -func (block *BlindedBeaconBlockElectra) Copy() *BlindedBeaconBlockElectra { +func (block *BlindedBeaconBlockDeneb) Copy() *BlindedBeaconBlockDeneb { if block == nil { return nil } - return &BlindedBeaconBlockElectra{ + return &BlindedBeaconBlockDeneb{ Slot: block.Slot, ProposerIndex: block.ProposerIndex, ParentRoot: bytesutil.SafeCopyBytes(block.ParentRoot), @@ -296,11 +456,11 @@ func (block *BlindedBeaconBlockElectra) Copy() *BlindedBeaconBlockElectra { } // Copy -- -func (body *BlindedBeaconBlockBodyElectra) Copy() *BlindedBeaconBlockBodyElectra { +func (body *BlindedBeaconBlockBodyDeneb) Copy() *BlindedBeaconBlockBodyDeneb { if body == nil { return nil } - return &BlindedBeaconBlockBodyElectra{ + return &BlindedBeaconBlockBodyDeneb{ RandaoReveal: bytesutil.SafeCopyBytes(body.RandaoReveal), Eth1Data: body.Eth1Data.Copy(), Graffiti: bytesutil.SafeCopyBytes(body.Graffiti), @@ -313,27 +473,26 @@ func (body *BlindedBeaconBlockBodyElectra) Copy() *BlindedBeaconBlockBodyElectra ExecutionPayloadHeader: body.ExecutionPayloadHeader.Copy(), BlsToExecutionChanges: CopySlice(body.BlsToExecutionChanges), BlobKzgCommitments: CopyBlobKZGs(body.BlobKzgCommitments), - ExecutionRequests: CopyExecutionRequests(body.ExecutionRequests), } } // Copy -- -func (sigBlock *SignedBlindedBeaconBlockBellatrix) Copy() *SignedBlindedBeaconBlockBellatrix { +func (sigBlock *SignedBeaconBlockDeneb) Copy() *SignedBeaconBlockDeneb { if sigBlock == nil { return nil } - return &SignedBlindedBeaconBlockBellatrix{ + return &SignedBeaconBlockDeneb{ Block: sigBlock.Block.Copy(), Signature: bytesutil.SafeCopyBytes(sigBlock.Signature), } } // Copy -- -func (block *BlindedBeaconBlockBellatrix) Copy() *BlindedBeaconBlockBellatrix { +func (block *BeaconBlockDeneb) Copy() *BeaconBlockDeneb { if block == nil { return nil } - return &BlindedBeaconBlockBellatrix{ + return &BeaconBlockDeneb{ Slot: block.Slot, ProposerIndex: block.ProposerIndex, ParentRoot: bytesutil.SafeCopyBytes(block.ParentRoot), @@ -343,21 +502,23 @@ func (block *BlindedBeaconBlockBellatrix) Copy() *BlindedBeaconBlockBellatrix { } // Copy -- -func (body *BlindedBeaconBlockBodyBellatrix) Copy() *BlindedBeaconBlockBodyBellatrix { +func (body *BeaconBlockBodyDeneb) Copy() *BeaconBlockBodyDeneb { if body == nil { return nil } - return &BlindedBeaconBlockBodyBellatrix{ - RandaoReveal: bytesutil.SafeCopyBytes(body.RandaoReveal), - Eth1Data: body.Eth1Data.Copy(), - Graffiti: bytesutil.SafeCopyBytes(body.Graffiti), - ProposerSlashings: CopySlice(body.ProposerSlashings), - AttesterSlashings: CopySlice(body.AttesterSlashings), - Attestations: CopySlice(body.Attestations), - Deposits: CopySlice(body.Deposits), - VoluntaryExits: CopySlice(body.VoluntaryExits), - SyncAggregate: body.SyncAggregate.Copy(), - ExecutionPayloadHeader: body.ExecutionPayloadHeader.Copy(), + return &BeaconBlockBodyDeneb{ + RandaoReveal: bytesutil.SafeCopyBytes(body.RandaoReveal), + Eth1Data: body.Eth1Data.Copy(), + Graffiti: bytesutil.SafeCopyBytes(body.Graffiti), + ProposerSlashings: CopySlice(body.ProposerSlashings), + AttesterSlashings: CopySlice(body.AttesterSlashings), + Attestations: CopySlice(body.Attestations), + Deposits: CopySlice(body.Deposits), + VoluntaryExits: CopySlice(body.VoluntaryExits), + SyncAggregate: body.SyncAggregate.Copy(), + ExecutionPayload: body.ExecutionPayload.Copy(), + BlsToExecutionChanges: CopySlice(body.BlsToExecutionChanges), + BlobKzgCommitments: CopyBlobKZGs(body.BlobKzgCommitments), } } @@ -366,48 +527,27 @@ func CopyBlobKZGs(b [][]byte) [][]byte { return bytesutil.SafeCopy2dBytes(b) } -// CopyExecutionRequests copies the provided execution requests. -func CopyExecutionRequests(e *enginev1.ExecutionRequests) *enginev1.ExecutionRequests { - if e == nil { - return nil - } - dr := make([]*enginev1.DepositRequest, len(e.Deposits)) - for i, d := range e.Deposits { - dr[i] = d.Copy() - } - wr := make([]*enginev1.WithdrawalRequest, len(e.Withdrawals)) - for i, w := range e.Withdrawals { - wr[i] = w.Copy() - } - cr := make([]*enginev1.ConsolidationRequest, len(e.Consolidations)) - for i, c := range e.Consolidations { - cr[i] = c.Copy() - } - - return &enginev1.ExecutionRequests{ - Deposits: dr, - Withdrawals: wr, - Consolidations: cr, - } -} +// ---------------------------------------------------------------------------- +// Electra +// ---------------------------------------------------------------------------- // Copy -- -func (sigBlock *SignedBeaconBlockDeneb) Copy() *SignedBeaconBlockDeneb { +func (sigBlock *SignedBlindedBeaconBlockElectra) Copy() *SignedBlindedBeaconBlockElectra { if sigBlock == nil { return nil } - return &SignedBeaconBlockDeneb{ - Block: sigBlock.Block.Copy(), + return &SignedBlindedBeaconBlockElectra{ + Message: sigBlock.Message.Copy(), Signature: bytesutil.SafeCopyBytes(sigBlock.Signature), } } // Copy -- -func (block *BeaconBlockDeneb) Copy() *BeaconBlockDeneb { +func (block *BlindedBeaconBlockElectra) Copy() *BlindedBeaconBlockElectra { if block == nil { return nil } - return &BeaconBlockDeneb{ + return &BlindedBeaconBlockElectra{ Slot: block.Slot, ProposerIndex: block.ProposerIndex, ParentRoot: bytesutil.SafeCopyBytes(block.ParentRoot), @@ -417,23 +557,24 @@ func (block *BeaconBlockDeneb) Copy() *BeaconBlockDeneb { } // Copy -- -func (body *BeaconBlockBodyDeneb) Copy() *BeaconBlockBodyDeneb { +func (body *BlindedBeaconBlockBodyElectra) Copy() *BlindedBeaconBlockBodyElectra { if body == nil { return nil } - return &BeaconBlockBodyDeneb{ - RandaoReveal: bytesutil.SafeCopyBytes(body.RandaoReveal), - Eth1Data: body.Eth1Data.Copy(), - Graffiti: bytesutil.SafeCopyBytes(body.Graffiti), - ProposerSlashings: CopySlice(body.ProposerSlashings), - AttesterSlashings: CopySlice(body.AttesterSlashings), - Attestations: CopySlice(body.Attestations), - Deposits: CopySlice(body.Deposits), - VoluntaryExits: CopySlice(body.VoluntaryExits), - SyncAggregate: body.SyncAggregate.Copy(), - ExecutionPayload: body.ExecutionPayload.Copy(), - BlsToExecutionChanges: CopySlice(body.BlsToExecutionChanges), - BlobKzgCommitments: CopyBlobKZGs(body.BlobKzgCommitments), + return &BlindedBeaconBlockBodyElectra{ + RandaoReveal: bytesutil.SafeCopyBytes(body.RandaoReveal), + Eth1Data: body.Eth1Data.Copy(), + Graffiti: bytesutil.SafeCopyBytes(body.Graffiti), + ProposerSlashings: CopySlice(body.ProposerSlashings), + AttesterSlashings: CopySlice(body.AttesterSlashings), + Attestations: CopySlice(body.Attestations), + Deposits: CopySlice(body.Deposits), + VoluntaryExits: CopySlice(body.VoluntaryExits), + SyncAggregate: body.SyncAggregate.Copy(), + ExecutionPayloadHeader: body.ExecutionPayloadHeader.Copy(), + BlsToExecutionChanges: CopySlice(body.BlsToExecutionChanges), + BlobKzgCommitments: CopyBlobKZGs(body.BlobKzgCommitments), + ExecutionRequests: CopyExecutionRequests(body.ExecutionRequests), } } @@ -484,144 +625,27 @@ func (body *BeaconBlockBodyElectra) Copy() *BeaconBlockBodyElectra { } } -// Copy -- -func (data *Eth1Data) Copy() *Eth1Data { - if data == nil { - return nil - } - return &Eth1Data{ - DepositRoot: bytesutil.SafeCopyBytes(data.DepositRoot), - DepositCount: data.DepositCount, - BlockHash: bytesutil.SafeCopyBytes(data.BlockHash), - } -} - -// Copy -- -func (slashing *ProposerSlashing) Copy() *ProposerSlashing { - if slashing == nil { - return nil - } - return &ProposerSlashing{ - Header_1: slashing.Header_1.Copy(), - Header_2: slashing.Header_2.Copy(), - } -} - -// Copy -- -func (header *SignedBeaconBlockHeader) Copy() *SignedBeaconBlockHeader { - if header == nil { - return nil - } - return &SignedBeaconBlockHeader{ - Header: header.Header.Copy(), - Signature: bytesutil.SafeCopyBytes(header.Signature), - } -} - -// Copy -- -func (header *BeaconBlockHeader) Copy() *BeaconBlockHeader { - if header == nil { - return nil - } - parentRoot := bytesutil.SafeCopyBytes(header.ParentRoot) - stateRoot := bytesutil.SafeCopyBytes(header.StateRoot) - bodyRoot := bytesutil.SafeCopyBytes(header.BodyRoot) - return &BeaconBlockHeader{ - Slot: header.Slot, - ProposerIndex: header.ProposerIndex, - ParentRoot: parentRoot, - StateRoot: stateRoot, - BodyRoot: bodyRoot, - } -} - -// Copy -- -func (deposit *Deposit) Copy() *Deposit { - if deposit == nil { - return nil - } - return &Deposit{ - Proof: bytesutil.SafeCopy2dBytes(deposit.Proof), - Data: deposit.Data.Copy(), - } -} - -// Copy -- -func (depData *Deposit_Data) Copy() *Deposit_Data { - if depData == nil { - return nil - } - return &Deposit_Data{ - PublicKey: bytesutil.SafeCopyBytes(depData.PublicKey), - WithdrawalCredentials: bytesutil.SafeCopyBytes(depData.WithdrawalCredentials), - Amount: depData.Amount, - Signature: bytesutil.SafeCopyBytes(depData.Signature), - } -} - -// Copy -- -func (exit *SignedVoluntaryExit) Copy() *SignedVoluntaryExit { - if exit == nil { - return nil - } - return &SignedVoluntaryExit{ - Exit: exit.Exit.Copy(), - Signature: bytesutil.SafeCopyBytes(exit.Signature), - } -} - -// Copy -- -func (exit *VoluntaryExit) Copy() *VoluntaryExit { - if exit == nil { - return nil - } - return &VoluntaryExit{ - Epoch: exit.Epoch, - ValidatorIndex: exit.ValidatorIndex, - } -} - -// Copy -- -func (a *SyncAggregate) Copy() *SyncAggregate { - if a == nil { - return nil - } - return &SyncAggregate{ - SyncCommitteeBits: bytesutil.SafeCopyBytes(a.SyncCommitteeBits), - SyncCommitteeSignature: bytesutil.SafeCopyBytes(a.SyncCommitteeSignature), - } -} - -// Copy -- -func (change *SignedBLSToExecutionChange) Copy() *SignedBLSToExecutionChange { - if change == nil { +// CopyExecutionRequests copies the provided execution requests. +func CopyExecutionRequests(e *enginev1.ExecutionRequests) *enginev1.ExecutionRequests { + if e == nil { return nil } - return &SignedBLSToExecutionChange{ - Message: change.Message.Copy(), - Signature: bytesutil.SafeCopyBytes(change.Signature), + dr := make([]*enginev1.DepositRequest, len(e.Deposits)) + for i, d := range e.Deposits { + dr[i] = d.Copy() } -} - -// Copy -- -func (change *BLSToExecutionChange) Copy() *BLSToExecutionChange { - if change == nil { - return nil + wr := make([]*enginev1.WithdrawalRequest, len(e.Withdrawals)) + for i, w := range e.Withdrawals { + wr[i] = w.Copy() } - return &BLSToExecutionChange{ - ValidatorIndex: change.ValidatorIndex, - FromBlsPubkey: bytesutil.SafeCopyBytes(change.FromBlsPubkey), - ToExecutionAddress: bytesutil.SafeCopyBytes(change.ToExecutionAddress), + cr := make([]*enginev1.ConsolidationRequest, len(e.Consolidations)) + for i, c := range e.Consolidations { + cr[i] = c.Copy() } -} -// Copy -- -func (summary *HistoricalSummary) Copy() *HistoricalSummary { - if summary == nil { - return nil - } - return &HistoricalSummary{ - BlockSummaryRoot: bytesutil.SafeCopyBytes(summary.BlockSummaryRoot), - StateSummaryRoot: bytesutil.SafeCopyBytes(summary.StateSummaryRoot), + return &enginev1.ExecutionRequests{ + Deposits: dr, + Withdrawals: wr, + Consolidations: cr, } } diff --git a/runtime/interop/BUILD.bazel b/runtime/interop/BUILD.bazel index 454b309e009a..50cffc8cc2e0 100644 --- a/runtime/interop/BUILD.bazel +++ b/runtime/interop/BUILD.bazel @@ -24,7 +24,6 @@ go_library( "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", - "//consensus-types/interfaces:go_default_library", "//container/trie:go_default_library", "//crypto/bls:go_default_library", "//crypto/hash:go_default_library", diff --git a/runtime/interop/premine-state.go b/runtime/interop/premine-state.go index ce2381a7191d..011ed8189b33 100644 --- a/runtime/interop/premine-state.go +++ b/runtime/interop/premine-state.go @@ -13,7 +13,6 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/container/trie" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" @@ -543,7 +542,7 @@ func (s *PremineGenesisConfig) setLatestBlockHeader(g state.BeaconState) error { SyncCommitteeBits: make([]byte, fieldparams.SyncCommitteeLength/8), SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength), }, - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), @@ -581,16 +580,10 @@ func (s *PremineGenesisConfig) setLatestBlockHeader(g state.BeaconState) error { } func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error { - if s.Version < version.Bellatrix { - return nil - } - gb := s.GB - var ed interfaces.ExecutionData - switch s.Version { - case version.Bellatrix: - payload := &enginev1.ExecutionPayload{ + if s.Version >= version.Deneb { + payload := &enginev1.ExecutionPayloadDeneb{ ParentHash: gb.ParentHash().Bytes(), FeeRecipient: gb.Coinbase().Bytes(), StateRoot: gb.Root().Bytes(), @@ -605,20 +598,30 @@ func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error { BaseFeePerGas: bytesutil.PadTo(bytesutil.ReverseByteOrder(gb.BaseFee().Bytes()), fieldparams.RootLength), BlockHash: gb.Hash().Bytes(), Transactions: make([][]byte, 0), + Withdrawals: make([]*enginev1.Withdrawal, 0), + ExcessBlobGas: unwrapUint64Ptr(gb.ExcessBlobGas()), + BlobGasUsed: unwrapUint64Ptr(gb.BlobGasUsed()), } - wep, err := blocks.WrappedExecutionPayload(payload) + + wep, err := blocks.WrappedExecutionPayloadDeneb(payload) if err != nil { return err } - eph, err := blocks.PayloadToHeader(wep) + + eph, err := blocks.PayloadToHeaderDeneb(wep) if err != nil { return err } - ed, err = blocks.WrappedExecutionPayloadHeader(eph) + + ed, err := blocks.WrappedExecutionPayloadHeaderDeneb(eph) if err != nil { return err } - case version.Capella: + + return g.SetLatestExecutionPayloadHeader(ed) + } + + if s.Version >= version.Capella { payload := &enginev1.ExecutionPayloadCapella{ ParentHash: gb.ParentHash().Bytes(), FeeRecipient: gb.Coinbase().Bytes(), @@ -636,52 +639,27 @@ func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error { Transactions: make([][]byte, 0), Withdrawals: make([]*enginev1.Withdrawal, 0), } + wep, err := blocks.WrappedExecutionPayloadCapella(payload) if err != nil { return err } + eph, err := blocks.PayloadToHeaderCapella(wep) if err != nil { return err } - ed, err = blocks.WrappedExecutionPayloadHeaderCapella(eph) - if err != nil { - return err - } - case version.Deneb: - payload := &enginev1.ExecutionPayloadDeneb{ - ParentHash: gb.ParentHash().Bytes(), - FeeRecipient: gb.Coinbase().Bytes(), - StateRoot: gb.Root().Bytes(), - ReceiptsRoot: gb.ReceiptHash().Bytes(), - LogsBloom: gb.Bloom().Bytes(), - PrevRandao: params.BeaconConfig().ZeroHash[:], - BlockNumber: gb.NumberU64(), - GasLimit: gb.GasLimit(), - GasUsed: gb.GasUsed(), - Timestamp: gb.Time(), - ExtraData: gb.Extra()[:32], - BaseFeePerGas: bytesutil.PadTo(bytesutil.ReverseByteOrder(gb.BaseFee().Bytes()), fieldparams.RootLength), - BlockHash: gb.Hash().Bytes(), - Transactions: make([][]byte, 0), - Withdrawals: make([]*enginev1.Withdrawal, 0), - ExcessBlobGas: unwrapUint64Ptr(gb.ExcessBlobGas()), - BlobGasUsed: unwrapUint64Ptr(gb.BlobGasUsed()), - } - wep, err := blocks.WrappedExecutionPayloadDeneb(payload) - if err != nil { - return err - } - eph, err := blocks.PayloadToHeaderDeneb(wep) - if err != nil { - return err - } - ed, err = blocks.WrappedExecutionPayloadHeaderDeneb(eph) + + ed, err := blocks.WrappedExecutionPayloadHeaderCapella(eph) if err != nil { return err } - case version.Electra: - payload := &enginev1.ExecutionPayloadElectra{ + + return g.SetLatestExecutionPayloadHeader(ed) + } + + if s.Version >= version.Bellatrix { + payload := &enginev1.ExecutionPayload{ ParentHash: gb.ParentHash().Bytes(), FeeRecipient: gb.Coinbase().Bytes(), StateRoot: gb.Root().Bytes(), @@ -696,26 +674,31 @@ func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error { BaseFeePerGas: bytesutil.PadTo(bytesutil.ReverseByteOrder(gb.BaseFee().Bytes()), fieldparams.RootLength), BlockHash: gb.Hash().Bytes(), Transactions: make([][]byte, 0), - Withdrawals: make([]*enginev1.Withdrawal, 0), - ExcessBlobGas: *gb.ExcessBlobGas(), - BlobGasUsed: *gb.BlobGasUsed(), } - wep, err := blocks.WrappedExecutionPayloadElectra(payload) + + wep, err := blocks.WrappedExecutionPayload(payload) if err != nil { return err } - eph, err := blocks.PayloadToHeaderElectra(wep) + + eph, err := blocks.PayloadToHeader(wep) if err != nil { return err } - ed, err = blocks.WrappedExecutionPayloadHeaderElectra(eph) + + ed, err := blocks.WrappedExecutionPayloadHeader(eph) if err != nil { return err } - default: - return errUnsupportedVersion + + return g.SetLatestExecutionPayloadHeader(ed) } - return g.SetLatestExecutionPayloadHeader(ed) + + if s.Version > version.Phase0 { + return nil + } + + return errUnsupportedVersion } func unwrapUint64Ptr(u *uint64) uint64 { diff --git a/testing/spectest/shared/common/forkchoice/runner.go b/testing/spectest/shared/common/forkchoice/runner.go index c4d7a2d79ca6..c43594403add 100644 --- a/testing/spectest/shared/common/forkchoice/runner.go +++ b/testing/spectest/shared/common/forkchoice/runner.go @@ -192,6 +192,129 @@ func runTest(t *testing.T, config string, fork int, basePath string) { // nolint } } +func runBlobStep(t *testing.T, + step Step, + beaconBlock interfaces.ReadOnlySignedBeaconBlock, + fork int, + folder os.DirEntry, + testsFolderPath string, + builder *Builder, +) { + blobs := step.Blobs + proofs := step.Proofs + if blobs != nil && *blobs != "null" { + require.NotNil(t, beaconBlock) + require.Equal(t, true, fork >= version.Deneb) + + block := beaconBlock.Block() + root, err := block.HashTreeRoot() + require.NoError(t, err) + kzgs, err := block.Body().BlobKzgCommitments() + require.NoError(t, err) + + blobsFile, err := util.BazelFileBytes(testsFolderPath, folder.Name(), fmt.Sprint(*blobs, ".ssz_snappy")) + require.NoError(t, err) + blobsSSZ, err := snappy.Decode(nil /* dst */, blobsFile) + require.NoError(t, err) + sh, err := beaconBlock.Header() + require.NoError(t, err) + requireVerifyExpected := errAssertionForStep(step, verification.ErrBlobInvalid) + for index := 0; index*fieldparams.BlobLength < len(blobsSSZ); index++ { + var proof []byte + if index < len(proofs) { + proofPTR := proofs[index] + require.NotNil(t, proofPTR) + proof, err = hexutil.Decode(*proofPTR) + require.NoError(t, err) + } + + blob := [fieldparams.BlobLength]byte{} + copy(blob[:], blobsSSZ[index*fieldparams.BlobLength:]) + if len(proof) == 0 { + proof = make([]byte, 48) + } + + inclusionProof, err := blocks.MerkleProofKZGCommitment(block.Body(), index) + require.NoError(t, err) + pb := ðpb.BlobSidecar{ + Index: uint64(index), + Blob: blob[:], + KzgCommitment: kzgs[index], + KzgProof: proof, + SignedBlockHeader: sh, + CommitmentInclusionProof: inclusionProof, + } + ro, err := blocks.NewROBlobWithRoot(pb, root) + require.NoError(t, err) + ini, err := builder.vwait.WaitForInitializer(context.Background()) + require.NoError(t, err) + bv := ini.NewBlobVerifier(ro, verification.SpectestBlobSidecarRequirements) + ctx := context.Background() + if err := bv.BlobIndexInBounds(); err != nil { + t.Logf("BlobIndexInBounds error: %s", err.Error()) + } + if err := bv.NotFromFutureSlot(); err != nil { + t.Logf("NotFromFutureSlot error: %s", err.Error()) + } + if err := bv.SlotAboveFinalized(); err != nil { + t.Logf("SlotAboveFinalized error: %s", err.Error()) + } + if err := bv.SidecarInclusionProven(); err != nil { + t.Logf("SidecarInclusionProven error: %s", err.Error()) + } + if err := bv.SidecarKzgProofVerified(); err != nil { + t.Logf("SidecarKzgProofVerified error: %s", err.Error()) + } + if err := bv.ValidProposerSignature(ctx); err != nil { + t.Logf("ValidProposerSignature error: %s", err.Error()) + } + if err := bv.SidecarParentSlotLower(); err != nil { + t.Logf("SidecarParentSlotLower error: %s", err.Error()) + } + if err := bv.SidecarDescendsFromFinalized(); err != nil { + t.Logf("SidecarDescendsFromFinalized error: %s", err.Error()) + } + if err := bv.SidecarProposerExpected(ctx); err != nil { + t.Logf("SidecarProposerExpected error: %s", err.Error()) + } + + vsc, err := bv.VerifiedROBlob() + requireVerifyExpected(t, err) + + if err == nil { + require.NoError(t, builder.service.ReceiveBlob(context.Background(), vsc)) + } + } + } +} + +func errAssertionForStep(step Step, expect error) func(t *testing.T, err error) { + if !*step.Valid { + return func(t *testing.T, err error) { + require.ErrorIs(t, err, expect) + } + } + return func(t *testing.T, err error) { + if err != nil { + require.ErrorIs(t, err, verification.ErrBlobInvalid) + var me verification.VerificationMultiError + ok := errors.As(err, &me) + require.Equal(t, true, ok) + fails := me.Failures() + // we haven't performed any verification, so all the results should be this type + fmsg := make([]string, 0, len(fails)) + for k, v := range fails { + fmsg = append(fmsg, fmt.Sprintf("%s - %s", v.Error(), k.String())) + } + t.Fatal(strings.Join(fmsg, ";")) + } + } +} + +// ---------------------------------------------------------------------------- +// Phase 0 +// ---------------------------------------------------------------------------- + func unmarshalPhase0State(t *testing.T, raw []byte) state.BeaconState { base := ðpb.BeaconState{} require.NoError(t, base.UnmarshalSSZ(raw)) @@ -216,6 +339,10 @@ func unmarshalSignedPhase0Block(t *testing.T, raw []byte) interfaces.ReadOnlySig return blk } +// ---------------------------------------------------------------------------- +// Altair +// ---------------------------------------------------------------------------- + func unmarshalAltairState(t *testing.T, raw []byte) state.BeaconState { base := ðpb.BeaconStateAltair{} require.NoError(t, base.UnmarshalSSZ(raw)) @@ -240,6 +367,10 @@ func unmarshalSignedAltairBlock(t *testing.T, raw []byte) interfaces.ReadOnlySig return blk } +// ---------------------------------------------------------------------------- +// Bellatrix +// ---------------------------------------------------------------------------- + func unmarshalBellatrixState(t *testing.T, raw []byte) state.BeaconState { base := ðpb.BeaconStateBellatrix{} require.NoError(t, base.UnmarshalSSZ(raw)) @@ -264,6 +395,10 @@ func unmarshalSignedBellatrixBlock(t *testing.T, raw []byte) interfaces.ReadOnly return blk } +// ---------------------------------------------------------------------------- +// Capella +// ---------------------------------------------------------------------------- + func unmarshalCapellaState(t *testing.T, raw []byte) state.BeaconState { base := ðpb.BeaconStateCapella{} require.NoError(t, base.UnmarshalSSZ(raw)) @@ -288,6 +423,10 @@ func unmarshalSignedCapellaBlock(t *testing.T, raw []byte) interfaces.ReadOnlySi return blk } +// ---------------------------------------------------------------------------- +// Deneb +// ---------------------------------------------------------------------------- + func unmarshalDenebState(t *testing.T, raw []byte) state.BeaconState { base := ðpb.BeaconStateDeneb{} require.NoError(t, base.UnmarshalSSZ(raw)) @@ -312,6 +451,10 @@ func unmarshalSignedDenebBlock(t *testing.T, raw []byte) interfaces.SignedBeacon return blk } +// ---------------------------------------------------------------------------- +// Electra +// ---------------------------------------------------------------------------- + func unmarshalElectraState(t *testing.T, raw []byte) state.BeaconState { base := ðpb.BeaconStateElectra{} require.NoError(t, base.UnmarshalSSZ(raw)) @@ -335,122 +478,3 @@ func unmarshalSignedElectraBlock(t *testing.T, raw []byte) interfaces.SignedBeac require.NoError(t, err) return blk } - -func runBlobStep(t *testing.T, - step Step, - beaconBlock interfaces.ReadOnlySignedBeaconBlock, - fork int, - folder os.DirEntry, - testsFolderPath string, - builder *Builder, -) { - blobs := step.Blobs - proofs := step.Proofs - if blobs != nil && *blobs != "null" { - require.NotNil(t, beaconBlock) - require.Equal(t, true, fork >= version.Deneb) - - block := beaconBlock.Block() - root, err := block.HashTreeRoot() - require.NoError(t, err) - kzgs, err := block.Body().BlobKzgCommitments() - require.NoError(t, err) - - blobsFile, err := util.BazelFileBytes(testsFolderPath, folder.Name(), fmt.Sprint(*blobs, ".ssz_snappy")) - require.NoError(t, err) - blobsSSZ, err := snappy.Decode(nil /* dst */, blobsFile) - require.NoError(t, err) - sh, err := beaconBlock.Header() - require.NoError(t, err) - requireVerifyExpected := errAssertionForStep(step, verification.ErrBlobInvalid) - for index := 0; index*fieldparams.BlobLength < len(blobsSSZ); index++ { - var proof []byte - if index < len(proofs) { - proofPTR := proofs[index] - require.NotNil(t, proofPTR) - proof, err = hexutil.Decode(*proofPTR) - require.NoError(t, err) - } - - blob := [fieldparams.BlobLength]byte{} - copy(blob[:], blobsSSZ[index*fieldparams.BlobLength:]) - if len(proof) == 0 { - proof = make([]byte, 48) - } - - inclusionProof, err := blocks.MerkleProofKZGCommitment(block.Body(), index) - require.NoError(t, err) - pb := ðpb.BlobSidecar{ - Index: uint64(index), - Blob: blob[:], - KzgCommitment: kzgs[index], - KzgProof: proof, - SignedBlockHeader: sh, - CommitmentInclusionProof: inclusionProof, - } - ro, err := blocks.NewROBlobWithRoot(pb, root) - require.NoError(t, err) - ini, err := builder.vwait.WaitForInitializer(context.Background()) - require.NoError(t, err) - bv := ini.NewBlobVerifier(ro, verification.SpectestBlobSidecarRequirements) - ctx := context.Background() - if err := bv.BlobIndexInBounds(); err != nil { - t.Logf("BlobIndexInBounds error: %s", err.Error()) - } - if err := bv.NotFromFutureSlot(); err != nil { - t.Logf("NotFromFutureSlot error: %s", err.Error()) - } - if err := bv.SlotAboveFinalized(); err != nil { - t.Logf("SlotAboveFinalized error: %s", err.Error()) - } - if err := bv.SidecarInclusionProven(); err != nil { - t.Logf("SidecarInclusionProven error: %s", err.Error()) - } - if err := bv.SidecarKzgProofVerified(); err != nil { - t.Logf("SidecarKzgProofVerified error: %s", err.Error()) - } - if err := bv.ValidProposerSignature(ctx); err != nil { - t.Logf("ValidProposerSignature error: %s", err.Error()) - } - if err := bv.SidecarParentSlotLower(); err != nil { - t.Logf("SidecarParentSlotLower error: %s", err.Error()) - } - if err := bv.SidecarDescendsFromFinalized(); err != nil { - t.Logf("SidecarDescendsFromFinalized error: %s", err.Error()) - } - if err := bv.SidecarProposerExpected(ctx); err != nil { - t.Logf("SidecarProposerExpected error: %s", err.Error()) - } - - vsc, err := bv.VerifiedROBlob() - requireVerifyExpected(t, err) - - if err == nil { - require.NoError(t, builder.service.ReceiveBlob(context.Background(), vsc)) - } - } - } -} - -func errAssertionForStep(step Step, expect error) func(t *testing.T, err error) { - if !*step.Valid { - return func(t *testing.T, err error) { - require.ErrorIs(t, err, expect) - } - } - return func(t *testing.T, err error) { - if err != nil { - require.ErrorIs(t, err, verification.ErrBlobInvalid) - var me verification.VerificationMultiError - ok := errors.As(err, &me) - require.Equal(t, true, ok) - fails := me.Failures() - // we haven't performed any verification, so all the results should be this type - fmsg := make([]string, 0, len(fails)) - for k, v := range fails { - fmsg = append(fmsg, fmt.Sprintf("%s - %s", v.Error(), k.String())) - } - t.Fatal(strings.Join(fmsg, ";")) - } - } -} diff --git a/testing/spectest/shared/electra/operations/withdrawals.go b/testing/spectest/shared/electra/operations/withdrawals.go index 38fb73d8323b..51031d615d45 100644 --- a/testing/spectest/shared/electra/operations/withdrawals.go +++ b/testing/spectest/shared/electra/operations/withdrawals.go @@ -13,7 +13,7 @@ import ( ) func blockWithWithdrawals(ssz []byte) (interfaces.SignedBeaconBlock, error) { - e := &enginev1.ExecutionPayloadElectra{} + e := &enginev1.ExecutionPayloadDeneb{} if err := e.UnmarshalSSZ(ssz); err != nil { return nil, err } diff --git a/testing/spectest/shared/electra/ssz_static/ssz_static.go b/testing/spectest/shared/electra/ssz_static/ssz_static.go index 2bfeeaba6612..84b5c757e95a 100644 --- a/testing/spectest/shared/electra/ssz_static/ssz_static.go +++ b/testing/spectest/shared/electra/ssz_static/ssz_static.go @@ -37,9 +37,9 @@ func UnmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (i var obj interface{} switch folderName { case "ExecutionPayload": - obj = &enginev1.ExecutionPayloadElectra{} + obj = &enginev1.ExecutionPayloadDeneb{} case "ExecutionPayloadHeader": - obj = &enginev1.ExecutionPayloadHeaderElectra{} + obj = &enginev1.ExecutionPayloadHeaderDeneb{} case "Attestation": obj = ðpb.AttestationElectra{} case "AttestationData": diff --git a/testing/util/block.go b/testing/util/block.go index bc6f21923133..56d7bb3378fa 100644 --- a/testing/util/block.go +++ b/testing/util/block.go @@ -65,6 +65,10 @@ func DefaultBlockGenConfig() *BlockGenConfig { } } +// ---------------------------------------------------------------------------- +// Phase 0 +// ---------------------------------------------------------------------------- + // NewBeaconBlock creates a beacon block with minimum marshalable fields. func NewBeaconBlock() *ethpb.SignedBeaconBlock { return ðpb.SignedBeaconBlock{ @@ -655,6 +659,10 @@ func HydrateV1BeaconBlockBody(b *v1.BeaconBlockBody) *v1.BeaconBlockBody { return b } +// ---------------------------------------------------------------------------- +// Altair +// ---------------------------------------------------------------------------- + // HydrateV2AltairSignedBeaconBlock hydrates a signed beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. func HydrateV2AltairSignedBeaconBlock(b *v2.SignedBeaconBlockAltair) *v2.SignedBeaconBlockAltair { @@ -708,21 +716,21 @@ func HydrateV2AltairBeaconBlockBody(b *v2.BeaconBlockBodyAltair) *v2.BeaconBlock return b } -// HydrateV2BellatrixSignedBeaconBlock hydrates a signed beacon block with correct field length sizes +// HydrateSignedBeaconBlockAltair hydrates a signed beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateV2BellatrixSignedBeaconBlock(b *v2.SignedBeaconBlockBellatrix) *v2.SignedBeaconBlockBellatrix { +func HydrateSignedBeaconBlockAltair(b *ethpb.SignedBeaconBlockAltair) *ethpb.SignedBeaconBlockAltair { if b.Signature == nil { b.Signature = make([]byte, fieldparams.BLSSignatureLength) } - b.Message = HydrateV2BellatrixBeaconBlock(b.Message) + b.Block = HydrateBeaconBlockAltair(b.Block) return b } -// HydrateV2BellatrixBeaconBlock hydrates a beacon block with correct field length sizes +// HydrateBeaconBlockAltair hydrates a beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateV2BellatrixBeaconBlock(b *v2.BeaconBlockBellatrix) *v2.BeaconBlockBellatrix { +func HydrateBeaconBlockAltair(b *ethpb.BeaconBlockAltair) *ethpb.BeaconBlockAltair { if b == nil { - b = &v2.BeaconBlockBellatrix{} + b = ðpb.BeaconBlockAltair{} } if b.ParentRoot == nil { b.ParentRoot = make([]byte, fieldparams.RootLength) @@ -730,15 +738,15 @@ func HydrateV2BellatrixBeaconBlock(b *v2.BeaconBlockBellatrix) *v2.BeaconBlockBe if b.StateRoot == nil { b.StateRoot = make([]byte, fieldparams.RootLength) } - b.Body = HydrateV2BellatrixBeaconBlockBody(b.Body) + b.Body = HydrateBeaconBlockBodyAltair(b.Body) return b } -// HydrateV2BellatrixBeaconBlockBody hydrates a beacon block body with correct field length sizes +// HydrateBeaconBlockBodyAltair hydrates a beacon block body with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateV2BellatrixBeaconBlockBody(b *v2.BeaconBlockBodyBellatrix) *v2.BeaconBlockBodyBellatrix { +func HydrateBeaconBlockBodyAltair(b *ethpb.BeaconBlockBodyAltair) *ethpb.BeaconBlockBodyAltair { if b == nil { - b = &v2.BeaconBlockBodyBellatrix{} + b = ðpb.BeaconBlockBodyAltair{} } if b.RandaoReveal == nil { b.RandaoReveal = make([]byte, fieldparams.BLSSignatureLength) @@ -747,49 +755,39 @@ func HydrateV2BellatrixBeaconBlockBody(b *v2.BeaconBlockBodyBellatrix) *v2.Beaco b.Graffiti = make([]byte, fieldparams.RootLength) } if b.Eth1Data == nil { - b.Eth1Data = &v1.Eth1Data{ + b.Eth1Data = ðpb.Eth1Data{ DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, fieldparams.RootLength), } } if b.SyncAggregate == nil { - b.SyncAggregate = &v1.SyncAggregate{ + b.SyncAggregate = ðpb.SyncAggregate{ SyncCommitteeBits: make([]byte, 64), SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength), } } - if b.ExecutionPayload == nil { - b.ExecutionPayload = &enginev1.ExecutionPayload{ - ParentHash: make([]byte, fieldparams.RootLength), - FeeRecipient: make([]byte, 20), - StateRoot: make([]byte, fieldparams.RootLength), - ReceiptsRoot: make([]byte, fieldparams.RootLength), - LogsBloom: make([]byte, 256), - PrevRandao: make([]byte, fieldparams.RootLength), - ExtraData: make([]byte, 0), - BaseFeePerGas: make([]byte, fieldparams.RootLength), - BlockHash: make([]byte, fieldparams.RootLength), - Transactions: make([][]byte, 0), - } - } return b } -// HydrateSignedBeaconBlockAltair hydrates a signed beacon block with correct field length sizes +// ---------------------------------------------------------------------------- +// Bellatrix +// ---------------------------------------------------------------------------- + +// HydrateV2BellatrixSignedBeaconBlock hydrates a signed beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateSignedBeaconBlockAltair(b *ethpb.SignedBeaconBlockAltair) *ethpb.SignedBeaconBlockAltair { +func HydrateV2BellatrixSignedBeaconBlock(b *v2.SignedBeaconBlockBellatrix) *v2.SignedBeaconBlockBellatrix { if b.Signature == nil { b.Signature = make([]byte, fieldparams.BLSSignatureLength) } - b.Block = HydrateBeaconBlockAltair(b.Block) + b.Message = HydrateV2BellatrixBeaconBlock(b.Message) return b } -// HydrateBeaconBlockAltair hydrates a beacon block with correct field length sizes +// HydrateV2BellatrixBeaconBlock hydrates a beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateBeaconBlockAltair(b *ethpb.BeaconBlockAltair) *ethpb.BeaconBlockAltair { +func HydrateV2BellatrixBeaconBlock(b *v2.BeaconBlockBellatrix) *v2.BeaconBlockBellatrix { if b == nil { - b = ðpb.BeaconBlockAltair{} + b = &v2.BeaconBlockBellatrix{} } if b.ParentRoot == nil { b.ParentRoot = make([]byte, fieldparams.RootLength) @@ -797,15 +795,15 @@ func HydrateBeaconBlockAltair(b *ethpb.BeaconBlockAltair) *ethpb.BeaconBlockAlta if b.StateRoot == nil { b.StateRoot = make([]byte, fieldparams.RootLength) } - b.Body = HydrateBeaconBlockBodyAltair(b.Body) + b.Body = HydrateV2BellatrixBeaconBlockBody(b.Body) return b } -// HydrateBeaconBlockBodyAltair hydrates a beacon block body with correct field length sizes +// HydrateV2BellatrixBeaconBlockBody hydrates a beacon block body with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateBeaconBlockBodyAltair(b *ethpb.BeaconBlockBodyAltair) *ethpb.BeaconBlockBodyAltair { +func HydrateV2BellatrixBeaconBlockBody(b *v2.BeaconBlockBodyBellatrix) *v2.BeaconBlockBodyBellatrix { if b == nil { - b = ðpb.BeaconBlockBodyAltair{} + b = &v2.BeaconBlockBodyBellatrix{} } if b.RandaoReveal == nil { b.RandaoReveal = make([]byte, fieldparams.BLSSignatureLength) @@ -814,17 +812,31 @@ func HydrateBeaconBlockBodyAltair(b *ethpb.BeaconBlockBodyAltair) *ethpb.BeaconB b.Graffiti = make([]byte, fieldparams.RootLength) } if b.Eth1Data == nil { - b.Eth1Data = ðpb.Eth1Data{ + b.Eth1Data = &v1.Eth1Data{ DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, fieldparams.RootLength), } } if b.SyncAggregate == nil { - b.SyncAggregate = ðpb.SyncAggregate{ + b.SyncAggregate = &v1.SyncAggregate{ SyncCommitteeBits: make([]byte, 64), SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength), } } + if b.ExecutionPayload == nil { + b.ExecutionPayload = &enginev1.ExecutionPayload{ + ParentHash: make([]byte, fieldparams.RootLength), + FeeRecipient: make([]byte, 20), + StateRoot: make([]byte, fieldparams.RootLength), + ReceiptsRoot: make([]byte, fieldparams.RootLength), + LogsBloom: make([]byte, 256), + PrevRandao: make([]byte, fieldparams.RootLength), + ExtraData: make([]byte, 0), + BaseFeePerGas: make([]byte, fieldparams.RootLength), + BlockHash: make([]byte, fieldparams.RootLength), + Transactions: make([][]byte, 0), + } + } return b } @@ -1029,6 +1041,10 @@ func HydrateV2BlindedBeaconBlockBodyBellatrix(b *v2.BlindedBeaconBlockBodyBellat return b } +// ---------------------------------------------------------------------------- +// Capella +// ---------------------------------------------------------------------------- + // HydrateSignedBeaconBlockCapella hydrates a signed beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. func HydrateSignedBeaconBlockCapella(b *ethpb.SignedBeaconBlockCapella) *ethpb.SignedBeaconBlockCapella { @@ -1240,6 +1256,10 @@ func SaveBlock(tb assertions.AssertionTestingTB, ctx context.Context, db iface.N return wsb } +// ---------------------------------------------------------------------------- +// Deneb +// ---------------------------------------------------------------------------- + // HydrateSignedBeaconBlockDeneb hydrates a signed beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. func HydrateSignedBeaconBlockDeneb(b *ethpb.SignedBeaconBlockDeneb) *ethpb.SignedBeaconBlockDeneb { @@ -1253,19 +1273,6 @@ func HydrateSignedBeaconBlockDeneb(b *ethpb.SignedBeaconBlockDeneb) *ethpb.Signe return b } -// HydrateSignedBeaconBlockElectra hydrates a signed beacon block with correct field length sizes -// to comply with fssz marshalling and unmarshalling rules. -func HydrateSignedBeaconBlockElectra(b *ethpb.SignedBeaconBlockElectra) *ethpb.SignedBeaconBlockElectra { - if b == nil { - b = ðpb.SignedBeaconBlockElectra{} - } - if b.Signature == nil { - b.Signature = make([]byte, fieldparams.BLSSignatureLength) - } - b.Block = HydrateBeaconBlockElectra(b.Block) - return b -} - // HydrateSignedBeaconBlockContentsDeneb hydrates a signed beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. func HydrateSignedBeaconBlockContentsDeneb(b *ethpb.SignedBeaconBlockContentsDeneb) *ethpb.SignedBeaconBlockContentsDeneb { @@ -1273,13 +1280,6 @@ func HydrateSignedBeaconBlockContentsDeneb(b *ethpb.SignedBeaconBlockContentsDen return b } -// HydrateSignedBeaconBlockContentsElectra hydrates a signed beacon block with correct field length sizes -// to comply with fssz marshalling and unmarshalling rules. -func HydrateSignedBeaconBlockContentsElectra(b *ethpb.SignedBeaconBlockContentsElectra) *ethpb.SignedBeaconBlockContentsElectra { - b.Block = HydrateSignedBeaconBlockElectra(b.Block) - return b -} - // HydrateV2SignedBeaconBlockDeneb hydrates a v2 signed beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. func HydrateV2SignedBeaconBlockDeneb(b *v2.SignedBeaconBlockDeneb) *v2.SignedBeaconBlockDeneb { @@ -1306,22 +1306,6 @@ func HydrateBeaconBlockDeneb(b *ethpb.BeaconBlockDeneb) *ethpb.BeaconBlockDeneb return b } -// HydrateBeaconBlockElectra hydrates a beacon block with correct field length sizes -// to comply with fssz marshalling and unmarshalling rules. -func HydrateBeaconBlockElectra(b *ethpb.BeaconBlockElectra) *ethpb.BeaconBlockElectra { - if b == nil { - b = ðpb.BeaconBlockElectra{} - } - if b.ParentRoot == nil { - b.ParentRoot = make([]byte, fieldparams.RootLength) - } - if b.StateRoot == nil { - b.StateRoot = make([]byte, fieldparams.RootLength) - } - b.Body = HydrateBeaconBlockBodyElectra(b.Body) - return b -} - // HydrateV2BeaconBlockDeneb hydrates a v2 beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. func HydrateV2BeaconBlockDeneb(b *v2.BeaconBlockDeneb) *v2.BeaconBlockDeneb { @@ -1380,67 +1364,6 @@ func HydrateBeaconBlockBodyDeneb(b *ethpb.BeaconBlockBodyDeneb) *ethpb.BeaconBlo return b } -// HydrateBeaconBlockBodyElectra hydrates a beacon block body with correct field length sizes -// to comply with fssz marshalling and unmarshalling rules. -func HydrateBeaconBlockBodyElectra(b *ethpb.BeaconBlockBodyElectra) *ethpb.BeaconBlockBodyElectra { - if b == nil { - b = ðpb.BeaconBlockBodyElectra{} - } - if b.RandaoReveal == nil { - b.RandaoReveal = make([]byte, fieldparams.BLSSignatureLength) - } - if b.Graffiti == nil { - b.Graffiti = make([]byte, fieldparams.RootLength) - } - if b.Eth1Data == nil { - b.Eth1Data = ðpb.Eth1Data{ - DepositRoot: make([]byte, fieldparams.RootLength), - BlockHash: make([]byte, fieldparams.RootLength), - } - } - if b.SyncAggregate == nil { - b.SyncAggregate = ðpb.SyncAggregate{ - SyncCommitteeBits: make([]byte, fieldparams.SyncAggregateSyncCommitteeBytesLength), - SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength), - } - } - if b.ExecutionPayload == nil { - b.ExecutionPayload = &enginev1.ExecutionPayloadElectra{ - ParentHash: make([]byte, fieldparams.RootLength), - FeeRecipient: make([]byte, 20), - StateRoot: make([]byte, fieldparams.RootLength), - ReceiptsRoot: make([]byte, fieldparams.RootLength), - LogsBloom: make([]byte, 256), - PrevRandao: make([]byte, fieldparams.RootLength), - ExtraData: make([]byte, 0), - BaseFeePerGas: make([]byte, fieldparams.RootLength), - BlockHash: make([]byte, fieldparams.RootLength), - Transactions: make([][]byte, 0), - Withdrawals: make([]*enginev1.Withdrawal, 0), - } - } - b.ExecutionRequests = HydrateExecutionRequests(b.ExecutionRequests) - return b -} - -// HydrateExecutionRequests fills the exectution requests with the correct field -// lengths -func HydrateExecutionRequests(e *enginev1.ExecutionRequests) *enginev1.ExecutionRequests { - if e == nil { - e = &enginev1.ExecutionRequests{} - } - if e.Deposits == nil { - e.Deposits = make([]*enginev1.DepositRequest, 0) - } - if e.Withdrawals == nil { - e.Withdrawals = make([]*enginev1.WithdrawalRequest, 0) - } - if e.Consolidations == nil { - e.Consolidations = make([]*enginev1.ConsolidationRequest, 0) - } - return e -} - // HydrateV2BeaconBlockBodyDeneb hydrates a v2 beacon block body with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. func HydrateV2BeaconBlockBodyDeneb(b *v2.BeaconBlockBodyDeneb) *v2.BeaconBlockBodyDeneb { @@ -1493,16 +1416,6 @@ func HydrateSignedBlindedBeaconBlockDeneb(b *ethpb.SignedBlindedBeaconBlockDeneb return b } -// HydrateSignedBlindedBeaconBlockElectra hydrates a signed blinded beacon block with correct field length sizes -// to comply with fssz marshalling and unmarshalling rules. -func HydrateSignedBlindedBeaconBlockElectra(b *ethpb.SignedBlindedBeaconBlockElectra) *ethpb.SignedBlindedBeaconBlockElectra { - if b.Signature == nil { - b.Signature = make([]byte, fieldparams.BLSSignatureLength) - } - b.Message = HydrateBlindedBeaconBlockElectra(b.Message) - return b -} - // HydrateV2SignedBlindedBeaconBlockDeneb hydrates a signed v2 blinded beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. func HydrateV2SignedBlindedBeaconBlockDeneb(b *v2.SignedBlindedBeaconBlockDeneb) *v2.SignedBlindedBeaconBlockDeneb { @@ -1529,22 +1442,6 @@ func HydrateBlindedBeaconBlockDeneb(b *ethpb.BlindedBeaconBlockDeneb) *ethpb.Bli return b } -// HydrateBlindedBeaconBlockElectra hydrates a blinded beacon block with correct field length sizes -// to comply with fssz marshalling and unmarshalling rules. -func HydrateBlindedBeaconBlockElectra(b *ethpb.BlindedBeaconBlockElectra) *ethpb.BlindedBeaconBlockElectra { - if b == nil { - b = ðpb.BlindedBeaconBlockElectra{} - } - if b.ParentRoot == nil { - b.ParentRoot = make([]byte, fieldparams.RootLength) - } - if b.StateRoot == nil { - b.StateRoot = make([]byte, fieldparams.RootLength) - } - b.Body = HydrateBlindedBeaconBlockBodyElectra(b.Body) - return b -} - // HydrateV2BlindedBeaconBlockDeneb hydrates a v2 blinded beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. func HydrateV2BlindedBeaconBlockDeneb(b *v2.BlindedBeaconBlockDeneb) *v2.BlindedBeaconBlockDeneb { @@ -1603,11 +1500,11 @@ func HydrateBlindedBeaconBlockBodyDeneb(b *ethpb.BlindedBeaconBlockBodyDeneb) *e return b } -// HydrateBlindedBeaconBlockBodyElectra hydrates a blinded beacon block body with correct field length sizes +// HydrateV2BlindedBeaconBlockBodyDeneb hydrates a blinded v2 beacon block body with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateBlindedBeaconBlockBodyElectra(b *ethpb.BlindedBeaconBlockBodyElectra) *ethpb.BlindedBeaconBlockBodyElectra { +func HydrateV2BlindedBeaconBlockBodyDeneb(b *v2.BlindedBeaconBlockBodyDeneb) *v2.BlindedBeaconBlockBodyDeneb { if b == nil { - b = ðpb.BlindedBeaconBlockBodyElectra{} + b = &v2.BlindedBeaconBlockBodyDeneb{} } if b.RandaoReveal == nil { b.RandaoReveal = make([]byte, fieldparams.BLSSignatureLength) @@ -1616,19 +1513,19 @@ func HydrateBlindedBeaconBlockBodyElectra(b *ethpb.BlindedBeaconBlockBodyElectra b.Graffiti = make([]byte, 32) } if b.Eth1Data == nil { - b.Eth1Data = ðpb.Eth1Data{ + b.Eth1Data = &v1.Eth1Data{ DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, 32), } } if b.SyncAggregate == nil { - b.SyncAggregate = ðpb.SyncAggregate{ + b.SyncAggregate = &v1.SyncAggregate{ SyncCommitteeBits: make([]byte, fieldparams.SyncAggregateSyncCommitteeBytesLength), SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength), } } if b.ExecutionPayloadHeader == nil { - b.ExecutionPayloadHeader = &enginev1.ExecutionPayloadHeaderElectra{ + b.ExecutionPayloadHeader = &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, fieldparams.RootLength), @@ -1642,15 +1539,141 @@ func HydrateBlindedBeaconBlockBodyElectra(b *ethpb.BlindedBeaconBlockBodyElectra WithdrawalsRoot: make([]byte, fieldparams.RootLength), } } + return b +} + +// ---------------------------------------------------------------------------- +// Electra +// ---------------------------------------------------------------------------- + +// HydrateSignedBeaconBlockElectra hydrates a signed beacon block with correct field length sizes +// to comply with fssz marshalling and unmarshalling rules. +func HydrateSignedBeaconBlockElectra(b *ethpb.SignedBeaconBlockElectra) *ethpb.SignedBeaconBlockElectra { + if b == nil { + b = ðpb.SignedBeaconBlockElectra{} + } + if b.Signature == nil { + b.Signature = make([]byte, fieldparams.BLSSignatureLength) + } + b.Block = HydrateBeaconBlockElectra(b.Block) + return b +} + +// HydrateSignedBeaconBlockContentsElectra hydrates a signed beacon block with correct field length sizes +// to comply with fssz marshalling and unmarshalling rules. +func HydrateSignedBeaconBlockContentsElectra(b *ethpb.SignedBeaconBlockContentsElectra) *ethpb.SignedBeaconBlockContentsElectra { + b.Block = HydrateSignedBeaconBlockElectra(b.Block) + return b +} + +// HydrateBeaconBlockElectra hydrates a beacon block with correct field length sizes +// to comply with fssz marshalling and unmarshalling rules. +func HydrateBeaconBlockElectra(b *ethpb.BeaconBlockElectra) *ethpb.BeaconBlockElectra { + if b == nil { + b = ðpb.BeaconBlockElectra{} + } + if b.ParentRoot == nil { + b.ParentRoot = make([]byte, fieldparams.RootLength) + } + if b.StateRoot == nil { + b.StateRoot = make([]byte, fieldparams.RootLength) + } + b.Body = HydrateBeaconBlockBodyElectra(b.Body) + return b +} + +// HydrateBeaconBlockBodyElectra hydrates a beacon block body with correct field length sizes +// to comply with fssz marshalling and unmarshalling rules. +func HydrateBeaconBlockBodyElectra(b *ethpb.BeaconBlockBodyElectra) *ethpb.BeaconBlockBodyElectra { + if b == nil { + b = ðpb.BeaconBlockBodyElectra{} + } + if b.RandaoReveal == nil { + b.RandaoReveal = make([]byte, fieldparams.BLSSignatureLength) + } + if b.Graffiti == nil { + b.Graffiti = make([]byte, fieldparams.RootLength) + } + if b.Eth1Data == nil { + b.Eth1Data = ðpb.Eth1Data{ + DepositRoot: make([]byte, fieldparams.RootLength), + BlockHash: make([]byte, fieldparams.RootLength), + } + } + if b.SyncAggregate == nil { + b.SyncAggregate = ðpb.SyncAggregate{ + SyncCommitteeBits: make([]byte, fieldparams.SyncAggregateSyncCommitteeBytesLength), + SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength), + } + } + if b.ExecutionPayload == nil { + b.ExecutionPayload = &enginev1.ExecutionPayloadDeneb{ + ParentHash: make([]byte, fieldparams.RootLength), + FeeRecipient: make([]byte, 20), + StateRoot: make([]byte, fieldparams.RootLength), + ReceiptsRoot: make([]byte, fieldparams.RootLength), + LogsBloom: make([]byte, 256), + PrevRandao: make([]byte, fieldparams.RootLength), + ExtraData: make([]byte, 0), + BaseFeePerGas: make([]byte, fieldparams.RootLength), + BlockHash: make([]byte, fieldparams.RootLength), + Transactions: make([][]byte, 0), + Withdrawals: make([]*enginev1.Withdrawal, 0), + } + } b.ExecutionRequests = HydrateExecutionRequests(b.ExecutionRequests) return b } -// HydrateV2BlindedBeaconBlockBodyDeneb hydrates a blinded v2 beacon block body with correct field length sizes +// HydrateExecutionRequests fills the exectution requests with the correct field +// lengths +func HydrateExecutionRequests(e *enginev1.ExecutionRequests) *enginev1.ExecutionRequests { + if e == nil { + e = &enginev1.ExecutionRequests{} + } + if e.Deposits == nil { + e.Deposits = make([]*enginev1.DepositRequest, 0) + } + if e.Withdrawals == nil { + e.Withdrawals = make([]*enginev1.WithdrawalRequest, 0) + } + if e.Consolidations == nil { + e.Consolidations = make([]*enginev1.ConsolidationRequest, 0) + } + return e +} + +// HydrateSignedBlindedBeaconBlockElectra hydrates a signed blinded beacon block with correct field length sizes // to comply with fssz marshalling and unmarshalling rules. -func HydrateV2BlindedBeaconBlockBodyDeneb(b *v2.BlindedBeaconBlockBodyDeneb) *v2.BlindedBeaconBlockBodyDeneb { +func HydrateSignedBlindedBeaconBlockElectra(b *ethpb.SignedBlindedBeaconBlockElectra) *ethpb.SignedBlindedBeaconBlockElectra { + if b.Signature == nil { + b.Signature = make([]byte, fieldparams.BLSSignatureLength) + } + b.Message = HydrateBlindedBeaconBlockElectra(b.Message) + return b +} + +// HydrateBlindedBeaconBlockElectra hydrates a blinded beacon block with correct field length sizes +// to comply with fssz marshalling and unmarshalling rules. +func HydrateBlindedBeaconBlockElectra(b *ethpb.BlindedBeaconBlockElectra) *ethpb.BlindedBeaconBlockElectra { if b == nil { - b = &v2.BlindedBeaconBlockBodyDeneb{} + b = ðpb.BlindedBeaconBlockElectra{} + } + if b.ParentRoot == nil { + b.ParentRoot = make([]byte, fieldparams.RootLength) + } + if b.StateRoot == nil { + b.StateRoot = make([]byte, fieldparams.RootLength) + } + b.Body = HydrateBlindedBeaconBlockBodyElectra(b.Body) + return b +} + +// HydrateBlindedBeaconBlockBodyElectra hydrates a blinded beacon block body with correct field length sizes +// to comply with fssz marshalling and unmarshalling rules. +func HydrateBlindedBeaconBlockBodyElectra(b *ethpb.BlindedBeaconBlockBodyElectra) *ethpb.BlindedBeaconBlockBodyElectra { + if b == nil { + b = ðpb.BlindedBeaconBlockBodyElectra{} } if b.RandaoReveal == nil { b.RandaoReveal = make([]byte, fieldparams.BLSSignatureLength) @@ -1659,13 +1682,13 @@ func HydrateV2BlindedBeaconBlockBodyDeneb(b *v2.BlindedBeaconBlockBodyDeneb) *v2 b.Graffiti = make([]byte, 32) } if b.Eth1Data == nil { - b.Eth1Data = &v1.Eth1Data{ + b.Eth1Data = ðpb.Eth1Data{ DepositRoot: make([]byte, fieldparams.RootLength), BlockHash: make([]byte, 32), } } if b.SyncAggregate == nil { - b.SyncAggregate = &v1.SyncAggregate{ + b.SyncAggregate = ðpb.SyncAggregate{ SyncCommitteeBits: make([]byte, fieldparams.SyncAggregateSyncCommitteeBytesLength), SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength), } @@ -1685,5 +1708,6 @@ func HydrateV2BlindedBeaconBlockBodyDeneb(b *v2.BlindedBeaconBlockBodyDeneb) *v2 WithdrawalsRoot: make([]byte, fieldparams.RootLength), } } + b.ExecutionRequests = HydrateExecutionRequests(b.ExecutionRequests) return b } diff --git a/testing/util/electra.go b/testing/util/electra.go index 0c0959bdbd82..1b785476d61f 100644 --- a/testing/util/electra.go +++ b/testing/util/electra.go @@ -47,7 +47,7 @@ type electraBlockGenerator struct { sk bls.SecretKey proposer primitives.ValidatorIndex valRoot []byte - payload *enginev1.ExecutionPayloadElectra + payload *enginev1.ExecutionPayloadDeneb } func WithElectraProposerSigning(idx primitives.ValidatorIndex, sk bls.SecretKey, valRoot []byte) ElectraBlockGeneratorOption { @@ -59,7 +59,7 @@ func WithElectraProposerSigning(idx primitives.ValidatorIndex, sk bls.SecretKey, } } -func WithElectraPayload(p *enginev1.ExecutionPayloadElectra) ElectraBlockGeneratorOption { +func WithElectraPayload(p *enginev1.ExecutionPayloadDeneb) ElectraBlockGeneratorOption { return func(g *electraBlockGenerator) { g.payload = p } @@ -96,7 +96,7 @@ func GenerateTestElectraBlockWithSidecar(t *testing.T, parent [32]byte, slot pri logsBloom := bytesutil.PadTo([]byte("logs"), fieldparams.LogsBloomLength) receiptsRoot := bytesutil.PadTo([]byte("receiptsRoot"), fieldparams.RootLength) parentHash := bytesutil.PadTo([]byte("parentHash"), fieldparams.RootLength) - g.payload = &enginev1.ExecutionPayloadElectra{ + g.payload = &enginev1.ExecutionPayloadDeneb{ ParentHash: parentHash, FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), StateRoot: stateRoot, diff --git a/testing/util/electra_block.go b/testing/util/electra_block.go index acd4f8c8146d..8ba401722612 100644 --- a/testing/util/electra_block.go +++ b/testing/util/electra_block.go @@ -172,7 +172,7 @@ func GenerateFullBlockElectra( return nil, err } blockHash := indexToHash(uint64(slot)) - newExecutionPayloadElectra := &v1.ExecutionPayloadElectra{ + newExecutionPayloadElectra := &v1.ExecutionPayloadDeneb{ ParentHash: parentExecution.BlockHash(), FeeRecipient: make([]byte, 20), StateRoot: params.BeaconConfig().ZeroHash[:], diff --git a/testing/util/electra_state.go b/testing/util/electra_state.go index 551af5536508..3688734a41d0 100644 --- a/testing/util/electra_state.go +++ b/testing/util/electra_state.go @@ -96,7 +96,7 @@ func emptyGenesisStateElectra() (state.BeaconState, error) { Eth1DataVotes: []*ethpb.Eth1Data{}, Eth1DepositIndex: 0, - LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderElectra{}, + LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderDeneb{}, DepositBalanceToConsume: primitives.Gwei(0), ExitBalanceToConsume: primitives.Gwei(0), @@ -226,7 +226,7 @@ func buildGenesisBeaconStateElectra(genesisTime uint64, preState state.BeaconSta SyncCommitteeBits: scBits[:], SyncCommitteeSignature: make([]byte, 96), }, - ExecutionPayload: &enginev1.ExecutionPayloadElectra{ + ExecutionPayload: &enginev1.ExecutionPayloadDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), @@ -273,7 +273,7 @@ func buildGenesisBeaconStateElectra(genesisTime uint64, preState state.BeaconSta AggregatePubkey: aggregated.Marshal(), } - st.LatestExecutionPayloadHeader = &enginev1.ExecutionPayloadHeaderElectra{ + st.LatestExecutionPayloadHeader = &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32), diff --git a/testing/util/lightclient.go b/testing/util/lightclient.go index 0cbb0542f9ab..571a39f6b957 100644 --- a/testing/util/lightclient.go +++ b/testing/util/lightclient.go @@ -15,7 +15,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/encoding/ssz" v11 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" - pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/runtime/version" "github.com/prysmaticlabs/prysm/v5/testing/require" ) @@ -894,7 +893,7 @@ func (l *TestLightClient) CheckAttestedHeader(header interfaces.LightClientHeade } } -func (l *TestLightClient) CheckSyncAggregate(sa *pb.SyncAggregate) { +func (l *TestLightClient) CheckSyncAggregate(sa *ethpb.SyncAggregate) { syncAggregate, err := l.Block.Block().Body().SyncAggregate() require.NoError(l.T, err) require.DeepSSZEqual(l.T, syncAggregate.SyncCommitteeBits, sa.SyncCommitteeBits, "SyncAggregate bits is not equal") diff --git a/testing/util/state.go b/testing/util/state.go index 2c1f08c756b8..cdc7541343d3 100644 --- a/testing/util/state.go +++ b/testing/util/state.go @@ -424,7 +424,7 @@ func NewBeaconStateElectra(options ...func(state *ethpb.BeaconStateElectra) erro Pubkeys: pubkeys, AggregatePubkey: make([]byte, 48), }, - LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderElectra{ + LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeaderDeneb{ ParentHash: make([]byte, 32), FeeRecipient: make([]byte, 20), StateRoot: make([]byte, 32),