From e22a5350e2ba43a65773028fc0cffa77c5aea0e5 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Wed, 17 Nov 2021 11:18:24 +0800 Subject: [PATCH 1/2] reject tx with too large gas limit --- rpc/ethereum/backend/backend.go | 7 +++++++ rpc/ethereum/namespaces/eth/api.go | 7 +++++++ rpc/ethereum/types/types.go | 6 ++++++ 3 files changed, 20 insertions(+) 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..510b807dd4 100644 --- a/rpc/ethereum/types/types.go +++ b/rpc/ethereum/types/types.go @@ -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. From e127ac53e9656100ed949edb9f99f80a81b2e046 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Wed, 17 Nov 2021 12:21:21 +0800 Subject: [PATCH 2/2] comments --- rpc/ethereum/types/types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rpc/ethereum/types/types.go b/rpc/ethereum/types/types.go index 510b807dd4..88dae8afff 100644 --- a/rpc/ethereum/types/types.go +++ b/rpc/ethereum/types/types.go @@ -13,7 +13,8 @@ import ( // 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. +// 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