From a265cf08faed609ca6c0d7b59b0f9514e2e3943e Mon Sep 17 00:00:00 2001 From: james-prysm <90280386+james-prysm@users.noreply.github.com> Date: Fri, 1 Nov 2024 14:11:12 -0500 Subject: [PATCH] adding in a check to make sure duplicates are now allowed (#14601) --- proto/engine/v1/electra.go | 8 ++++---- proto/engine/v1/electra_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/proto/engine/v1/electra.go b/proto/engine/v1/electra.go index 628373fe1c..c6e3af5554 100644 --- a/proto/engine/v1/electra.go +++ b/proto/engine/v1/electra.go @@ -28,16 +28,16 @@ const ( func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequests, error) { requests := &ExecutionRequests{} - var prevTypeNum uint8 + var prevTypeNum *uint8 for i := range ebe.ExecutionRequests { requestType, requestListInSSZBytes, err := decodeExecutionRequest(ebe.ExecutionRequests[i]) if err != nil { return nil, err } - if prevTypeNum > requestType { - return nil, errors.New("invalid execution request type order, requests should be in sorted order") + if prevTypeNum != nil && *prevTypeNum >= requestType { + return nil, errors.New("invalid execution request type order or duplicate requests, requests should be in sorted order and unique") } - prevTypeNum = requestType + prevTypeNum = &requestType switch requestType { case DepositRequestType: drs, err := unmarshalDeposits(requestListInSSZBytes) diff --git a/proto/engine/v1/electra_test.go b/proto/engine/v1/electra_test.go index e6aa2c783d..bab9f3912b 100644 --- a/proto/engine/v1/electra_test.go +++ b/proto/engine/v1/electra_test.go @@ -83,6 +83,36 @@ func TestGetDecodedExecutionRequests(t *testing.T) { _, err = ebe.GetDecodedExecutionRequests() require.ErrorContains(t, "invalid execution request, length less than 1", err) }) + t.Run("a duplicate request should fail", func(t *testing.T) { + withdrawalRequestBytes, err := hexutil.Decode("0x6400000000000000000000000000000000000000" + + "6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040597307000000") + require.NoError(t, err) + withdrawalRequestBytes2, err := hexutil.Decode("0x6400000000000000000000000000000000000000" + + "6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040597307000000") + require.NoError(t, err) + ebe := &enginev1.ExecutionBundleElectra{ + ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.WithdrawalRequestType)}, withdrawalRequestBytes...), append([]byte{uint8(enginev1.WithdrawalRequestType)}, withdrawalRequestBytes2...)}, + } + _, err = ebe.GetDecodedExecutionRequests() + require.ErrorContains(t, "requests should be in sorted order and unique", err) + }) + t.Run("a duplicate withdrawals ( non 0 request type )request should fail", func(t *testing.T) { + depositRequestBytes, err := hexutil.Decode("0x610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "620000000000000000000000000000000000000000000000000000000000000000" + + "4059730700000063000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "00000000000000000000000000000000000000000000000000000000000000000000000000000000") + require.NoError(t, err) + depositRequestBytes2, err := hexutil.Decode("0x610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "620000000000000000000000000000000000000000000000000000000000000000" + + "4059730700000063000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "00000000000000000000000000000000000000000000000000000000000000000000000000000000") + require.NoError(t, err) + ebe := &enginev1.ExecutionBundleElectra{ + ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes...), append([]byte{uint8(enginev1.DepositRequestType)}, depositRequestBytes2...)}, + } + _, err = ebe.GetDecodedExecutionRequests() + require.ErrorContains(t, "requests should be in sorted order and unique", err) + }) t.Run("If a request type is provided, but the request list is shorter than the ssz of 1 request we error", func(t *testing.T) { consolidationRequestBytes, err := hexutil.Decode("0x6600000000000000000000000000000000000000" + "670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +