{"eip":2031,"title":"State Rent B - Net transaction counter","description":"Ethereum starts to track the number of transactions inside its state (for now, only number of transactions after this change is introduced, therefore it is called Net transaction count). It is done by incrementing a storage slot in the special contract, called State counter contract (EIP-2029).","authors":["Alexey Akhunov (@AlexeyAkhunov)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2019-05-15","requires":[2029],"discussionsTo":"https://ethereum-magicians.org/t/eip-2031-net-transaction-counter-change-b-from-state-rent-v3-proposal/3283","repo":"EIPs","label":"EIP-2031","officialUrl":"https://eips.ethereum.org/EIPS/eip-2031","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2031.md","url":"https://eips.huatuo.xyz/eip-2031/","tldr":{"en":"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.","ja":"State Rent 計画の一部。システムコントラクトでトランザクションのグローバルカウントを保持し、rent により削除されたのち復活したアカウントに、リプレイに安全な新しい nonce を与えられるようにする。","ko":"State Rent 계획의 일부. 시스템 컨트랙트에 트랜잭션의 전역 카운트를 유지해, 렌트로 제거되었다가 다시 살아난 계정이 리플레이에 안전한 새 nonce를 받을 수 있게 한다.","zh":"State Rent 计划的一部分：在系统合约中维护全局交易计数，使被租金机制驱逐、之后又被唤醒的账户能获得一个新的、可防重放的 nonce。"},"tags":["state-rent","nonce","replay-protection","core","state"],"explainers":{"en":{"lang":"en","tldr":"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.","tags":["state-rent","nonce","replay-protection","core","state"],"related":[2029,2027,2026],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2031/","markdown":"## What problem does it solve?\n\nAround 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.\n\nEIP-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.\n\n## How it works\n\n- [EIP-2029](/eip-2029/) (\"State Rent A\") introduces a special **state counter contract** that holds global counters in its storage.\n- EIP-2031 adds `txCount` at **storage slot 0** of that contract. It can be read by calling the contract with 32 zero bytes as input.\n- From fork block B (or the deployment of the counter contract, whichever comes first), `txCount` is incremented after **every** transaction. These updates are never reverted, even if the transaction itself fails.\n- Because it only counts transactions after activation, it is called the *net* transaction counter.\n- 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 `txCount` cannot collide with an old one.\n\nThe spec also considers two alternatives and rejects them:\n\n1. A `valid-until` field on transactions, which keeps nonces at 0 but conflicts with nonces being used to derive `CREATE` contract addresses.\n2. A nonce derived from the block number, which needs an arbitrary cap on transactions per block.\n\n## Sample code\n\nPseudocode for the state transition:\n\n```python\nSTATE_COUNTER_CONTRACT = ...   # defined by EIP-2029\nTX_COUNT_SLOT = 0\n\ndef apply_transaction(state, tx):\n    result = execute(state, tx)           # may succeed or fail\n    n = state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT)\n    state.set_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT, n + 1)  # never reverted\n    return result\n\ndef create_account(state, address):\n    state.accounts[address] = Account(\n        nonce=state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT),\n        balance=0,\n    )\n```\n\n## Things to know\n\n- **Status: Stagnant**, like the rest of the State Rent series ([EIP-2029](/eip-2029/), [EIP-2027](/eip-2027/), [EIP-2026](/eip-2026/)).\n- It would have required a hard fork. The block number B was never set.\n- State rent was not adopted on Ethereum. Research into state growth moved to other directions such as statelessness and state expiry.\n- Even if revived, the spec was preliminary: test cases and a reference implementation were still listed as future work.\n"},"ja":{"lang":"ja","tldr":"State Rent 計画の一部。システムコントラクトでトランザクションのグローバルカウントを保持し、rent により削除されたのち復活したアカウントに、リプレイに安全な新しい nonce を与えられるようにする。","tags":["state-rent","nonce","replay-protection","core","state"],"related":[2029,2027,2026],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2031/","markdown":"## 何を解決するのか\n\n2019 年頃、Ethereum の研究者は **state rent** を検討していました。アカウントが占有するステートに対して時間とともに料金を支払い、支払いをやめたアカウントは削除される、という仕組みです。これはリプレイ問題を生みます。削除されたアカウントに誰かが ether を送って復活させると、nonce 0 からやり直すことになります。すると、そのアカウントが過去に nonce 0、1、2… で署名したすべてのトランザクションをリプレイできてしまいます。\n\nEIP-2031（「State Rent B」）は、そのアカウントがこれまでに使ったどの nonce よりも確実に大きい開始 nonce を選ぶ方法を提供します。\n\n## 仕組み\n\n- [EIP-2029](/eip-2029/)（「State Rent A」）は、ストレージにグローバルカウンターを保持する特別な **state counter コントラクト**を導入します。\n- EIP-2031 は、そのコントラクトの**ストレージスロット 0** に `txCount` を追加します。32 バイトのゼロを入力としてコントラクトを呼び出すと読み取れます。\n- フォークブロック B（またはカウンターコントラクトのデプロイのうち早い方）以降、`txCount` は**すべての**トランザクションの後にインクリメントされます。この更新は、トランザクション自体が失敗しても決して revert されません。\n- 有効化後のトランザクションだけを数えるため、*net* トランザクションカウンターと呼ばれます。\n- このカウンターは、新しく作成される非コントラクトアカウント（再作成された削除済みアカウントを含む）の nonce の設定に使われます。どのアカウントもグローバル合計より多くのトランザクションを送ることはできないため、`txCount` から取った nonce が過去の nonce と衝突することはありません。\n\n仕様は 2 つの代替案も検討したうえで却下しています。\n\n1. トランザクションの `valid-until` フィールド。nonce は 0 のままにできますが、nonce を使って `CREATE` のコントラクトアドレスを導出する仕組みと衝突します。\n2. ブロック番号から導出する nonce。ブロックあたりのトランザクション数に任意の上限が必要になります。\n\n## サンプルコード\n\nステート遷移の疑似コード:\n\n```python\nSTATE_COUNTER_CONTRACT = ...   # defined by EIP-2029\nTX_COUNT_SLOT = 0\n\ndef apply_transaction(state, tx):\n    result = execute(state, tx)           # may succeed or fail\n    n = state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT)\n    state.set_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT, n + 1)  # never reverted\n    return result\n\ndef create_account(state, address):\n    state.accounts[address] = Account(\n        nonce=state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT),\n        balance=0,\n    )\n```\n\n## 知っておくべきこと\n\n- **ステータス: Stagnant**。State Rent シリーズの他の提案（[EIP-2029](/eip-2029/)、[EIP-2027](/eip-2027/)、[EIP-2026](/eip-2026/)）と同様です。\n- ハードフォークが必要でした。ブロック番号 B は決定されませんでした。\n- State rent は Ethereum では採用されませんでした。ステート肥大化の研究は、ステートレス化やステート expiry など別の方向へ移りました。\n- 仮に復活させるとしても、仕様は暫定的でした。テストケースとリファレンス実装は今後の作業として挙げられたままでした。\n"},"ko":{"lang":"ko","tldr":"State Rent 계획의 일부. 시스템 컨트랙트에 트랜잭션의 전역 카운트를 유지해, 렌트로 제거되었다가 다시 살아난 계정이 리플레이에 안전한 새 nonce를 받을 수 있게 한다.","tags":["state-rent","nonce","replay-protection","core","state"],"related":[2029,2027,2026],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2031/","markdown":"## 어떤 문제를 해결하나요?\n\n2019년경 이더리움 연구자들은 **state rent**를 검토했습니다. 계정이 차지하는 상태에 대해 시간이 지남에 따라 비용을 내고, 비용 지불을 멈춘 계정은 제거될 수 있다는 개념입니다. 이는 리플레이 문제를 만듭니다. 제거된 계정에 누군가 ether를 보내 되살리면 nonce 0부터 다시 시작하게 됩니다. 그러면 그 계정이 과거에 nonce 0, 1, 2…로 서명한 모든 트랜잭션을 리플레이할 수 있습니다.\n\nEIP-2031(\"State Rent B\")은 해당 계정이 이전에 사용한 어떤 nonce보다 확실히 큰 시작 nonce를 고르는 방법을 제공합니다.\n\n## 어떻게 동작하나요?\n\n- [EIP-2029](/eip-2029/)(\"State Rent A\")는 스토리지에 전역 카운터를 보관하는 특별한 **state counter 컨트랙트**를 도입합니다.\n- EIP-2031은 이 컨트랙트의 **스토리지 슬롯 0**에 `txCount`를 추가합니다. 32바이트 0을 입력으로 컨트랙트를 호출하면 읽을 수 있습니다.\n- 포크 블록 B(또는 카운터 컨트랙트 배포 시점 중 더 이른 쪽)부터 `txCount`는 **모든** 트랜잭션 뒤에 증가합니다. 이 업데이트는 트랜잭션 자체가 실패하더라도 절대 되돌려지지 않습니다.\n- 활성화 이후의 트랜잭션만 세기 때문에 *net* 트랜잭션 카운터라고 부릅니다.\n- 이 카운터는 새로 생성되는 비컨트랙트 계정(다시 만들어지는 제거된 계정 포함)의 nonce를 설정하는 데 쓰입니다. 어떤 계정도 전역 합계보다 많은 트랜잭션을 보낼 수 없으므로, `txCount`에서 가져온 nonce는 과거 nonce와 충돌하지 않습니다.\n\n스펙은 두 가지 대안도 검토한 뒤 기각합니다.\n\n1. 트랜잭션의 `valid-until` 필드. nonce를 0으로 유지할 수 있지만, nonce로 `CREATE` 컨트랙트 주소를 도출하는 방식과 충돌합니다.\n2. 블록 번호에서 도출한 nonce. 블록당 트랜잭션 수에 임의의 상한이 필요합니다.\n\n## 샘플 코드\n\n상태 전이의 의사 코드:\n\n```python\nSTATE_COUNTER_CONTRACT = ...   # defined by EIP-2029\nTX_COUNT_SLOT = 0\n\ndef apply_transaction(state, tx):\n    result = execute(state, tx)           # may succeed or fail\n    n = state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT)\n    state.set_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT, n + 1)  # never reverted\n    return result\n\ndef create_account(state, address):\n    state.accounts[address] = Account(\n        nonce=state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT),\n        balance=0,\n    )\n```\n\n## 알아둘 점\n\n- **상태: Stagnant**. State Rent 시리즈의 다른 제안([EIP-2029](/eip-2029/), [EIP-2027](/eip-2027/), [EIP-2026](/eip-2026/))과 마찬가지입니다.\n- 하드포크가 필요했을 것입니다. 블록 번호 B는 결정된 적이 없습니다.\n- State rent는 이더리움에 채택되지 않았습니다. 상태 증가에 대한 연구는 statelessness와 state expiry 같은 다른 방향으로 옮겨 갔습니다.\n- 되살린다 해도 스펙은 예비 단계였습니다. 테스트 케이스와 레퍼런스 구현은 여전히 향후 과제로 남아 있었습니다.\n"},"zh":{"lang":"zh","tldr":"State Rent 计划的一部分：在系统合约中维护全局交易计数，使被租金机制驱逐、之后又被唤醒的账户能获得一个新的、可防重放的 nonce。","tags":["state-rent","nonce","replay-protection","core","state"],"related":[2029,2027,2026],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2031/","markdown":"## 它解决什么问题？\n\n2019 年前后，以太坊研究者探索了**状态租金（state rent）**：账户需要为其占用的状态随时间付费，停止付费的账户可能被驱逐。这就带来了重放问题。如果被驱逐的账户因有人向它发送 ether 而复活，它会重新从 nonce 0 开始。它过去用 nonce 0、1、2…… 签名的每一笔交易都可能被重放。\n\nEIP-2031（\"State Rent B\"）提供了一种方法，选出一个保证高于该账户以往用过的任何 nonce 的起始 nonce。\n\n## 它如何运作\n\n- [EIP-2029](/eip-2029/)（\"State Rent A\"）引入了一个特殊的**状态计数器合约**，其存储中保存全局计数器。\n- EIP-2031 在该合约的**存储槽 0** 中加入 `txCount`。以 32 个零字节作为输入调用该合约即可读取。\n- 从分叉区块 B（或计数器合约部署时，以较早者为准）起，`txCount` 在**每一笔**交易之后递增。即使交易本身失败，这些更新也永远不会被回滚。\n- 由于它只统计激活之后的交易，因此被称为*净*交易计数器。\n- 该计数器随后用于设置新创建的非合约账户（包括被重新创建的已驱逐账户）的 nonce。任何账户发送的交易数都不可能超过全局总数，因此取自 `txCount` 的 nonce 不会与旧 nonce 冲突。\n\n规范还考虑了两个替代方案并否决了它们：\n\n1. 在交易上加 `valid-until` 字段，这样 nonce 可保持为 0，但与用 nonce 推导 `CREATE` 合约地址的做法冲突。\n2. 由区块号推导 nonce，这需要对每个区块的交易数设定一个任意上限。\n\n## 示例代码\n\n状态转换的伪代码：\n\n```python\nSTATE_COUNTER_CONTRACT = ...   # defined by EIP-2029\nTX_COUNT_SLOT = 0\n\ndef apply_transaction(state, tx):\n    result = execute(state, tx)           # may succeed or fail\n    n = state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT)\n    state.set_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT, n + 1)  # never reverted\n    return result\n\ndef create_account(state, address):\n    state.accounts[address] = Account(\n        nonce=state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT),\n        balance=0,\n    )\n```\n\n## 需要注意\n\n- **状态：Stagnant**，与 State Rent 系列的其他提案（[EIP-2029](/eip-2029/)、[EIP-2027](/eip-2027/)、[EIP-2026](/eip-2026/)）一样。\n- 它需要一次硬分叉。区块号 B 从未确定。\n- 状态租金没有在以太坊上被采纳。对状态增长的研究转向了无状态（statelessness）和状态过期（state expiry）等其他方向。\n- 即使重新启用，该规范也只是初步的：测试用例和参考实现仍被列为未来工作。\n"}}}
