diff --git a/CHANGELOG.md b/CHANGELOG.md index ba6d3291e..553714568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,7 +104,7 @@ tests for race conditions within funtoken precompile - [#2107](https://github.com/NibiruChain/nibiru/pull/2107) - 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. #### Nibiru EVM | Before Audit 1 - 2024-10-18 diff --git a/x/evm/keeper/grpc_query.go b/x/evm/keeper/grpc_query.go index 4e423e881..31a887bbc 100644 --- a/x/evm/keeper/grpc_query.go +++ b/x/evm/keeper/grpc_query.go @@ -454,7 +454,7 @@ func (k Keeper) EstimateGasForEvmCallType( return nil, fmt.Errorf("gas required exceeds allowance (%d)", gasCap) } - return nil, fmt.Errorf("Estimgate gas VMError: %s", result.VmError) + return nil, fmt.Errorf("Estimate gas VMError: %s", result.VmError) } } diff --git a/x/evm/keeper/msg_server.go b/x/evm/keeper/msg_server.go index 9914426fa..b7a3ec9a8 100644 --- a/x/evm/keeper/msg_server.go +++ b/x/evm/keeper/msg_server.go @@ -259,6 +259,12 @@ func (k *Keeper) ApplyEvmMsg(ctx sdk.Context, vmErr error // vm errors do not effect consensus and are therefore not assigned to err ) + // save a reference to return to the previous stateDB + oldStateDb := k.Bank.StateDB + defer func() { + k.Bank.StateDB = oldStateDb + }() + stateDB := k.NewStateDB(ctx, txConfig) evmObj = k.NewEVM(ctx, msg, evmConfig, tracer, stateDB)