Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(evm): make conditional balance check free in gas cost #2114

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions x/evm/keeper/bank_extension.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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(),
)
Expand Down
Loading