mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
adding in a check to make sure duplicates are now allowed (#14601)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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" +
|
||||
|
||||
Reference in New Issue
Block a user