From a3bb5a059612bb0c5885d102831e6e0e2c9bc00b Mon Sep 17 00:00:00 2001 From: stavrosvl7 Date: Wed, 1 Jul 2026 19:22:16 +0300 Subject: [PATCH] rpc: reject block parameter with neither number nor hash An EIP-1898 block parameter object specifying neither blockNumber nor blockHash (e.g. {}) is invalid, but UnmarshalJSON accepted it and it was only rejected later in the backend with a generic -32000 error. Reject it during unmarshalling so it surfaces as -32602 (invalid params), mirroring the existing 'cannot specify both' check. --- rpc/types.go | 3 +++ rpc/types_test.go | 2 ++ 2 files changed, 5 insertions(+) diff --git a/rpc/types.go b/rpc/types.go index 578d3f86dd..7720a8d9c6 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -158,6 +158,9 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error { if e.BlockNumber != nil && e.BlockHash != nil { return errors.New("cannot specify both BlockHash and BlockNumber, choose one or the other") } + if e.BlockNumber == nil && e.BlockHash == nil { + return errors.New("must specify either BlockHash or BlockNumber") + } bnh.BlockNumber = e.BlockNumber bnh.BlockHash = e.BlockHash bnh.RequireCanonical = e.RequireCanonical diff --git a/rpc/types_test.go b/rpc/types_test.go index 9dd6fa6508..35294c3dba 100644 --- a/rpc/types_test.go +++ b/rpc/types_test.go @@ -109,6 +109,8 @@ func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) { 27: {`{"blockNumber":"safe"}`, false, BlockNumberOrHashWithNumber(SafeBlockNumber)}, 28: {`{"blockNumber":"finalized"}`, false, BlockNumberOrHashWithNumber(FinalizedBlockNumber)}, 29: {`{"blockNumber":"0x1", "blockHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}`, true, BlockNumberOrHash{}}, + 30: {`{}`, true, BlockNumberOrHash{}}, + 31: {`{"requireCanonical":true}`, true, BlockNumberOrHash{}}, } for i, test := range tests {