From 0365deb6034664e8b6966de8e38acbbd0b742dbe Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:42:55 -0800 Subject: [PATCH 1/4] fix: typo --- x/evm/keeper/grpc_query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) } } From 83200cb51cdc5d0df1c52aba517a210314cb1a9b Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:43:09 -0800 Subject: [PATCH 2/4] fix: return to old StateDB pointer in BankKeeper after ApplyEvmMsg --- x/evm/keeper/msg_server.go | 6 ++++++ 1 file changed, 6 insertions(+) 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) From 6c73ff4829487b54737b90b8f146843c9226d63d Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:03:02 -0800 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba6d3291e..90af397d0 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 - +- [#2108](https://github.com/NibiruChain/nibiru/pull/2110) - fix(evm): get rid of non-deterministic gas usage of NibiruBankKeeper #### Nibiru EVM | Before Audit 1 - 2024-10-18 From 0a20fab5359be2186b7bb8735fae510c07f1bbab Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:05:39 -0700 Subject: [PATCH 4/4] Update CHANGELOG.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90af397d0..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 -- [#2108](https://github.com/NibiruChain/nibiru/pull/2110) - fix(evm): get rid of non-deterministic gas usage of NibiruBankKeeper +- [#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