diff --git a/rpc/ethereum/backend/backend.go b/rpc/ethereum/backend/backend.go index 17a3dfafaa..7174db16aa 100644 --- a/rpc/ethereum/backend/backend.go +++ b/rpc/ethereum/backend/backend.go @@ -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 diff --git a/rpc/ethereum/namespaces/eth/api.go b/rpc/ethereum/namespaces/eth/api.go index 35c5095971..76f926c4e8 100644 --- a/rpc/ethereum/namespaces/eth/api.go +++ b/rpc/ethereum/namespaces/eth/api.go @@ -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 diff --git a/rpc/ethereum/types/types.go b/rpc/ethereum/types/types.go index b8aa449cf4..88dae8afff 100644 --- a/rpc/ethereum/types/types.go +++ b/rpc/ethereum/types/types.go @@ -11,6 +11,13 @@ 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 is picked up to meet the demand of mainstream use cases. +// It's also the max block gas parameter in current mainnet: https://github.com/crypto-org-chain/cronos-mainnet/blob/master/cronosmainnet_25-1/genesis.json#L8 +// 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.