From b61c103c3c09da844972b5cc36884da403376363 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:22:03 -0500 Subject: [PATCH] fix(evm): make conditional balance check free in gas cost (#2114) * fix(evm): make conditional balance check free in gas cost * chore: update changelog --- CHANGELOG.md | 1 + x/evm/keeper/bank_extension.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 408bd8bc7..f6727ecb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,7 @@ feat(evm-funtoken-precompile): Implement methods: balance, bankBalance, whoAmI - [#2108](https://github.com/NibiruChain/nibiru/pull/2108) - fix(evm): removed deprecated root key from eth_getTransactionReceipt - [#2110](https://github.com/NibiruChain/nibiru/pull/2110) - fix(evm): Restore StateDB to its state prior to ApplyEvmMsg call to ensure deterministic gas usage. This fixes an issue where the StateDB pointer field in NibiruBankKeeper was being updated during readonly query endpoints like eth_estimateGas, leading to non-deterministic gas usage in subsequent transactions. - [#2111](https://github.com/NibiruChain/nibiru/pull/2111) - fix: e2e-evm-cron.yml +- [#2114](https://github.com/NibiruChain/nibiru/pull/2114) - fix(evm): make gas cost zero in conditional bank keeper flow #### Nibiru EVM | Before Audit 1 - 2024-10-18 diff --git a/x/evm/keeper/bank_extension.go b/x/evm/keeper/bank_extension.go index da5221cbb..cb94ccc59 100644 --- a/x/evm/keeper/bank_extension.go +++ b/x/evm/keeper/bank_extension.go @@ -1,6 +1,7 @@ package keeper import ( + storetypes "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" @@ -84,6 +85,14 @@ func (bk *NibiruBankKeeper) SyncStateDBWithAccount( if bk.StateDB == nil { return } + + cachedGasConfig := ctx.KVGasConfig() + defer func() { + ctx = ctx.WithKVGasConfig(cachedGasConfig) + }() + + // set gas cost to zero for this conditional operation + ctx = ctx.WithKVGasConfig(storetypes.GasConfig{}) balanceWei := evm.NativeToWei( bk.GetBalance(ctx, acc, evm.EVMBankDenom).Amount.BigInt(), )