Skip to content

Commit fc12dbe

Browse files
authored
eth/catalyst: fix validation of type 0 request (#31103)
I caught this error on Hive. It was introduced by #31071 because after adding the equality check the request type 0 will be rejected.
1 parent 8daefeb commit fc12dbe

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

eth/catalyst/api.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,18 +1272,16 @@ func convertRequests(hex []hexutil.Bytes) [][]byte {
12721272

12731273
// validateRequests checks that requests are ordered by their type and are not empty.
12741274
func validateRequests(requests [][]byte) error {
1275-
var last byte
1276-
for _, req := range requests {
1275+
for i, req := range requests {
12771276
// No empty requests.
12781277
if len(req) < 2 {
12791278
return fmt.Errorf("empty request: %v", req)
12801279
}
12811280
// Check that requests are ordered by their type.
12821281
// Each type must appear only once.
1283-
if req[0] <= last {
1282+
if i > 0 && req[0] <= requests[i-1][0] {
12841283
return fmt.Errorf("invalid request order: %v", req)
12851284
}
1286-
last = req[0]
12871285
}
12881286
return nil
12891287
}

eth/catalyst/api_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,3 +1737,61 @@ func TestGetClientVersion(t *testing.T) {
17371737
t.Fatalf("client info does match expected, got %s", info.String())
17381738
}
17391739
}
1740+
1741+
func TestValidateRequests(t *testing.T) {
1742+
tests := []struct {
1743+
name string
1744+
requests [][]byte
1745+
wantErr bool
1746+
}{
1747+
{
1748+
name: "valid ascending",
1749+
requests: [][]byte{
1750+
{0x00, 0xAA, 0xBB}, // type 0x00
1751+
{0x01, 0xCC}, // type 0x01
1752+
{0x02, 0xDD}, // type 0x02
1753+
},
1754+
wantErr: false,
1755+
},
1756+
{
1757+
name: "empty request (too short)",
1758+
requests: [][]byte{
1759+
{0x00}, // only 1 byte: type with no data
1760+
},
1761+
wantErr: true,
1762+
},
1763+
{
1764+
name: "duplicate type",
1765+
requests: [][]byte{
1766+
{0x00, 0x11},
1767+
{0x01, 0x22},
1768+
{0x01, 0x33}, // duplicate type 0x01
1769+
},
1770+
wantErr: true,
1771+
},
1772+
{
1773+
name: "out of order",
1774+
requests: [][]byte{
1775+
{0x01, 0xAA}, // type 0x01
1776+
{0x00, 0xBB}, // type 0x00 out of order (should be ascending)
1777+
},
1778+
wantErr: true,
1779+
},
1780+
{
1781+
name: "single request valid",
1782+
requests: [][]byte{
1783+
{0x01, 0xAB},
1784+
},
1785+
wantErr: false,
1786+
},
1787+
}
1788+
for _, tt := range tests {
1789+
t.Run(tt.name, func(t *testing.T) {
1790+
err := validateRequests(tt.requests)
1791+
if (err != nil) != tt.wantErr {
1792+
t.Errorf("validateRequests(%v) error = %v, wantErr = %v",
1793+
tt.requests, err, tt.wantErr)
1794+
}
1795+
})
1796+
}
1797+
}

0 commit comments

Comments
 (0)