From 3d514b500bfc32dcc03ea8fadcc4fe6990817ae8 Mon Sep 17 00:00:00 2001 From: james-prysm Date: Wed, 7 Aug 2024 09:02:12 -0500 Subject: [PATCH 1/4] adding hexutil encoding on request parameters --- beacon-chain/execution/payload_body.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beacon-chain/execution/payload_body.go b/beacon-chain/execution/payload_body.go index 71e8f7473978..a895044319f4 100644 --- a/beacon-chain/execution/payload_body.go +++ b/beacon-chain/execution/payload_body.go @@ -5,6 +5,7 @@ import ( "sort" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" @@ -160,7 +161,7 @@ func computeRanges(hbns []hashBlockNumber) []byRangeReq { func (r *blindedBlockReconstructor) requestBodiesByRange(ctx context.Context, client RPCClient, method string, req byRangeReq) error { result := make([]*pb.ExecutionPayloadBody, 0) - if err := client.CallContext(ctx, &result, method, req.start, req.count); err != nil { + if err := client.CallContext(ctx, &result, method, hexutil.EncodeUint64(req.start), hexutil.EncodeUint64(req.count)); err != nil { return err } if uint64(len(result)) != req.count { From 110d629faa269e3d22c0880c671f1893076af258 Mon Sep 17 00:00:00 2001 From: james-prysm Date: Wed, 7 Aug 2024 09:28:44 -0500 Subject: [PATCH 2/4] fix for test --- beacon-chain/execution/mock_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/beacon-chain/execution/mock_test.go b/beacon-chain/execution/mock_test.go index a77c83ecc446..ca19778afaac 100644 --- a/beacon-chain/execution/mock_test.go +++ b/beacon-chain/execution/mock_test.go @@ -84,11 +84,15 @@ func (s *mockEngine) callCount(method string) int { } func mockParseUintList(t *testing.T, data json.RawMessage) []uint64 { - var list []uint64 + var list []string if err := json.Unmarshal(data, &list); err != nil { t.Fatalf("failed to parse uint list: %v", err) } - return list + uints := make([]uint64, len(list)) + for i, u := range list { + uints[i] = hexutil.MustDecodeUint64(u) + } + return uints } func mockParseHexByteList(t *testing.T, data json.RawMessage) []hexutil.Bytes { From 2f25f673dac5005e9c062dea0b7c3e3a5647eeac Mon Sep 17 00:00:00 2001 From: james-prysm Date: Wed, 7 Aug 2024 09:50:42 -0500 Subject: [PATCH 3/4] fixing more tests --- beacon-chain/execution/mock_test.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/beacon-chain/execution/mock_test.go b/beacon-chain/execution/mock_test.go index ca19778afaac..02e197dfbbca 100644 --- a/beacon-chain/execution/mock_test.go +++ b/beacon-chain/execution/mock_test.go @@ -121,7 +121,7 @@ func TestParseRequest(t *testing.T) { ctx := context.Background() cases := []struct { method string - uintArgs []uint64 + hexArgs []string // uint64 as hex byteArgs []hexutil.Bytes }{ { @@ -139,12 +139,12 @@ func TestParseRequest(t *testing.T) { }, }, { - method: GetPayloadBodiesByRangeV1, - uintArgs: []uint64{0, 1}, + method: GetPayloadBodiesByRangeV1, + hexArgs: []string{hexutil.EncodeUint64(0), hexutil.EncodeUint64(1)}, }, { - method: GetPayloadBodiesByRangeV2, - uintArgs: []uint64{math.MaxUint64, 1}, + method: GetPayloadBodiesByRangeV2, + hexArgs: []string{hexutil.EncodeUint64(math.MaxUint64), hexutil.EncodeUint64(1)}, }, } for _, c := range cases { @@ -156,9 +156,11 @@ func TestParseRequest(t *testing.T) { if len(c.byteArgs) > 0 { require.DeepEqual(t, c.byteArgs, mockParseHexByteList(t, msg.Params)) } - if len(c.uintArgs) > 0 { + if len(c.hexArgs) > 0 { rang := mockParseUintList(t, msg.Params) - require.DeepEqual(t, c.uintArgs, rang) + for i, r := range rang { + require.Equal(t, c.hexArgs[i], hexutil.EncodeUint64(r)) + } nr = rang[1] } mockWriteResult(t, w, msg, make([]*pb.ExecutionPayloadBody, nr)) @@ -169,18 +171,18 @@ func TestParseRequest(t *testing.T) { if len(c.byteArgs) > 0 { args = []interface{}{c.byteArgs} } - if len(c.uintArgs) > 0 { - args = make([]interface{}, len(c.uintArgs)) - for i := range c.uintArgs { - args[i] = c.uintArgs[i] + if len(c.hexArgs) > 0 { + args = make([]interface{}, len(c.hexArgs)) + for i := range c.hexArgs { + args[i] = c.hexArgs[i] } } require.NoError(t, cli.CallContext(ctx, &result, c.method, args...)) if len(c.byteArgs) > 0 { require.Equal(t, len(c.byteArgs), len(result)) } - if len(c.uintArgs) > 0 { - require.Equal(t, int(c.uintArgs[1]), len(result)) + if len(c.hexArgs) > 0 { + require.Equal(t, int(hexutil.MustDecodeUint64(c.hexArgs[1])), len(result)) } }) } From e440434b2aa03a4b04f522775a8019c116da3512 Mon Sep 17 00:00:00 2001 From: james-prysm Date: Wed, 7 Aug 2024 09:58:51 -0500 Subject: [PATCH 4/4] deepsource fix --- beacon-chain/execution/mock_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beacon-chain/execution/mock_test.go b/beacon-chain/execution/mock_test.go index 02e197dfbbca..046ccaaa5255 100644 --- a/beacon-chain/execution/mock_test.go +++ b/beacon-chain/execution/mock_test.go @@ -150,7 +150,7 @@ func TestParseRequest(t *testing.T) { for _, c := range cases { t.Run(c.method, func(t *testing.T) { cli, srv := newMockEngine(t) - srv.register(c.method, func(msg *jsonrpcMessage, w http.ResponseWriter, r *http.Request) { + srv.register(c.method, func(msg *jsonrpcMessage, w http.ResponseWriter, _ *http.Request) { require.Equal(t, c.method, msg.Method) nr := uint64(len(c.byteArgs)) if len(c.byteArgs) > 0 { @@ -209,7 +209,7 @@ func TestCallCount(t *testing.T) { for _, c := range cases { t.Run(c.method, func(t *testing.T) { cli, srv := newMockEngine(t) - srv.register(c.method, func(msg *jsonrpcMessage, w http.ResponseWriter, r *http.Request) { + srv.register(c.method, func(msg *jsonrpcMessage, w http.ResponseWriter, _ *http.Request) { mockWriteResult(t, w, msg, nil) }) for i := 0; i < c.count; i++ {