Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reject tx with too large gas limit #12

Merged
merged 2 commits into from
Nov 17, 2021
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
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
7 changes: 7 additions & 0 deletions rpc/ethereum/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down