From 71774e71fbe128901bc1354fa055c6b99ecc6330 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 9 Jun 2023 17:20:49 +0800 Subject: [PATCH 1/6] add nil check for consParams.Block --- x/feemarket/keeper/eip1559.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/feemarket/keeper/eip1559.go b/x/feemarket/keeper/eip1559.go index ef931f0e0a..d477caa84e 100644 --- a/x/feemarket/keeper/eip1559.go +++ b/x/feemarket/keeper/eip1559.go @@ -59,7 +59,7 @@ func (k Keeper) CalculateBaseFee(ctx sdk.Context) *big.Int { gasLimit := new(big.Int).SetUint64(math.MaxUint64) // NOTE: a MaxGas equal to -1 means that block gas is unlimited - if consParams != nil && consParams.Block.MaxGas > -1 { + if consParams != nil && consParams.Block != nil && consParams.Block.MaxGas > -1 { gasLimit = big.NewInt(consParams.Block.MaxGas) } From 141ec2e2555be518af34ca3f093a3331659c65b2 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 15 Jun 2023 11:34:36 +0800 Subject: [PATCH 2/6] update nix --- gomod2nix.toml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gomod2nix.toml b/gomod2nix.toml index f5b91071dd..0e3d07aa46 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -409,8 +409,8 @@ schema = 3 version = "v0.9.1" hash = "sha256-YLGNrHHM+mN4ElW/XWuylOnFrA/VjSY+eBuC4LN//5c=" [mod."github.com/rs/cors"] - version = "v1.8.3" - hash = "sha256-VgVB4HKAhPSjNg96mIEUN1bt5ZQng8Fi3ZABy3CDWQE=" + version = "v1.9.0" + hash = "sha256-CNBCGXOydU6MIEZ0B5eXBjBm3smH2ryYHvgRJA2udBM=" [mod."github.com/rs/zerolog"] version = "v1.27.0" hash = "sha256-BxQtP2TROeSSpj9l1irocuSfxn55UL4ugzB/og7r8eE=" @@ -512,8 +512,8 @@ schema = 3 version = "v0.0.0-20230131160201-f062dba9d201" hash = "sha256-sxLT/VOe93v0h3miChJSHS9gscTZS/B71+390ju/e20=" [mod."golang.org/x/net"] - version = "v0.8.0" - hash = "sha256-2cOtqa7aJ5mn64kZ+8+PVjJ4uGbhpXTpC1vm/+iaZzM=" + version = "v0.9.0" + hash = "sha256-EG5GRDq282twyce8uugsDTjMz1pNn6zPcyVTZmSiJ14=" [mod."golang.org/x/oauth2"] version = "v0.4.0" hash = "sha256-Dj9wHbSbs0Ghr9Hef0hSfanaR8L0GShI18jGBT3yNn8=" @@ -521,14 +521,14 @@ schema = 3 version = "v0.1.0" hash = "sha256-Hygjq9euZ0qz6TvHYQwOZEjNiTbTh1nSLRAWZ6KFGR8=" [mod."golang.org/x/sys"] - version = "v0.6.0" - hash = "sha256-zAgxiTuL24sGhbXrna9R1UYqLQh46ldztpumOScmduY=" + version = "v0.7.0" + hash = "sha256-GotRHJaas/q3L+tFam0q3oQ1rc8GDStt7wnz9h8MTEU=" [mod."golang.org/x/term"] - version = "v0.6.0" - hash = "sha256-Ao0yXpwY8GyG+/23dVfJUYrfEfNUTES3RF45v1VhUAk=" + version = "v0.7.0" + hash = "sha256-VYnXZ50OXTsylzncIMceVC2ZBKdbyp+V367Qbq3Vlqk=" [mod."golang.org/x/text"] - version = "v0.8.0" - hash = "sha256-hgWFnT01DRmywBEXKYEVaOee7i6z8Ydz7zGbjcWwOgI=" + version = "v0.9.0" + hash = "sha256-tkhDeMsSQZr3jo7vmKehWs3DvWetwXR0IB+DCLbQ4nk=" [mod."golang.org/x/tools"] version = "v0.7.0" hash = "sha256-ZEjfFulQd6U9r4mEJ5RZOnW49NZnQnrCFLMKCgLg7go=" From da74c626d3b988523ee3a7ee68d8d56adf8bc9c9 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 15 Jun 2023 11:39:52 +0800 Subject: [PATCH 3/6] add change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84fe644400..303c1272ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - (app) [#1739](https://github.com/evmos/ethermint/pull/1739) Remove distribution module perms - (ante) [#1741](https://github.com/evmos/ethermint/pull/1741) Add authz ante handler - (eip712) [#1746](https://github.com/evmos/ethermint/pull/1746) Add EIP712 support for multiple messages and schemas +- (feemarket) [#1790](https://github.com/evmos/ethermint/pull/1790) Add nil check for consParams.Block ### Bug Fixes From f6266d0151ef326998165ed6fd93b232bb7006d9 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 15 Jun 2023 13:50:19 +0800 Subject: [PATCH 4/6] skip invalid consensus params --- x/feemarket/keeper/eip1559.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x/feemarket/keeper/eip1559.go b/x/feemarket/keeper/eip1559.go index d477caa84e..61b181ad9a 100644 --- a/x/feemarket/keeper/eip1559.go +++ b/x/feemarket/keeper/eip1559.go @@ -16,6 +16,7 @@ package keeper import ( + "fmt" "math/big" sdk "github.com/cosmos/cosmos-sdk/types" @@ -56,13 +57,12 @@ func (k Keeper) CalculateBaseFee(ctx sdk.Context) *big.Int { parentGasUsed := k.GetBlockGasWanted(ctx) - gasLimit := new(big.Int).SetUint64(math.MaxUint64) - // NOTE: a MaxGas equal to -1 means that block gas is unlimited - if consParams != nil && consParams.Block != nil && consParams.Block.MaxGas > -1 { - gasLimit = big.NewInt(consParams.Block.MaxGas) + if consParams == nil || consParams.Block == nil || consParams.Block.MaxGas <= -1 { + k.Logger(ctx).Error(fmt.Sprintf("get invalid consensus params: %s", consParams)) + return nil } - + gasLimit := big.NewInt(consParams.Block.MaxGas) // CONTRACT: ElasticityMultiplier cannot be 0 as it's checked in the params // validation parentGasTargetBig := new(big.Int).Div(gasLimit, new(big.Int).SetUint64(uint64(params.ElasticityMultiplier))) From 929b3452120810931a0cc9e50330982c1fc83e5a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 15 Jun 2023 16:42:21 +0800 Subject: [PATCH 5/6] panic on invalid consensus params --- CHANGELOG.md | 2 +- x/feemarket/keeper/eip1559.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 303c1272ce..69affee629 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - (app) [#1739](https://github.com/evmos/ethermint/pull/1739) Remove distribution module perms - (ante) [#1741](https://github.com/evmos/ethermint/pull/1741) Add authz ante handler - (eip712) [#1746](https://github.com/evmos/ethermint/pull/1746) Add EIP712 support for multiple messages and schemas -- (feemarket) [#1790](https://github.com/evmos/ethermint/pull/1790) Add nil check for consParams.Block +- (feemarket) [#1790](https://github.com/evmos/ethermint/pull/1790) Raise error when get invalid consensus params ### Bug Fixes diff --git a/x/feemarket/keeper/eip1559.go b/x/feemarket/keeper/eip1559.go index 61b181ad9a..2f58f70651 100644 --- a/x/feemarket/keeper/eip1559.go +++ b/x/feemarket/keeper/eip1559.go @@ -59,8 +59,7 @@ func (k Keeper) CalculateBaseFee(ctx sdk.Context) *big.Int { // NOTE: a MaxGas equal to -1 means that block gas is unlimited if consParams == nil || consParams.Block == nil || consParams.Block.MaxGas <= -1 { - k.Logger(ctx).Error(fmt.Sprintf("get invalid consensus params: %s", consParams)) - return nil + panic(fmt.Sprintf("get invalid consensus params: %s", consParams)) } gasLimit := big.NewInt(consParams.Block.MaxGas) // CONTRACT: ElasticityMultiplier cannot be 0 as it's checked in the params From 444b8e894c65a0d51d9fe7dacb6144cb117479cb Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 15 Jun 2023 16:55:18 +0800 Subject: [PATCH 6/6] update default params for test --- app/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/utils.go b/app/utils.go index b2f4f181e5..d5e7c79a0b 100644 --- a/app/utils.go +++ b/app/utils.go @@ -42,8 +42,8 @@ import ( // EthermintApp testing. var DefaultConsensusParams = &abci.ConsensusParams{ Block: &abci.BlockParams{ - MaxBytes: 200000, - MaxGas: -1, // no limit + MaxBytes: 1048576, + MaxGas: 81500000, // default limit }, Evidence: &tmproto.EvidenceParams{ MaxAgeNumBlocks: 302400,