---
eip: 2027
label: EIP-2027
title: State Rent C - Net contract size accounting
status: Stagnant
type: Standards Track
category: Core
created: 2019-05-14
official: https://eips.ethereum.org/EIPS/eip-2027
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2027.md
canonical: https://eips.huatuo.xyz/eip-2027/
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]
---

# EIP-2027: State Rent C - Net contract size accounting

> 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.

**TL;DR:** 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.

## What problem does it solve?

Ethereum 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:

- pricing `SLOAD`/`SSTORE` according to contract size, to cover the bandwidth of block proofs;
- letting snapshot sync protocols know and prove how big each contract's storage is;
- eventually charging state rent.

EIP-2027 ("State Rent C") is a first step: start counting changes from a fork block onward.

## How it works

Every contract (account whose code hash is not the empty-code hash) gets a new `uint64` field, `storagesize`. After fork block `C`, `SSTORE` updates it:

- slot goes from **zero to non-zero**: increment;
- slot goes from **non-zero to zero**: decrement;
- changes are reverted with the call frame like any other state change.

Since 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:

```python
HUGE_NUMBER = 2**63

def increment(acct):
    acct.storagesize = (acct.storagesize + 1) if acct.has_storagesize else HUGE_NUMBER + 1

def decrement(acct):
    acct.storagesize = (acct.storagesize - 1) if acct.has_storagesize else HUGE_NUMBER - 1
```

So `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.

## Sample code

Tracing a contract that writes three new slots and clears one existing slot after the fork:

```python
HUGE = 2**63
size = None                     # field absent before first touch

def sstore(old, new):
    global size
    if old == 0 and new != 0:
        size = HUGE + 1 if size is None else size + 1
    elif old != 0 and new == 0:
        size = HUGE - 1 if size is None else size - 1

sstore(0, 5); sstore(0, 7); sstore(0, 9)   # three new slots
sstore(42, 0)                              # one pre-existing slot cleared
print(size - HUGE)                         # 2  (net change since fork)
```

## Things to know

- **Status: Stagnant.** It was never activated on mainnet.
- 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.
- 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.
- For an earlier, single-step rent design see [EIP-1418](/eip-1418/).


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2027
