diff --git a/CHANGELOG.md b/CHANGELOG.md index ecc8368d17..91d2450c98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (rpc) [#559](https://github.com/crypto-org-chain/ethermint/pull/559) Use basefee of transaction height instead of minus one height when `debug_traceTransaction`. * (ante) [#560](https://github.com/crypto-org-chain/ethermint/pull/560) Check gasWanted only in checkTx mode. * (rpc) [#562](https://github.com/crypto-org-chain/ethermint/pull/562) Fix nil pointer panic with legacy transaction format. +* (evm) [#]() Fix nonce management in batch transaction. ### Improvements diff --git a/tests/integration_tests/test_batch.py b/tests/integration_tests/test_batch.py index b43934a5b4..75a50fa79a 100644 --- a/tests/integration_tests/test_batch.py +++ b/tests/integration_tests/test_batch.py @@ -51,6 +51,9 @@ def test_batch_tx(ethermint): == receipts[0].gasUsed + receipts[1].gasUsed + receipts[2].gasUsed ) + # check nonce + assert w3.eth.get_transaction_count(sender) == nonce + 3 + # check traceTransaction rsps = [ w3.provider.make_request("debug_traceTransaction", [h.hex()])["result"] diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index 3b4906246e..c561f6ba7b 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -373,11 +373,12 @@ func (k *Keeper) ApplyMessageWithConfig( if contractCreation { // take over the nonce management from evm: - // - reset sender's nonce to msg.Nonce() before calling evm. - // - increase sender's nonce by one no matter the result. + // - reset sender's nonce to msg.Nonce() to generate correct contract address. + // - set the nonce back to the original value after contract creation. + oldNonce := stateDB.GetNonce(sender.Address()) stateDB.SetNonce(sender.Address(), msg.Nonce) ret, _, leftoverGas, vmErr = evm.Create(sender, msg.Data, leftoverGas, msg.Value) - stateDB.SetNonce(sender.Address(), msg.Nonce+1) + stateDB.SetNonce(sender.Address(), oldNonce) } else { ret, leftoverGas, vmErr = evm.Call(sender, *msg.To, msg.Data, leftoverGas, msg.Value) }