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

Problem: Int64 is not checked in gas related api #425

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (evm) [#405](https://github.com/crypto-org-chain/ethermint/pull/405) Avoid duplicate cache events emitted from evm hooks.
- (rpc) [#406](https://github.com/crypto-org-chain/ethermint/pull/406) Align filter rule for eth_getLogs when toBlock is newer than latest or extract error occurs.
- (rpc) [#409](https://github.com/crypto-org-chain/ethermint/pull/409) Fix nextBaseFee in eth_feeHistory before fee market param change.
- (rpc) [#425](https://github.com/crypto-org-chain/ethermint/pull/425) Avoid Int64() out of bound error in gas related api.

### Improvements

Expand Down
2 changes: 1 addition & 1 deletion rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type EVMBackend interface {
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
RPCEVMTimeout() time.Duration // global timeout for eth_call over rpc: DoS protection
RPCTxFeeCap() float64 // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for send-transaction variants. The unit is ether.
RPCMinGasPrice() int64
RPCMinGasPrice() *big.Int

// Sign Tx
Sign(address common.Address, data hexutil.Bytes) (hexutil.Bytes, error)
Expand Down
2 changes: 1 addition & 1 deletion rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
}
result = result.Add(result, head.BaseFee)
} else {
result = big.NewInt(b.RPCMinGasPrice())
result = b.RPCMinGasPrice()

Check warning on line 435 in rpc/backend/call_tx.go

View check run for this annotation

Codecov / codecov/patch

rpc/backend/call_tx.go#L435

Added line #L435 was not covered by tests
}

// return at least GlobalMinGasPrice from FeeMarket module
Expand Down
2 changes: 1 addition & 1 deletion rpc/backend/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (b *Backend) FeeHistory(
// Although we don't support tx prioritization yet, but we return a positive value to help client to
// mitigate the base fee changes.
func (b *Backend) SuggestGasTipCap(baseFee *big.Int) (*big.Int, error) {
if baseFee == nil {
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
if baseFee == nil || !baseFee.IsInt64() {
// london hardfork not enabled or feemarket not enabled
return big.NewInt(0), nil
}
Expand Down
12 changes: 6 additions & 6 deletions rpc/backend/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,17 @@ func (b *Backend) RPCBlockRangeCap() int32 {
// RPCMinGasPrice returns the minimum gas price for a transaction obtained from
// the node config. If set value is 0, it will default to 20.

func (b *Backend) RPCMinGasPrice() int64 {
func (b *Backend) RPCMinGasPrice() *big.Int {
evmParams, err := b.queryClient.Params(b.ctx, &evmtypes.QueryParamsRequest{})
if err != nil {
return ethermint.DefaultGasPrice
return new(big.Int).SetInt64(ethermint.DefaultGasPrice)
}

minGasPrice := b.cfg.GetMinGasPrices()
amt := minGasPrice.AmountOf(evmParams.Params.EvmDenom).TruncateInt64()
if amt == 0 {
return ethermint.DefaultGasPrice
amt := minGasPrice.AmountOf(evmParams.Params.EvmDenom).TruncateInt()
if amt.IsZero() {
return new(big.Int).SetInt64(ethermint.DefaultGasPrice)
}

return amt
return amt.BigInt()
}
20 changes: 17 additions & 3 deletions rpc/backend/node_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math/big"

"cosmossdk.io/math"
tmrpcclient "github.com/cometbft/cometbft/rpc/client"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -17,10 +18,12 @@ import (
)

func (suite *BackendTestSuite) TestRPCMinGasPrice() {
defaultPrice := new(big.Int).SetInt64(ethermint.DefaultGasPrice)
bigPrice, _ := new(big.Int).SetString("18446744073709551616", 10)
testCases := []struct {
name string
registerMock func()
expMinGasPrice int64
expMinGasPrice *big.Int
expPass bool
}{
{
Expand All @@ -29,7 +32,7 @@ func (suite *BackendTestSuite) TestRPCMinGasPrice() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParamsWithoutHeaderError(queryClient, 1)
},
ethermint.DefaultGasPrice,
defaultPrice,
true,
},
{
Expand All @@ -38,7 +41,18 @@ func (suite *BackendTestSuite) TestRPCMinGasPrice() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParamsWithoutHeader(queryClient, 1)
},
ethermint.DefaultGasPrice,
defaultPrice,
true,
},
{
"pass - min gas price exceeds math.MaxUint64",
func() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParamsWithoutHeader(queryClient, 1)
amt, _ := math.NewIntFromString("18446744073709551616")
suite.backend.cfg.SetMinGasPrices([]sdk.DecCoin{sdk.NewDecCoin(ethermint.AttoPhoton, amt)})
},
bigPrice,
true,
},
}
Expand Down
Loading