diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a261e126..a1f70e2e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,9 +55,11 @@ documentation. - [#2129](https://github.com/NibiruChain/nibiru/pull/2129) - fix(evm): issue with infinite recursion in erc20 funtoken contracts - [#2134](https://github.com/NibiruChain/nibiru/pull/2134) - fix(evm): query of NIBI should use bank state, not the StateDB - [#2139](https://github.com/NibiruChain/nibiru/pull/2139) - fix(evm): erc20 born funtoken: properly burn bank coins after converting coin back to erc20 +- [#2140](https://github.com/NibiruChain/nibiru/pull/2140) - fix(bank): bank keeper extension now charges gas for the bank operations - [#2141](https://github.com/NibiruChain/nibiru/pull/2141) - refactor: simplify account retrieval operation in `nibid q evm account`. - [#2142](https://github.com/NibiruChain/nibiru/pull/2142) - fix(bank): add additional missing methods to the NibiruBankKeeper + #### Nibiru EVM | Before Audit 2 - 2024-12-06 The codebase went through a third-party [Code4rena diff --git a/app/ante/fixed_gas_test.go b/app/ante/fixed_gas_test.go index 4e45f6b6b..64f4c6e8c 100644 --- a/app/ante/fixed_gas_test.go +++ b/app/ante/fixed_gas_test.go @@ -197,7 +197,7 @@ func (suite *AnteTestSuite) TestOraclePostPriceTransactionsHaveFixedPrice() { Amount: sdk.NewCoins(sdk.NewInt64Coin(appconst.BondDenom, 200)), }, }, - expectedGas: 38175, + expectedGas: 67193, expectedErr: nil, }, } diff --git a/x/evm/keeper/bank_extension.go b/x/evm/keeper/bank_extension.go index 34cf1fbd6..aa4fe101c 100644 --- a/x/evm/keeper/bank_extension.go +++ b/x/evm/keeper/bank_extension.go @@ -1,7 +1,6 @@ package keeper import ( - store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" auth "github.com/cosmos/cosmos-sdk/x/auth/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" @@ -169,10 +168,9 @@ func (bk NibiruBankKeeper) ForceGasInvariant( // Note that because the ctx gas meter uses private variables to track gas, // we have to branch off with a new gas meter instance to avoid mutating the // "true" gas meter (called GasMeterBefore here). - ctx = ctx. - WithGasMeter(sdk.NewGasMeter(gasMeterBefore.Limit())). - WithKVGasConfig(zeroCostGasConfig). - WithTransientKVGasConfig(zeroCostGasConfig) + // We use an infinite gas meter because we consume gas in the deferred function + // and gasMeterBefore will panic if we consume too much gas. + ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) err := BaseOp(ctx) baseOpGasConsumed = ctx.GasMeter().GasConsumed() @@ -184,16 +182,6 @@ func (bk NibiruBankKeeper) ForceGasInvariant( return nil } -var zeroCostGasConfig store.GasConfig = store.GasConfig{ - HasCost: 0, - DeleteCost: 0, - ReadCostFlat: 0, - ReadCostPerByte: 0, - WriteCostFlat: 0, - WriteCostPerByte: 0, - IterNextCostFlat: 0, -} - func (bk NibiruBankKeeper) SendCoins( ctx sdk.Context, fromAddr sdk.AccAddress, diff --git a/x/evm/keeper/bank_extension_test.go b/x/evm/keeper/bank_extension_test.go index 378bb8546..b5b6a999d 100644 --- a/x/evm/keeper/bank_extension_test.go +++ b/x/evm/keeper/bank_extension_test.go @@ -61,14 +61,16 @@ func (s *Suite) TestGasConsumedInvariantSend() { for idx, tc := range testCases { s.Run(tc.name, func() { gasConsumed := tc.GasConsumedInvariantScenario.Run(s, to) + s.T().Logf("gasConsumed: %d", gasConsumed) + s.Require().NotZerof(gasConsumed, "gasConsumed should not be zero") if idx == 0 { first = gasConsumed return } // Each elem being equal to "first" implies that each elem is equal s.Equalf( - fmt.Sprintf("%d", first), - fmt.Sprintf("%d", gasConsumed), + first, + gasConsumed, "Gas consumed should be equal", ) }) @@ -106,7 +108,7 @@ func (scenario GasConsumedInvariantScenario) Run( ) gasConsumedAfter := deps.Ctx.GasMeter().GasConsumed() - s.GreaterOrEqualf(gasConsumedAfter, gasConsumedBefore, + s.Greaterf(gasConsumedAfter, gasConsumedBefore, "gas meter consumed should not be negative: gas consumed after = %d, gas consumed before = %d ", gasConsumedAfter, gasConsumedBefore, )