Skip to content

Commit e0e7354

Browse files
authored
improving the error messages for execution request deserialization (#14962)
* improving the error messages for execution request deserialization * changelog
1 parent 0f86a16 commit e0e7354

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Changed
2+
3+
- execution requests errors on ssz length have been improved

proto/engine/v1/electra.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,33 @@ func (ebe *ExecutionBundleElectra) GetDecodedExecutionRequests() (*ExecutionRequ
6363

6464
func unmarshalDeposits(requestListInSSZBytes []byte) ([]*DepositRequest, error) {
6565
if len(requestListInSSZBytes) < drSize {
66-
return nil, fmt.Errorf("invalid deposit requests length, requests should be at least the size of %d", drSize)
66+
return nil, fmt.Errorf("invalid deposit requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), drSize)
6767
}
68-
if uint64(len(requestListInSSZBytes)) > uint64(drSize)*params.BeaconConfig().MaxDepositRequestsPerPayload {
69-
return nil, fmt.Errorf("invalid deposit requests length, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), drSize)
68+
maxSSZsize := uint64(drSize) * params.BeaconConfig().MaxDepositRequestsPerPayload
69+
if uint64(len(requestListInSSZBytes)) > maxSSZsize {
70+
return nil, fmt.Errorf("invalid deposit requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize)
7071
}
7172
return unmarshalItems(requestListInSSZBytes, drSize, func() *DepositRequest { return &DepositRequest{} })
7273
}
7374

7475
func unmarshalWithdrawals(requestListInSSZBytes []byte) ([]*WithdrawalRequest, error) {
7576
if len(requestListInSSZBytes) < wrSize {
76-
return nil, fmt.Errorf("invalid withdrawal requests length, requests should be at least the size of %d", wrSize)
77+
return nil, fmt.Errorf("invalid withdrawal requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), wrSize)
7778
}
78-
if uint64(len(requestListInSSZBytes)) > uint64(wrSize)*params.BeaconConfig().MaxWithdrawalRequestsPerPayload {
79-
return nil, fmt.Errorf("invalid withdrawal requests length, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), wrSize)
79+
maxSSZsize := uint64(wrSize) * params.BeaconConfig().MaxWithdrawalRequestsPerPayload
80+
if uint64(len(requestListInSSZBytes)) > maxSSZsize {
81+
return nil, fmt.Errorf("invalid withdrawal requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize)
8082
}
8183
return unmarshalItems(requestListInSSZBytes, wrSize, func() *WithdrawalRequest { return &WithdrawalRequest{} })
8284
}
8385

8486
func unmarshalConsolidations(requestListInSSZBytes []byte) ([]*ConsolidationRequest, error) {
8587
if len(requestListInSSZBytes) < crSize {
86-
return nil, fmt.Errorf("invalid consolidation requests length, requests should be at least the size of %d", crSize)
88+
return nil, fmt.Errorf("invalid consolidation requests SSZ size, got %d expected at least %d", len(requestListInSSZBytes), crSize)
8789
}
88-
if uint64(len(requestListInSSZBytes)) > uint64(crSize)*params.BeaconConfig().MaxConsolidationsRequestsPerPayload {
89-
return nil, fmt.Errorf("invalid consolidation requests length, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), crSize)
90+
maxSSZsize := uint64(crSize) * params.BeaconConfig().MaxConsolidationsRequestsPerPayload
91+
if uint64(len(requestListInSSZBytes)) > maxSSZsize {
92+
return nil, fmt.Errorf("invalid consolidation requests SSZ size, requests should not be more than the max per payload, got %d max %d", len(requestListInSSZBytes), maxSSZsize)
9093
}
9194
return unmarshalItems(requestListInSSZBytes, crSize, func() *ConsolidationRequest { return &ConsolidationRequest{} })
9295
}

proto/engine/v1/electra_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
122122
ExecutionRequests: [][]byte{append([]byte{uint8(enginev1.DepositRequestType)}, []byte{}...), append([]byte{uint8(enginev1.ConsolidationRequestType)}, consolidationRequestBytes...)},
123123
}
124124
_, err = ebe.GetDecodedExecutionRequests()
125-
require.ErrorContains(t, "invalid deposit requests length", err)
125+
require.ErrorContains(t, "invalid deposit requests SSZ size", err)
126126
})
127127
t.Run("If deposit requests are over the max allowed per payload then we should error", func(t *testing.T) {
128128
requests := make([]*enginev1.DepositRequest, params.BeaconConfig().MaxDepositRequestsPerPayload+1)
@@ -143,7 +143,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
143143
},
144144
}
145145
_, err = ebe.GetDecodedExecutionRequests()
146-
require.ErrorContains(t, "invalid deposit requests length, requests should not be more than the max per payload", err)
146+
require.ErrorContains(t, "invalid deposit requests SSZ size, requests should not be more than the max per payload", err)
147147
})
148148
t.Run("If withdrawal requests are over the max allowed per payload then we should error", func(t *testing.T) {
149149
requests := make([]*enginev1.WithdrawalRequest, params.BeaconConfig().MaxWithdrawalRequestsPerPayload+1)
@@ -162,7 +162,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
162162
},
163163
}
164164
_, err = ebe.GetDecodedExecutionRequests()
165-
require.ErrorContains(t, "invalid withdrawal requests length, requests should not be more than the max per payload", err)
165+
require.ErrorContains(t, "invalid withdrawal requests SSZ size, requests should not be more than the max per payload", err)
166166
})
167167
t.Run("If consolidation requests are over the max allowed per payload then we should error", func(t *testing.T) {
168168
requests := make([]*enginev1.ConsolidationRequest, params.BeaconConfig().MaxConsolidationsRequestsPerPayload+1)
@@ -181,7 +181,7 @@ func TestGetDecodedExecutionRequests(t *testing.T) {
181181
},
182182
}
183183
_, err = ebe.GetDecodedExecutionRequests()
184-
require.ErrorContains(t, "invalid consolidation requests length, requests should not be more than the max per payload", err)
184+
require.ErrorContains(t, "invalid consolidation requests SSZ size, requests should not be more than the max per payload", err)
185185
})
186186
}
187187

0 commit comments

Comments
 (0)