{"eip":2027,"title":"State Rent C - Net contract size accounting","description":"Ethereum starts counting the number of storage slots filled and emptied in the contracts. Since the number of pre-existing slots is not currently accounted in the state, effectively, only net change in the number of slots is tracked.","authors":["Alexey Akhunov (@AlexeyAkhunov)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2019-05-14","discussionsTo":"https://ethereum-magicians.org/t/eip-2027-net-contract-size-accounting-change-c-from-state-rent-v3-proposal/3275","repo":"EIPs","label":"EIP-2027","officialUrl":"https://eips.ethereum.org/EIPS/eip-2027","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2027.md","url":"https://eips.huatuo.xyz/eip-2027/","tldr":{"en":"A State Rent building block that would make every contract track the net change in its number of non-empty storage slots, laying groundwork for size-aware gas costs and rent.","ja":"すべてのコントラクトに、空でないストレージスロット数の純増減を記録させる State Rent の構成要素。サイズに応じたガスコストやレントの土台になる。","ko":"모든 컨트랙트가 비어 있지 않은 스토리지 슬롯 수의 순변화를 추적하도록 하는 State Rent의 구성 요소. 크기를 반영한 가스 비용과 렌트의 토대를 마련한다.","zh":"一个 State Rent 的构件：让每个合约记录其非空存储槽数量的净变化，为按大小定价的 gas 成本和租金奠定基础。"},"tags":["state-rent","storage","accounting","core"],"explainers":{"en":{"lang":"en","tldr":"A State Rent building block that would make every contract track the net change in its number of non-empty storage slots, laying groundwork for size-aware gas costs and rent.","tags":["state-rent","storage","accounting","core"],"related":[2029,2031,2026,1418],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2027/","markdown":"## What problem does it solve?\n\nEthereum does not record how many storage slots a contract uses. Given the state, the only way to find out is to walk the contract's entire storage trie, which is not constant-time. Yet that number matters for several ideas being discussed in 2019:\n\n- pricing `SLOAD`/`SSTORE` according to contract size, to cover the bandwidth of block proofs;\n- letting snapshot sync protocols know and prove how big each contract's storage is;\n- eventually charging state rent.\n\nEIP-2027 (\"State Rent C\") is a first step: start counting changes from a fork block onward.\n\n## How it works\n\nEvery contract (account whose code hash is not the empty-code hash) gets a new `uint64` field, `storagesize`. After fork block `C`, `SSTORE` updates it:\n\n- slot goes from **zero to non-zero**: increment;\n- slot goes from **non-zero to zero**: decrement;\n- changes are reverted with the call frame like any other state change.\n\nSince nobody knows the true size of existing contracts at the fork, the field starts from an offset. `HUGE_NUMBER` is suggested to be 2^63:\n\n```python\nHUGE_NUMBER = 2**63\n\ndef increment(acct):\n    acct.storagesize = (acct.storagesize + 1) if acct.has_storagesize else HUGE_NUMBER + 1\n\ndef decrement(acct):\n    acct.storagesize = (acct.storagesize - 1) if acct.has_storagesize else HUGE_NUMBER - 1\n```\n\nSo `storagesize - HUGE_NUMBER` is the **net** change since the fork. Because no contract could have 2^62 slots, a later \"gross accounting\" upgrade can tell whether a value is still net (around 2^63) or has been converted to a real total (much smaller). The field is not readable from contracts.\n\n## Sample code\n\nTracing a contract that writes three new slots and clears one existing slot after the fork:\n\n```python\nHUGE = 2**63\nsize = None                     # field absent before first touch\n\ndef sstore(old, new):\n    global size\n    if old == 0 and new != 0:\n        size = HUGE + 1 if size is None else size + 1\n    elif old != 0 and new == 0:\n        size = HUGE - 1 if size is None else size - 1\n\nsstore(0, 5); sstore(0, 7); sstore(0, 9)   # three new slots\nsstore(42, 0)                              # one pre-existing slot cleared\nprint(size - HUGE)                         # 2  (net change since fork)\n```\n\n## Things to know\n\n- **Status: Stagnant.** It was never activated on mainnet.\n- It belongs to the \"State Rent\" proposal series by the same author, alongside [EIP-2029](/eip-2029/) (state counters contract), [EIP-2031](/eip-2031/) (net transaction counter) and [EIP-2026](/eip-2026/) (fixed account prepayment). The intended follow-up, gross contract size accounting, would track the full total.\n- It requires a hard fork and adds a field to the account, but because the value is not observable from the EVM, existing contracts would behave the same.\n- For an earlier, single-step rent design see [EIP-1418](/eip-1418/).\n"},"ja":{"lang":"ja","tldr":"すべてのコントラクトに、空でないストレージスロット数の純増減を記録させる State Rent の構成要素。サイズに応じたガスコストやレントの土台になる。","tags":["state-rent","storage","accounting","core"],"related":[2029,2031,2026,1418],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2027/","markdown":"## 何を解決するのか\n\nEthereum は、コントラクトが使っているストレージスロットの数を記録していません。ステートが与えられても、それを知る方法はコントラクトのストレージトライ全体を走査することしかなく、これは定数時間ではありません。しかしこの数は、2019 年当時議論されていたいくつかのアイデアにとって重要です。\n\n- ブロック証明の帯域を賄うため、コントラクトのサイズに応じて `SLOAD`/`SSTORE` の価格を決める。\n- スナップショット同期プロトコルが、各コントラクトのストレージサイズを把握し、証明できるようにする。\n- 最終的にステートレントを課金する。\n\nEIP-2027（「State Rent C」）はその第一歩で、フォークブロック以降の変化を数え始めます。\n\n## 仕組み\n\nすべてのコントラクト（コードハッシュが空コードのハッシュではないアカウント）に、新たに `uint64` のフィールド `storagesize` が追加されます。フォークブロック `C` 以降、`SSTORE` がこれを更新します。\n\n- スロットが**ゼロから非ゼロ**になる: インクリメントする。\n- スロットが**非ゼロからゼロ**になる: デクリメントする。\n- 変更は、他のステート変更と同様に、呼び出しフレームとともに巻き戻されます。\n\nフォーク時点で既存コントラクトの本当のサイズは誰にも分からないため、このフィールドはオフセットから始まります。`HUGE_NUMBER` は 2^63 が推奨されています。\n\n```python\nHUGE_NUMBER = 2**63\n\ndef increment(acct):\n    acct.storagesize = (acct.storagesize + 1) if acct.has_storagesize else HUGE_NUMBER + 1\n\ndef decrement(acct):\n    acct.storagesize = (acct.storagesize - 1) if acct.has_storagesize else HUGE_NUMBER - 1\n```\n\nしたがって `storagesize - HUGE_NUMBER` が、フォーク以降の**純**増減になります。2^62 個のスロットを持つコントラクトはありえないため、後の「総量会計」アップグレードでは、値がまだ純増減（2^63 付近）なのか、実際の合計（はるかに小さい値）に変換済みなのかを判別できます。このフィールドはコントラクトから読み取れません。\n\n## サンプルコード\n\nフォーク後に、新しいスロットを 3 つ書き込み、既存のスロットを 1 つクリアするコントラクトのトレース:\n\n```python\nHUGE = 2**63\nsize = None                     # field absent before first touch\n\ndef sstore(old, new):\n    global size\n    if old == 0 and new != 0:\n        size = HUGE + 1 if size is None else size + 1\n    elif old != 0 and new == 0:\n        size = HUGE - 1 if size is None else size - 1\n\nsstore(0, 5); sstore(0, 7); sstore(0, 9)   # three new slots\nsstore(42, 0)                              # one pre-existing slot cleared\nprint(size - HUGE)                         # 2  (net change since fork)\n```\n\n## 知っておくべきこと\n\n- **ステータス: Stagnant。** メインネットでは一度も有効化されていません。\n- 同じ著者による「State Rent」提案シリーズの一部で、[EIP-2029](/eip-2029/)（ステートカウンターコントラクト）、[EIP-2031](/eip-2031/)（正味トランザクションカウンター）、[EIP-2026](/eip-2026/)（固定額のアカウント前払い）と並びます。想定されている後続の、コントラクトサイズの総量会計は、合計全体を追跡します。\n- ハードフォークが必要で、アカウントにフィールドを追加しますが、値は EVM から観測できないため、既存のコントラクトの挙動は変わりません。\n- より前の、1 段階で完結するレント設計については [EIP-1418](/eip-1418/) を参照してください。\n"},"ko":{"lang":"ko","tldr":"모든 컨트랙트가 비어 있지 않은 스토리지 슬롯 수의 순변화를 추적하도록 하는 State Rent의 구성 요소. 크기를 반영한 가스 비용과 렌트의 토대를 마련한다.","tags":["state-rent","storage","accounting","core"],"related":[2029,2031,2026,1418],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2027/","markdown":"## 어떤 문제를 해결하나요?\n\n이더리움은 컨트랙트가 스토리지 슬롯을 몇 개 쓰는지 기록하지 않습니다. 상태가 주어져도 이를 알아내는 유일한 방법은 컨트랙트의 스토리지 트라이 전체를 순회하는 것인데, 이는 상수 시간이 아닙니다. 하지만 이 숫자는 2019년에 논의되던 여러 아이디어에 중요합니다.\n\n- 블록 증명의 대역폭을 감당하기 위해 컨트랙트 크기에 따라 `SLOAD`/`SSTORE` 가격을 책정\n- 스냅샷 동기화 프로토콜이 각 컨트랙트의 스토리지 크기를 알고 증명할 수 있게 하기\n- 궁극적으로 상태 렌트 부과\n\nEIP-2027(\"State Rent C\")은 그 첫걸음으로, 포크 블록부터 변화를 세기 시작합니다.\n\n## 어떻게 동작하나요?\n\n모든 컨트랙트(코드 해시가 빈 코드 해시가 아닌 계정)에 새로운 `uint64` 필드 `storagesize`가 생깁니다. 포크 블록 `C` 이후 `SSTORE`가 이를 갱신합니다.\n\n- 슬롯이 **0에서 0이 아닌 값**으로 바뀌면 증가\n- 슬롯이 **0이 아닌 값에서 0**으로 바뀌면 감소\n- 변경 사항은 다른 상태 변경과 마찬가지로 호출 프레임과 함께 되돌려집니다.\n\n포크 시점에 기존 컨트랙트의 실제 크기는 아무도 모르므로, 이 필드는 오프셋에서 시작합니다. `HUGE_NUMBER`는 2^63을 권장합니다.\n\n```python\nHUGE_NUMBER = 2**63\n\ndef increment(acct):\n    acct.storagesize = (acct.storagesize + 1) if acct.has_storagesize else HUGE_NUMBER + 1\n\ndef decrement(acct):\n    acct.storagesize = (acct.storagesize - 1) if acct.has_storagesize else HUGE_NUMBER - 1\n```\n\n따라서 `storagesize - HUGE_NUMBER`가 포크 이후의 **순**변화입니다. 슬롯이 2^62개인 컨트랙트는 있을 수 없으므로, 이후의 \"총량 회계\" 업그레이드에서는 값이 아직 순변화(2^63 근처)인지 실제 총계(훨씬 작은 값)로 변환되었는지 구별할 수 있습니다. 이 필드는 컨트랙트에서 읽을 수 없습니다.\n\n## 샘플 코드\n\n포크 이후 새 슬롯 세 개를 쓰고 기존 슬롯 하나를 비우는 컨트랙트의 추적:\n\n```python\nHUGE = 2**63\nsize = None                     # field absent before first touch\n\ndef sstore(old, new):\n    global size\n    if old == 0 and new != 0:\n        size = HUGE + 1 if size is None else size + 1\n    elif old != 0 and new == 0:\n        size = HUGE - 1 if size is None else size - 1\n\nsstore(0, 5); sstore(0, 7); sstore(0, 9)   # three new slots\nsstore(42, 0)                              # one pre-existing slot cleared\nprint(size - HUGE)                         # 2  (net change since fork)\n```\n\n## 알아둘 점\n\n- **상태: Stagnant.** 메인넷에서 활성화된 적이 없습니다.\n- 같은 저자의 \"State Rent\" 제안 시리즈에 속하며, [EIP-2029](/eip-2029/)(상태 카운터 컨트랙트), [EIP-2031](/eip-2031/)(순 트랜잭션 카운터), [EIP-2026](/eip-2026/)(고정 계정 선납)과 나란히 놓입니다. 예정된 후속 작업인 컨트랙트 크기의 총량 회계는 전체 합계를 추적합니다.\n- 하드 포크가 필요하고 계정에 필드가 추가되지만, 값을 EVM에서 관찰할 수 없으므로 기존 컨트랙트의 동작은 같습니다.\n- 이전의 단일 단계 렌트 설계는 [EIP-1418](/eip-1418/)을 참고하세요.\n"},"zh":{"lang":"zh","tldr":"一个 State Rent 的构件：让每个合约记录其非空存储槽数量的净变化，为按大小定价的 gas 成本和租金奠定基础。","tags":["state-rent","storage","accounting","core"],"related":[2029,2031,2026,1418],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2027/","markdown":"## 它解决什么问题？\n\n以太坊并不记录合约使用了多少个存储槽。仅凭状态，想知道这个数字只能遍历合约的整个存储 trie，而这并非常数时间操作。然而这个数字对 2019 年讨论的几个想法很重要：\n\n- 根据合约大小为 `SLOAD`/`SSTORE` 定价，以覆盖区块证明的带宽开销；\n- 让快照同步协议知道并证明每个合约的存储有多大；\n- 最终收取状态租金。\n\nEIP-2027（\"State Rent C\"）是第一步：从分叉区块起开始统计变化。\n\n## 它如何运作\n\n每个合约（代码哈希不是空代码哈希的账户）都会新增一个 `uint64` 字段 `storagesize`。在分叉区块 `C` 之后，`SSTORE` 会更新它：\n\n- 存储槽从**零变为非零**：加一；\n- 存储槽从**非零变为零**：减一；\n- 与其他状态变更一样，这些变化会随调用帧一起回滚。\n\n由于在分叉时没人知道现有合约的真实大小，该字段从一个偏移量开始。建议 `HUGE_NUMBER` 取 2^63：\n\n```python\nHUGE_NUMBER = 2**63\n\ndef increment(acct):\n    acct.storagesize = (acct.storagesize + 1) if acct.has_storagesize else HUGE_NUMBER + 1\n\ndef decrement(acct):\n    acct.storagesize = (acct.storagesize - 1) if acct.has_storagesize else HUGE_NUMBER - 1\n```\n\n因此 `storagesize - HUGE_NUMBER` 就是自分叉以来的**净**变化。由于不可能有合约拥有 2^62 个存储槽，后续的\"总量统计\"升级就可以判断某个值仍是净值（约 2^63），还是已经被转换为真实总数（小得多）。合约无法读取这个字段。\n\n## 示例代码\n\n追踪一个在分叉后写入三个新存储槽、并清除一个已有存储槽的合约：\n\n```python\nHUGE = 2**63\nsize = None                     # field absent before first touch\n\ndef sstore(old, new):\n    global size\n    if old == 0 and new != 0:\n        size = HUGE + 1 if size is None else size + 1\n    elif old != 0 and new == 0:\n        size = HUGE - 1 if size is None else size - 1\n\nsstore(0, 5); sstore(0, 7); sstore(0, 9)   # three new slots\nsstore(42, 0)                              # one pre-existing slot cleared\nprint(size - HUGE)                         # 2  (net change since fork)\n```\n\n## 需要注意\n\n- **状态：Stagnant。** 它从未在主网激活。\n- 它属于同一作者的\"State Rent\"提案系列，与 [EIP-2029](/eip-2029/)（状态计数器合约）、[EIP-2031](/eip-2031/)（净交易计数器）和 [EIP-2026](/eip-2026/)（固定账户预付）并列。预期的后续方案，即合约大小的总量统计，将追踪完整的总数。\n- 它需要一次硬分叉，并为账户增加一个字段，但由于该值在 EVM 中不可观察，现有合约的行为不会改变。\n- 关于更早的一步到位的租金设计，请参见 [EIP-1418](/eip-1418/)。\n"}}}
