Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ace832c
implementing new decisions around exectuion requests
james-prysm Oct 24, 2024
0884e0e
fixing test fixture
james-prysm Oct 25, 2024
bd26494
adding in more edge case checks and tests
james-prysm Oct 25, 2024
d932f6e
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm Oct 25, 2024
e0ffd1a
changelog
james-prysm Oct 25, 2024
3c7cbf7
fixing unsafe type cast
james-prysm Oct 25, 2024
2852bcc
Update beacon-chain/execution/engine_client_test.go
james-prysm Oct 25, 2024
3cdb4ad
Update proto/engine/v1/electra.go
james-prysm Oct 25, 2024
9f7997b
Update proto/engine/v1/electra.go
james-prysm Oct 25, 2024
14f5f0a
Update proto/engine/v1/electra.go
james-prysm Oct 25, 2024
4b22e25
Update proto/engine/v1/electra.go
james-prysm Oct 25, 2024
e7ba3b1
Update proto/engine/v1/electra_test.go
james-prysm Oct 25, 2024
b077cfd
Update proto/engine/v1/electra_test.go
james-prysm Oct 25, 2024
b48d359
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm Oct 28, 2024
8f62720
updating based on preston's feedback and adding more tests for edge c…
james-prysm Oct 28, 2024
44de042
adding more edgecases, and unit tests
james-prysm Oct 28, 2024
c879cfb
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm Oct 28, 2024
ace1aa5
fixing tests
james-prysm Oct 28, 2024
dc7eebd
missed some export changes
james-prysm Oct 28, 2024
8bf061b
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm Oct 28, 2024
c69ac6c
adding more tests
james-prysm Oct 28, 2024
cbdc3ad
Update proto/engine/v1/electra.go
james-prysm Oct 28, 2024
b077638
reducing complexity of function based on feedback
james-prysm Oct 28, 2024
14c629b
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm Oct 31, 2024
46b8205
Merge branch 'develop' into execution-requests-serialization-changes
james-prysm Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Use read only validator for core processing to avoid unnecessary copying.
- Use ROBlock across block processing pipeline.
- Added missing Eth-Consensus-Version headers to GetBlockAttestationsV2 and GetAttesterSlashingsV2 endpoints.
- `engine_newPayloadV4`,`engine_getPayloadV4` are changes due to new execution request serialization decisions, [PR](https://github.com/prysmaticlabs/prysm/pull/14580)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/execution/engine_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ func fixturesStruct() *payloadFixtures {
Proofs: []hexutil.Bytes{[]byte("proof1"), []byte("proof2")},
Blobs: []hexutil.Bytes{{'a'}, {'b'}},
},
ExecutionRequests: []hexutil.Bytes{depositRequestBytes, withdrawalRequestBytes, consolidationRequestBytes},
ExecutionRequests: []hexutil.Bytes{append([]byte{0}, depositRequestBytes...), append([]byte{1}, withdrawalRequestBytes...), append([]byte{2}, consolidationRequestBytes...)},
}
parent := bytesutil.PadTo([]byte("parentHash"), fieldparams.RootLength)
sha3Uncles := bytesutil.PadTo([]byte("sha3Uncles"), fieldparams.RootLength)
Expand Down
101 changes: 64 additions & 37 deletions proto/engine/v1/electra.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,45 @@ var (
crSize = crExample.SizeSSZ()
)

const LenExecutionRequestsElectra = 3
const (
depositRequestType = 0
withdrawalRequestType = 1
consolidationRequestType = 2
)

func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequests, error) {
requests := &ExecutionRequests{}

if len(ebe.ExecutionRequests) != LenExecutionRequestsElectra /* types of requests */ {
return nil, errors.Errorf("invalid execution request size: %d", len(ebe.ExecutionRequests))
}

// deposit requests
drs, err := unmarshalItems(ebe.ExecutionRequests[0], drSize, func() *DepositRequest { return &DepositRequest{} })
if err != nil {
return nil, err
}
requests.Deposits = drs

// withdrawal requests
wrs, err := unmarshalItems(ebe.ExecutionRequests[1], wrSize, func() *WithdrawalRequest { return &WithdrawalRequest{} })
if err != nil {
return nil, err
}
requests.Withdrawals = wrs

// consolidation requests
crs, err := unmarshalItems(ebe.ExecutionRequests[2], crSize, func() *ConsolidationRequest { return &ConsolidationRequest{} })
if err != nil {
return nil, err
var prevTypeNum uint8
for i := range ebe.ExecutionRequests {
requestType := ebe.ExecutionRequests[i][0]
if prevTypeNum > requestType {
return nil, errors.New("invalid execution request type order, requests should be in sorted order")
}
prevTypeNum = requestType
requestListInSSZBytes := ebe.ExecutionRequests[i][1:]
switch requestType {
case depositRequestType:
drs, err := unmarshalItems(requestListInSSZBytes, drSize, func() *DepositRequest { return &DepositRequest{} })
if err != nil {
return nil, err
}
requests.Deposits = drs
case withdrawalRequestType:
wrs, err := unmarshalItems(requestListInSSZBytes, wrSize, func() *WithdrawalRequest { return &WithdrawalRequest{} })
if err != nil {
return nil, err
}
requests.Withdrawals = wrs
case consolidationRequestType:
crs, err := unmarshalItems(requestListInSSZBytes, crSize, func() *ConsolidationRequest { return &ConsolidationRequest{} })
if err != nil {
return nil, err
}
requests.Consolidations = crs
default:
return nil, errors.Errorf("unsupported request type %d", requestType)
}
}
requests.Consolidations = crs

return requests, nil
}
Expand All @@ -57,21 +67,38 @@ func EncodeExecutionRequests(requests *ExecutionRequests) ([]hexutil.Bytes, erro
return nil, errors.New("invalid execution requests")
}

drBytes, err := marshalItems(requests.Deposits)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal deposit requests")
}
requestsData := make([]hexutil.Bytes, 0)

wrBytes, err := marshalItems(requests.Withdrawals)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal withdrawal requests")
// request types MUST be in sorted order starting from 0
if len(requests.Deposits) > 0 {
drBytes, err := marshalItems(requests.Deposits)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal deposit requests")
}
requestData := []byte{0}
requestData = append(requestData, drBytes...)
requestsData = append(requestsData, requestData)
}

crBytes, err := marshalItems(requests.Consolidations)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal consolidation requests")
if len(requests.Withdrawals) > 0 {
wrBytes, err := marshalItems(requests.Withdrawals)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal withdrawal requests")
}
requestData := []byte{1}
requestData = append(requestData, wrBytes...)
requestsData = append(requestsData, requestData)
}
return []hexutil.Bytes{drBytes, wrBytes, crBytes}, nil
if len(requests.Consolidations) > 0 {
crBytes, err := marshalItems(requests.Consolidations)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal consolidation requests")
}
requestData := []byte{2}
requestData = append(requestData, crBytes...)
requestsData = append(requestsData, requestData)
}

return requestsData, nil
}

type sszUnmarshaler interface {
Expand Down
48 changes: 48 additions & 0 deletions proto/engine/v1/electra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,54 @@ import (

var depositRequestsSSZHex = "0x706b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000077630000000000000000000000000000000000000000000000000000000000007b00000000000000736967000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c801000000000000706b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000776300000000000000000000000000000000000000000000000000000000000090010000000000007369670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000"

func TestGetDecodedExecutionRequests(t *testing.T) {
t.Run("Excluded requests still decode successfully", func(t *testing.T) {
depositRequestBytes, err := hexutil.Decode("0x610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"620000000000000000000000000000000000000000000000000000000000000000" +
"4059730700000063000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"00000000000000000000000000000000000000000000000000000000000000000000000000000000")
require.NoError(t, err)
consolidationRequestBytes, err := hexutil.Decode("0x6600000000000000000000000000000000000000" +
"670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
require.NoError(t, err)
ebe := &enginev1.ExecutionBundleElectra{
ExecutionRequests: [][]byte{append([]byte{0}, depositRequestBytes...), append([]byte{2}, consolidationRequestBytes...)},
}
requests, err := ebe.GetDecodedExecutionRequests()
require.NoError(t, err)
require.Equal(t, len(requests.Deposits), 1)
require.Equal(t, len(requests.Withdrawals), 0)
require.Equal(t, len(requests.Consolidations), 1)
})
t.Run("Decode execution requests should fail if ordering is not sorted", func(t *testing.T) {
depositRequestBytes, err := hexutil.Decode("0x610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"620000000000000000000000000000000000000000000000000000000000000000" +
"4059730700000063000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"00000000000000000000000000000000000000000000000000000000000000000000000000000000")
require.NoError(t, err)
consolidationRequestBytes, err := hexutil.Decode("0x6600000000000000000000000000000000000000" +
"670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
require.NoError(t, err)
ebe := &enginev1.ExecutionBundleElectra{
ExecutionRequests: [][]byte{append([]byte{2}, consolidationRequestBytes...), append([]byte{0}, depositRequestBytes...)},
}
_, err = ebe.GetDecodedExecutionRequests()
require.ErrorContains(t, "invalid execution request type order", err)
})
}

func TestEncodeExecutionRequests(t *testing.T) {
t.Run("Empty execution requests should return an empty response and not nil", func(t *testing.T) {
ebe := &enginev1.ExecutionRequests{}
b, err := enginev1.EncodeExecutionRequests(ebe)
require.NoError(t, err)
require.NotNil(t, b)
require.Equal(t, len(b), 0)
})
}

func TestUnmarshalItems_OK(t *testing.T) {
drb, err := hexutil.Decode(depositRequestsSSZHex)
require.NoError(t, err)
Expand Down
Loading