Skip to content

Commit

Permalink
reject tx with too large gas limit
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Nov 17, 2021
1 parent fabf5d7 commit e22a535
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rpc/ethereum/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,13 @@ func (e *EVMBackend) SendTransaction(args types.SendTxArgs) (common.Hash, error)

msg := args.ToTransaction()

// hotfix, reject tx with too high gas limit
// FIXME remove after real fix is used: https://github.com/tharsis/ethermint/pull/751
if msg.GetGas() > types.RPCTxGasCap {
e.logger.Debug("gas limit too large", "gasLimit", fmt.Sprintf("%d", msg.GetGas()))
return common.Hash{}, fmt.Errorf("gas limit too large %d", msg.GetGas())
}

if err := msg.ValidateBasic(); err != nil {
e.logger.Debug("tx failed basic validation", "error", err.Error())
return common.Hash{}, err
Expand Down
7 changes: 7 additions & 0 deletions rpc/ethereum/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ func (e *PublicAPI) SendRawTransaction(data hexutil.Bytes) (common.Hash, error)
return common.Hash{}, fmt.Errorf("invalid transaction type %T", tx)
}

// hotfix, reject tx with too high gas limit
// FIXME remove after real fix is used: https://github.com/tharsis/ethermint/pull/751
if ethereumTx.GetGas() > rpctypes.RPCTxGasCap {
e.logger.Debug("gas limit too large", "gasLimit", fmt.Sprintf("%d", ethereumTx.GetGas()))
return common.Hash{}, fmt.Errorf("gas limit too large %d", ethereumTx.GetGas())
}

if err := ethereumTx.ValidateBasic(); err != nil {
e.logger.Debug("tx failed basic validation", "error", err.Error())
return common.Hash{}, err
Expand Down
6 changes: 6 additions & 0 deletions rpc/ethereum/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)

// RPCTxGasCap defines a gas limit threshold for transaction at rpc level
// The transactions with gas limit larger than this will be rejected.
// The number should be enough for the mainstream use cases.
// FIXME The limitation is a temporary fix, should be removed after real fix is used: https://github.com/tharsis/ethermint/pull/751
const RPCTxGasCap = 10000000

// Copied the Account and StorageResult types since they are registered under an
// internal pkg on geth.

Expand Down

0 comments on commit e22a535

Please sign in to comment.