Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions x/evm/types/tx_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions x/evm/types/tx_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"fmt"
"math"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -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)
}
}
Loading