# Nonce can be manipulated by inserting a contract creation EthereumTx message first in an SDK TX with multiple EthereumTX messages

Nibiru's ApplyEvmMsg only resets nonce on contract-creation EVM txs, so bundling one creation plus call txs in a single Cosmos tx lets the call txs be replayed.

- Payout: Audit contest
- Severity: medium
- Program: Nibiru
- Found by: Sentryx
- Disclosed: 2025-02-24
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-11-nibiru-findings/issues/29
- Library page: https://bugbountylibrary.com/r/c4%3A2024-11-nibiru%3AM-07
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:signature-replay

**Target:** Cosmos SDK x/evm MsgEthereumTx ante/deliver path
**Root cause:** ApplyEvmMsg sets sender nonce to msg.Nonce()+1 only for contract-creation txs; for call/transfer txs it calls evmObj.Call() which never increments the account nonce, so the ante handler's sequence increments are overwritten by the creation tx's nonce reset.
**Steps:**
1. Build one Cosmos SDK tx containing 4 MsgEthereumTx: msg1 = contract creation with nonce 1, msgs 2-4 = calls/transfers with nonces 2,3,4.
2. Broadcast; ante handler validates and increments account sequence to 5.
3. DeliverTx: ApplyEvmMsg processes msg1 (contractCreation=true), sets nonce to msg.Nonce() then msg.Nonce()+1 = 2 and commits state.
4. Msgs 2-4 execute via evmObj.Call() without touching nonce; account sequence stays 1.
5. Replay msgs 2-4 since their nonces (2,3,4) are still valid.
**How found:** Code-reading of ApplyEvmMsg vs geth's state_transition: noticed geth increments sender nonce in both branches while Nibiru's ApplyEvmMsg only manages nonce for contract creation, then reasoned about multi-MsgEthereumTx SDK txs to exploit the mismatch.
**Exploitation:** Attacker bundles a contract-creation EVM tx first to force the account nonce back to a low value, then replays the subsequent call/transfer EVM messages multiple times, reusing nonces for repeated state-changing calls.
**Insight:** When a chain reimplements EVM state transition, diff its nonce handling against geth's state_transition.go branch-by-branch; any branch that skips SetNonce is a replay window, especially when multiple EVM msgs can share one Cosmos tx.

