Skip to content

Commit

Permalink
Problem: nonce management in batch tx
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Dec 17, 2024
1 parent eac770f commit 7b18e6a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions tests/integration_tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
7 changes: 4 additions & 3 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 7b18e6a

Please sign in to comment.