beacon/engine: check for empty requests (#31010)

According to
https://github.com/ethereum/execution-apis/blob/main/src/engine/prague.md#engine_newpayloadv4:

> Elements of the list MUST be ordered by request_type in ascending
order. Elements with empty request_data MUST be excluded from the list.

---------

Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
pull/31037/head
Sina M 2 weeks ago committed by GitHub
parent 8dfad579e9
commit 9b68875d68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 23
      eth/catalyst/api.go

@ -638,6 +638,9 @@ func (api *ConsensusAPI) NewPayloadV4(params engine.ExecutableData, versionedHas
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.UnsupportedFork.With(errors.New("newPayloadV4 must only be called for prague payloads")) return engine.PayloadStatusV1{Status: engine.INVALID}, engine.UnsupportedFork.With(errors.New("newPayloadV4 must only be called for prague payloads"))
} }
requests := convertRequests(executionRequests) requests := convertRequests(executionRequests)
if err := validateRequests(requests); err != nil {
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(err)
}
return api.newPayload(params, versionedHashes, beaconRoot, requests, false) return api.newPayload(params, versionedHashes, beaconRoot, requests, false)
} }
@ -727,6 +730,9 @@ func (api *ConsensusAPI) NewPayloadWithWitnessV4(params engine.ExecutableData, v
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.UnsupportedFork.With(errors.New("newPayloadWithWitnessV4 must only be called for prague payloads")) return engine.PayloadStatusV1{Status: engine.INVALID}, engine.UnsupportedFork.With(errors.New("newPayloadWithWitnessV4 must only be called for prague payloads"))
} }
requests := convertRequests(executionRequests) requests := convertRequests(executionRequests)
if err := validateRequests(requests); err != nil {
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(err)
}
return api.newPayload(params, versionedHashes, beaconRoot, requests, true) return api.newPayload(params, versionedHashes, beaconRoot, requests, true)
} }
@ -1287,3 +1293,20 @@ func convertRequests(hex []hexutil.Bytes) [][]byte {
} }
return req return req
} }
// validateRequests checks that requests are ordered by their type and are not empty.
func validateRequests(requests [][]byte) error {
var last byte
for _, req := range requests {
// No empty requests.
if len(req) < 2 {
return fmt.Errorf("empty request: %v", req)
}
// Check that requests are ordered by their type.
if req[0] < last {
return fmt.Errorf("invalid request order: %v", req)
}
last = req[0]
}
return nil
}

Loading…
Cancel
Save