diff --git a/x/evm/types/tx_args.go b/x/evm/types/tx_args.go index dd7b6475e4..a97b6f73c3 100644 --- a/x/evm/types/tx_args.go +++ b/x/evm/types/tx_args.go @@ -135,18 +135,17 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (* // Set sender address or use zero address if none specified. addr := args.GetFrom() - + // Ethereum block size is ~36000000, we limit this value to protect against DOS + MaxGasCap := uint64(100000000) // Set default gas & gas price if none were set - gas := globalGasCap - if gas == 0 { - gas = uint64(math.MaxUint64 / 2) - } - if args.Gas != nil { + gas := MaxGasCap + if args.Gas != nil && uint64(*args.Gas) < MaxGasCap { gas = uint64(*args.Gas) } if globalGasCap != 0 && globalGasCap < gas { gas = globalGasCap } + var ( gasPrice *big.Int gasFeeCap *big.Int diff --git a/x/evm/types/tx_args_test.go b/x/evm/types/tx_args_test.go index 9e8c20aa0b..fc97682b86 100644 --- a/x/evm/types/tx_args_test.go +++ b/x/evm/types/tx_args_test.go @@ -2,6 +2,7 @@ package types import ( "fmt" + "math" "math/big" "github.com/ethereum/go-ethereum/common" @@ -286,3 +287,45 @@ func (suite *TxDataTestSuite) TestGetData() { suite.Require().Equal(retrievedData, tc.expectedOutput) } } + +func (suite *TxDataTestSuite) TestMaxGasCap() { + testCases := []struct { + name string + globalGasCap uint64 + txArgs TransactionArgs + expectedOutput uint64 + }{ + { + "globalGasCap is below limit", + 25000000, + TransactionArgs{ + Gas: nil, + Input: nil, + }, + 25000000, + }, + { + "globalGasCap is above limit", + math.MaxInt64, + TransactionArgs{ + Gas: nil, + Input: nil, + }, + 100000000, + }, + { + "globalGasCap is zero", + 0, + TransactionArgs{ + Gas: nil, + Input: nil, + }, + 100000000, + }, + } + for _, tc := range testCases { + res, err := tc.txArgs.ToMessage(tc.globalGasCap, nil) + suite.Require().Nil(err) + suite.Require().Equal(res.GasLimit, tc.expectedOutput) + } +}