EIP-2031 · Stagnant · Core · 2019-05-15
EIP-2031: State Rent B - Net transaction counter
Part of the State Rent plan: keep a global count of transactions in a system contract, so accounts evicted by rent and later revived can get a fresh, replay-safe nonce.
What problem does it solve?
Around 2019 Ethereum researchers explored state rent: accounts would pay over time for the state they occupy, and accounts that stop paying could be evicted. That creates a replay problem. If an evicted account is brought back by someone sending it ether, it would start again with nonce 0. Every transaction it signed in the past, with nonces 0, 1, 2…, could then be replayed.
EIP-2031 ("State Rent B") gives a way to pick a starting nonce that is guaranteed to be higher than any nonce the account has used before.
How it works
- EIP-2029 ("State Rent A") introduces a special state counter contract that holds global counters in its storage.
- EIP-2031 adds
txCountat storage slot 0 of that contract. It can be read by calling the contract with 32 zero bytes as input. - From fork block B (or the deployment of the counter contract, whichever comes first),
txCountis incremented after every transaction. These updates are never reverted, even if the transaction itself fails. - Because it only counts transactions after activation, it is called the net transaction counter.
- The counter is then used to set the nonce of newly created non-contract accounts, including evicted accounts that are recreated. No account can have sent more transactions than the global total, so a nonce taken from
txCountcannot collide with an old one.
The spec also considers two alternatives and rejects them:
- A
valid-untilfield on transactions, which keeps nonces at 0 but conflicts with nonces being used to deriveCREATEcontract addresses. - A nonce derived from the block number, which needs an arbitrary cap on transactions per block.
Sample code
Pseudocode for the state transition:
STATE_COUNTER_CONTRACT = ... # defined by EIP-2029
TX_COUNT_SLOT = 0
def apply_transaction(state, tx):
result = execute(state, tx) # may succeed or fail
n = state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT)
state.set_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT, n + 1) # never reverted
return result
def create_account(state, address):
state.accounts[address] = Account(
nonce=state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT),
balance=0,
)
Things to know
- Status: Stagnant, like the rest of the State Rent series (EIP-2029, EIP-2027, EIP-2026).
- It would have required a hard fork. The block number B was never set.
- State rent was not adopted on Ethereum. Research into state growth moved to other directions such as statelessness and state expiry.
- Even if revived, the spec was preliminary: test cases and a reference implementation were still listed as future work.