Skip to content
Open
4 changes: 2 additions & 2 deletions rpc/jsonrpc/send_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func (api *APIImpl) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error) {
txn, err := types.DecodeWrappedTransaction(encodedTx)
if err != nil {
return common.Hash{}, err
return common.Hash{}, &rpc.InvalidParamsError{Message: err.Error()}
}

// If the transaction fee cap is already specified, ensure the
Expand Down Expand Up @@ -52,7 +52,7 @@ func (api *APIImpl) SendRawTransaction(ctx context.Context, encodedTx hexutil.By
txnChainId := txn.GetChainID()
chainId := cc.ChainID
if chainId.Cmp(txnChainId) != 0 {
return common.Hash{}, fmt.Errorf("invalid chain id, expected: %d got: %d", chainId, txnChainId)
return common.Hash{}, &rpc.InvalidParamsError{Message: fmt.Sprintf("invalid chain id, expected: %d got: %d", chainId, txnChainId)}
}
}

Expand Down
32 changes: 32 additions & 0 deletions rpc/jsonrpc/send_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package jsonrpc

import (
"bytes"
"errors"
"testing"
"time"

Expand All @@ -26,11 +27,13 @@ import (

"github.com/erigontech/erigon/cmd/rpcdaemon/rpcdaemontest"
"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/common/hexutil"
"github.com/erigontech/erigon/execution/execmodule/execmoduletester"
"github.com/erigontech/erigon/execution/protocol/params"
"github.com/erigontech/erigon/execution/tests/blockgen"
"github.com/erigontech/erigon/execution/types"
"github.com/erigontech/erigon/node/gointerfaces/txpoolproto"
"github.com/erigontech/erigon/rpc"
"github.com/erigontech/erigon/rpc/rpchelper"
"github.com/erigontech/erigon/txnprovider/txpool/txpoolcfg"
)
Expand Down Expand Up @@ -116,3 +119,32 @@ func TestSendRawTransactionUnprotected(t *testing.T) {
require.Equal(expectedTxValue, jsonTx.Value.Uint64())
}
}

func TestSendRawTransaction_InvalidParams_OnMalformedRLP(t *testing.T) {
m := execmoduletester.New(t, execmoduletester.WithTxPool())
ctx, conn := rpcdaemontest.CreateTestGrpcConn(t, m)
txPool := txpoolproto.NewTxpoolClient(conn)
api := newEthApiForTest(newBaseApiForTest(m), m.DB, txPool, nil)

cases := []struct {
name string
raw string
}{
{"empty-list", "0xc0"},
{"truncated-short-list", "0xd4"},
{"unknown-tx-type", "0x09c0"},
{"eip4844-truncated-list", "0x03c0"},
{"eip7702-truncated-list", "0x04c0"},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
require := require.New(t)
_, err := api.SendRawTransaction(ctx, hexutil.MustDecode(tc.raw))
require.Error(err)
var invalid *rpc.InvalidParamsError
require.True(errors.As(err, &invalid), "expected *rpc.InvalidParamsError, got %T: %v", err, err)
require.Equal(-32602, invalid.ErrorCode(), "want InvalidParams (-32602), got %d (%v)", invalid.ErrorCode(), err)
})
}
}
Loading