From aa2d52a180129355931c72dfcc3977a4d47bfba5 Mon Sep 17 00:00:00 2001 From: Sushil-19 Date: Tue, 3 Mar 2026 14:59:09 +0530 Subject: [PATCH 1/2] internal/ethapi: validate explicit transaction type in RPC calls --- internal/ethapi/transaction_args.go | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 4fb30e6289..284a2ab308 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -40,6 +40,8 @@ import ( // TransactionArgs represents the arguments to construct a new transaction // or a message call. type TransactionArgs struct { + Type *hexutil.Uint64 `json:"type,omitempty"` + From *common.Address `json:"from"` To *common.Address `json:"to"` Gas *hexutil.Uint64 `json:"gas"` @@ -72,6 +74,24 @@ type TransactionArgs struct { AuthorizationList []types.SetCodeAuthorization `json:"authorizationList"` } +func (args *TransactionArgs) inferTxType(defaultType int) int { + usedType := types.LegacyTxType + switch { + case args.AuthorizationList != nil || defaultType == types.SetCodeTxType: + usedType = types.SetCodeTxType + case args.BlobHashes != nil || defaultType == types.BlobTxType: + usedType = types.BlobTxType + case args.MaxFeePerGas != nil || defaultType == types.DynamicFeeTxType: + usedType = types.DynamicFeeTxType + case args.AccessList != nil || defaultType == types.AccessListTxType: + usedType = types.AccessListTxType + } + if args.GasPrice != nil { + usedType = types.LegacyTxType + } + return usedType +} + // from retrieves the transaction sender address. func (args *TransactionArgs) from() common.Address { if args.From == nil { @@ -176,6 +196,32 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend, config } else { args.ChainID = (*hexutil.Big)(want) } + + // Validate explicit transaction type if provided + if args.Type != nil { + requested := int(*args.Type) + + // Validate supported types + switch requested { + case types.LegacyTxType, + types.AccessListTxType, + types.DynamicFeeTxType, + types.BlobTxType, + types.SetCodeTxType: + // ok + default: + return fmt.Errorf("unsupported transaction type: %d", requested) + } + + inferred := args.inferTxType(types.LegacyTxType) + + if requested != inferred { + return fmt.Errorf( + "transaction type mismatch (requested=%d inferred=%d)", + requested, inferred, + ) + } + } return nil } From 0268f2e03df74c1e7db2e76218fb7ac796342d41 Mon Sep 17 00:00:00 2001 From: Sushil-19 Date: Tue, 3 Mar 2026 15:24:08 +0530 Subject: [PATCH 2/2] internal/ethapi: apply goimports formatting --- internal/ethapi/transaction_args.go | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 284a2ab308..ab709d3558 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -40,7 +40,7 @@ import ( // TransactionArgs represents the arguments to construct a new transaction // or a message call. type TransactionArgs struct { - Type *hexutil.Uint64 `json:"type,omitempty"` + Type *hexutil.Uint64 `json:"type,omitempty"` From *common.Address `json:"from"` To *common.Address `json:"to"` @@ -75,21 +75,21 @@ type TransactionArgs struct { } func (args *TransactionArgs) inferTxType(defaultType int) int { - usedType := types.LegacyTxType - switch { - case args.AuthorizationList != nil || defaultType == types.SetCodeTxType: - usedType = types.SetCodeTxType - case args.BlobHashes != nil || defaultType == types.BlobTxType: - usedType = types.BlobTxType - case args.MaxFeePerGas != nil || defaultType == types.DynamicFeeTxType: - usedType = types.DynamicFeeTxType - case args.AccessList != nil || defaultType == types.AccessListTxType: - usedType = types.AccessListTxType - } - if args.GasPrice != nil { - usedType = types.LegacyTxType - } - return usedType + usedType := types.LegacyTxType + switch { + case args.AuthorizationList != nil || defaultType == types.SetCodeTxType: + usedType = types.SetCodeTxType + case args.BlobHashes != nil || defaultType == types.BlobTxType: + usedType = types.BlobTxType + case args.MaxFeePerGas != nil || defaultType == types.DynamicFeeTxType: + usedType = types.DynamicFeeTxType + case args.AccessList != nil || defaultType == types.AccessListTxType: + usedType = types.AccessListTxType + } + if args.GasPrice != nil { + usedType = types.LegacyTxType + } + return usedType } // from retrieves the transaction sender address.