Skip to content

Commit

Permalink
Problem: Int64 is not checked in gas related api
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Mar 15, 2024
1 parent 70f88bf commit 2cf5851
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
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/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 {
if baseFee == nil || !baseFee.IsInt64() {
// london hardfork not enabled or feemarket not enabled
return big.NewInt(0), nil
}
Expand Down
6 changes: 3 additions & 3 deletions rpc/backend/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ func (b *Backend) RPCMinGasPrice() int64 {
}

minGasPrice := b.cfg.GetMinGasPrices()
amt := minGasPrice.AmountOf(evmParams.Params.EvmDenom).TruncateInt64()
if amt == 0 {
amt := minGasPrice.AmountOf(evmParams.Params.EvmDenom).TruncateInt()
if !amt.IsInt64() || amt.IsZero() {
return ethermint.DefaultGasPrice
}

return amt
return amt.Int64()

Check warning on line 353 in rpc/backend/node_info.go

View check run for this annotation

Codecov / codecov/patch

rpc/backend/node_info.go#L353

Added line #L353 was not covered by tests
}
12 changes: 12 additions & 0 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 Down Expand Up @@ -41,6 +42,17 @@ func (suite *BackendTestSuite) TestRPCMinGasPrice() {
ethermint.DefaultGasPrice,
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)})
},
ethermint.DefaultGasPrice,
true,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 2cf5851

Please sign in to comment.