From a513da9394e28fd27146cc99fe171dc45cccb0a9 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:33:40 -0500 Subject: [PATCH] fix(evm): make conditional balance check free in gas cost --- x/evm/keeper/bank_extension.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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(), )