Skip to content

Commit 98b3cd8

Browse files
committed
Add code duplication discount + update GAS_CREATE
1 parent d0c4986 commit 98b3cd8

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

EIPS/eip-0000.md

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ requires: 2780
1313

1414
## Abstract
1515

16-
This proposal increases the cost of state creation operations, thus avoiding excessive state growth under increased block gas limits. It sets a unit cost per new state byte that targets an average state growth of 60 GiB per year at a block gas limit of 300M gas units and an average gas utilization for state growth of 30%. Contract deployments get a 10x cost increase while new accounts get a 8.5x increase. To avoid limiting the maximum contract size that can be deployed, it also introduces an independent metering for code deposit costs.
16+
This proposal increases the cost of state creation operations, thus avoiding excessive state growth under increased block gas limits. It sets a unit cost per new state byte that targets an average state growth of 60 GiB per year at a block gas limit of 300M gas units and an average gas utilization for state growth of 30%. Contract deployments get a 10x cost increase while new accounts get a 8.5x increase. Deployments of duplicated do not pay deposit costs. To avoid limiting the maximum contract size that can be deployed, it also introduces an independent metering for code deposit costs.
1717

1818
## Motivation
1919

20-
State creation does not have a harmonized cost, with different methods incurring varied costs for creating the same size of new state. For instance, while contract deployment only costs 202 gas units per new byte created, new storage slots cost 625 gas units per new byte created. This proposal establishes a standard to harmonize all state creation operations.
20+
State creation does not have a harmonized cost, with different methods incurring varied costs for creating the same size of new state. For instance, while contract deployment only costs 202 gas units per new byte created, new storage slots cost 625 gas units per new byte created. Also, deploying duplicated bytecode costs the same as deploying new bytecode, even though clients don't store duplicated code in the database. This proposal establishes a standard to harmonize all state creation operations.
2121

2222
Additionally, state growth will become a bottleneck for scaling under higher block limits. As of May 2025, the current database size in a Geth node dedicated to state is ~340 GiB. After the increase in gas limit from 30M to 36M gas units, the median size of new state created each day doubled, from ~102 MiB to ~205 MiB.
2323

@@ -27,20 +27,37 @@ The relationship we are seeing in this example is not linear as expected. This i
2727

2828
## Specification
2929

30+
### Parameter changes
31+
3032
Upon activation of this EIP, the following parameters of the gas model are updated:
3133

3234
| **Parameter** | **Current value** | **New value** | **Increase** | **Operations affected** |
3335
|:---:|:---:|:---:|:---:|:---:|
34-
| `GAS_CREATE` | 32,000 | 5,000,000 | 78x | `CREATE`, `CREATE2`, contract creation txs |
36+
| `GAS_CREATE` | 32,000 | 212,800 | 6.7x | `CREATE`, `CREATE2`, contract creation txs |
3537
| `GAS_CODE_DEPOSIT` | 200 | 1,900 | 9.5x | `CREATE`, `CREATE2`, contract creation txs |
3638
| `GAS_NEW_ACCOUNT` | 25,000 | 212,800 | 8.5x | New EOA funding |
3739
| `GAS_SELF_DESTRUCT_NEW_ACCOUNT` | 25,000 | 212,800 | 8.5x | `SELF_DESTRUCT` |
3840
| `GAS_STORAGE_SET` | 20,000 | 60,800 | 3x | `SSTORE` |
3941
| `PER_EMPTY_ACCOUNT_COST` | 25,000 | 212,800 | 8.5x | EOA delegation |
4042
| `PER_AUTH_BASE_COST` | 12,500 | 43,700 | 3.5x | EOA delegation |
4143

44+
### Multidimensional metering for code deposit gas
45+
4246
Besides the parameter changes, this proposal introduces an independent metering for the code deposit costs. The specification is derived from [EIP-8011](./eip-8011.md). However, it only requires two dimensions, namely, `gas` and `code_deposit_gas`.
4347

48+
### Contract deployment cost calculation
49+
50+
This proposal further changes how contract deployment cost are computed. When a contract creation returns a runtime bytecode `R` (length `L`), first check whether the code already exists in the state trie. Then:
51+
52+
- If `CodeExists(keccak256(R), live_state) == false`, charge `code_deposit_cost=GAS_CODE_DEPOSIT*L` and store `R` under its code hash.
53+
- If `CodeExists(...) == true`, do not charge code-deposit storage gas (`code_deposit_gas=0`); simply link the new account's `codeHash` to the existing code object.
54+
55+
In addition, contract creation is also charged a `storage_access_cost = GAS_WARM_ACCESS (if warm) | GAS_COLD_SLOAD (if cold)` and a `hash_cost = GAS_KECCAK256_WORD * code_data_words`, where `code_data_words = ceil(L / 32)`. This accounts for the added execution cost of accessing and verifying for duplicated code.
56+
57+
#### `CREATE` vs `CREATE2`
58+
59+
`CREATE2` already charges for hashing the init code when deriving the address. That cost remains. Runtime-code deduplication hash (`keccak256(R)`) is separate: even with `CREATE2`, the runtime hash must be computed to determine whether the code is new or already stored.
60+
4461
## Rationale
4562

4663
### Harmonization across state creation
@@ -61,33 +78,31 @@ This capacity corresponds to an average of $\frac{60 \times 1024^3}{365} = 176,5
6178

6279
Now that we have a standardized cost per byte, we can derive the various costs parameters by multiplying the unit cost by the increase in bytes any given operation creates in the database (i.e., 32 bytes per slot, 112 bytes per account and 23 bytes per authorization):
6380

81+
- `GAS_CREATE` = 112 x `cost_per_state_byte`= 212,800
6482
- `GAS_CODE_DEPOSIT` = `cost_per_state_byte` = 1,900
6583
- `GAS_STORAGE_SET` = 32 x `cost_per_state_byte` = 60,800
6684
- `GAS_NEW_ACCOUNT` = 112 x `cost_per_state_byte`= 212,800
6785
- `GAS_SELF_DESTRUCT_NEW_ACCOUNT` = 112 x `cost_per_state_byte` = 212,800
6886
- `PER_EMPTY_ACCOUNT_COST` = 112 x `cost_per_state_byte` = 212,800
6987
- `PER_AUTH_BASE_COST` = 23 x `cost_per_state_byte` = 43,700
7088

71-
### Contract creation premium
72-
73-
The `GAS_CREATE` parameter is set differently from the remaining parameters. This parameter aims to encode a premium paid for deploying contracts.
74-
75-
Between genesis and the pre-Pectra block 22,431,083, 55% of all deployed contracts were never accessed after being deployed. This includes MEV or utility contracts that are created for a single transaction, mass-mint factories that never see adoption or even testing contracts.
76-
77-
In addition, contract deployment is done by very few accounts, with only 5.6 million accounts (around 2.3%) having deployed at least one contract since genesis.
78-
79-
Finally, compared with the overall costs of developing DApps, the contract deployment cost is fairly low.
80-
81-
Thus, **we define the `GAS_CREATE` parameter as a fixed cost representing a 10% premium over the code deposit cost of a 24 kB contract**. With the new pricing, a 24 kB contract pays $1,900 \times 24,576 = 46,694,400$ gas units of code deposit. Ten percent of that is roughly 5,000,000 gas units.
89+
Note that the fixed cost `GAS_CREATE` for contract deployments assumes the same cost as a new account creation.
8290

8391
### Multidimensional metering
8492

85-
[EIP-7825](./eip-7825.md) introduces a limit of 16.7M gas units for a single transaction. With the proposed contract creation costs, this cap would limit the maximum contract size that can be deployed to roughly 6kb ((16,777,216 - 21,000 - 5,000,000 - 212,800)/1,900 = 6,075). The limit by transaction was set in place to mitigate DoS attacks that result in uneven load distribution. This is not a concern for contract deployments, specially after the proposed 10x increase in costs.
93+
[EIP-7825](./eip-7825.md) introduces a limit of 16.7M gas units for a single transaction. With the proposed contract creation costs, this cap would limit the maximum contract size that can be deployed to roughly 6kb ($\frac{16,777,216 - 21,000 - 5,000,000 - 212,800}{1,900} = 6,075$). The limit by transaction was set in place to mitigate DoS attacks that result in uneven load distribution. This is not a concern for contract deployments, specially after the proposed 10x increase in costs.
8694

8795
An independent metering of the code deposit costs allows to lift this limit for contract creation transactions, while ensuring that users still pay the fair costs of contract deployment.
8896

8997
This proposal is consistent with the multidimensional gas metering introduced in [EIP-8011](./eip-8011.md). However, it only requires two dimensions, namely, `gas` and `code_deposit_gas`. If [EIP-8011](./eip-8011.md) is not implemented, a two-dimensional version of [EIP-8011](./eip-8011.md) is still required.
9098

99+
### Duplicated bytecode discount
100+
101+
- Ordering & same-block deployments: Sequential transaction execution ensures that a deployment storing new code makes it visible to later transactions in the same block. First transaction paying `code_deposit_cost`; subsequent transactions see the code as present and pay only lookup + hash costs.
102+
- Hashing cost is necessary: Always charge `hash_cost` for runtime code. Protects against abuse with large constructor outputs.
103+
- What counts as “same code”? Exact runtime bytecode. Even minor differences produce distinct hashes.
104+
- Empty code handling: Clients can treat empty code as a special case with a hard-coded hash lookup (`EMPTY_CODE_HASH`), making it effectively free.
105+
91106
## Backwards Compatibility
92107

93108
This is a backwards-incompatible gas repricing that requires a scheduled network upgrade.
@@ -115,8 +130,15 @@ New slot:
115130

116131
24kB contract deployment:
117132

118-
- OLD: 0.5 Gwei x (32,000 + 25,000 + 200 × 24,576) x 4,000 USD = 9.9444 USD
119-
- NEW: 0.5 Gwei x (5,000,000 + 212,800 + 1,900 × 24,576) x 4,000 USD = 103.814 USD
133+
- OLD: 0.5 Gwei x (32,000 + 200 × 24,576) x 4,000 USD = 9.8944 USD
134+
- NEW: 0.5 Gwei x (212,800 + 2100 + 6 * 768 + 1,900 × 24,576) x 4,000 USD = 93.828 USD
135+
136+
24kB contract deployment with duplicated bytecode:
137+
138+
- OLD: 0.5 Gwei x (32,000 + 200 × 24,576) x 4,000 USD = 9.8944 USD
139+
- NEW: 0.5 Gwei x (212,800 + 2100 + 6 * 768) x 4,000 USD = 0.439 USD
140+
141+
Note that we are ignoring transaction intrinsic costs (21k gas units), call data costs, and the costs of additional opcodes and scaffolding needed to execute such transactions.
120142

121143
## Security Considerations
122144

@@ -128,6 +150,10 @@ One potential concern is the cost of creating a new account (212,800 gas units),
128150

129151
[EIP-2780](./eip-2780.md) solves this mispricing by adding a new component to the intrinsic gas cost of transactions. For transactions the sending ETH that send ETH to a fresh account. If a non-create transaction has value > 0 and targets a non-existent account, the `GAS_NEW_ACCOUNT` is added to intrinsic cost.
130152

153+
### Independent metering for code deposit costs
154+
155+
Contract creation now introduces a cost that is not accounted for in the traditional gas metering and thus doesn't contribute to the block gas limit or the individual transaction limit. This could potentially be exploited by an attacker to create very large contracts that would stress the network. More benchmarking and analysis is needed to understand the potential risks and to determine if additional mitigations are necessary.
156+
131157
## Copyright
132158

133159
Copyright and related rights waived via [CC0](../LICENSE.md).

0 commit comments

Comments
 (0)