EIP-2031 Introduction of a net transaction counter (State Rent B - Net transaction counter)
No call decision · Scaling & data · EIP status Stagnant · created 2019-05-15
Adds a counter to Ethereum state that records the total number of transactions, so that an account that was deleted and later revived cannot be replay-attacked with its past transactions.
Why it is needed
Under the state rent proposal, accounts that have gone unused for a long time are evicted from state, and if someone sends ether to that address, the account is recreated. If the revived account's nonce restarts from 0, there is a risk that transactions the account signed in the past could be replayed. By recording the total transaction count (txCount) in the state counter contract created by EIP-2029, the nonce of a newly created or revived account can be filled with this value so it does not overlap with past signatures. An approach of determining the nonce based on block number was also considered, but it was not adopted because it would require arbitrarily fixing a maximum number of transactions per block.
What changes
Today
- Ethereum state has no dedicated space that records the total number of transactions.
- If an account is deleted and then recreated, its nonce restarts from 0, creating a risk that past transactions could be replayed.
After EIP-2031
- txCount is recorded in storage slot 0 of EIP-2029's state counter contract and increments with every transaction.
- The nonce of a newly created or revived account is filled with the txCount value at that time, so it does not overlap with past signatures.
Who is affected
- Client teams: The state counter contract's storage must be updated on every single transaction, which can only be applied via a hard fork.
- Developer of state rent related proposals: When designing the account eviction/revival logic, this counter is used as the source of nonce values.
- Wallet & app developers: If an account is deleted and then restored, existing assumptions about its nonce value may change.
In depth
The txCount field of the state counter contract
A txCount field is added to storage slot 0 inside the state counter contract (EIP-2029). This value can be read by calling that contract with 32 bytes of zero, and it holds the total number of transactions processed so far.
When and how it increments
Starting from Block B, or from whenever the state counter contract is deployed (whichever comes first), txCount increments every time a transaction is processed. This change updates the value of storage slot 0, and once applied, the change is not reverted.
The purpose of preventing nonce reuse
This counter is used to fill the nonce of newly created non-contract accounts. It serves as a means of preventing replay attacks against accounts that were deleted and then revived via an ether transfer.
Alternative considered 1: time-based replay prevention
An approach was considered where a new account's nonce would simply stay at 0, with a separate valid-until field that invalidates a transaction after a specified time. However, this was judged to have side effects, since the account nonce is also used to compute the address of contracts created via CREATE (though not CREATE2), beyond just replay prevention.
Alternative considered 2: block-number-based nonce
An approach of determining the nonce of new (and revived) accounts based on the current block number was also considered. In this case, an arbitrary parameter for the maximum number of transactions per block would need to be fixed, so that newly assigned nonces do not overlap with existing ones. It was noted that this could be especially problematic on private networks, where the number of transactions per block can be much higher.
Hard fork required, EIP-2029 dependency, current status
This change is not backward compatible and can only be applied via a hard fork, and it presupposes the existence of the state counter contract defined by EIP-2029 (requires: 2029). This proposal is part of the state rent roadmap, and its current status is Stagnant, meaning it is not actively discussed at this time.