EIPs Explained

EIP-5027 · Stagnant · Core · 2022-04-21

EIP-5027: Remove the limit on contract code size

Proposed removing the 24,576-byte contract code size cap and instead charging extra gas for deploying and loading oversized code.

What problem does it solve?

Since the Spurious Dragon fork, EIP-170 has limited deployed contract code to 24,576 bytes (24 KiB). The cap protects nodes from cheap denial-of-service, because loading code costs disk I/O and CPU but is charged a flat fee.

As applications have grown, many contracts hit this limit. Developers work around it by splitting logic across several contracts, using libraries, proxies or the diamond pattern, which adds complexity, gas overhead and audit surface.

EIP-5027 proposed lifting the hard cap (leaving only the block gas limit) and replacing it with gas metering proportional to the extra size.

How it works

Parameters:

Constant Value
CODE_SIZE_UNIT 24576
COLD_ACCOUNT_CODE_ACCESS_COST_PER_UNIT 2600
CREATE_DATA_GAS 200

After the fork:

  • Deploying with CREATE / CREATE2: if the new code is larger than CODE_SIZE_UNIT, charge an extra (CODE_SIZE - CODE_SIZE_UNIT) * CREATE_DATA_GAS.
  • Loading with EXTCODECOPY, CALL, CALLCODE, DELEGATECALL, STATICCALL: if the target's code is larger than CODE_SIZE_UNIT and this is the first access in the transaction, charge an extra (CODE_SIZE - 1) // CODE_SIZE_UNIT * 2600. In practice, each additional 24 KiB chunk costs one more cold access.
  • CODESIZE, CODECOPY, EXTCODESIZE, EXTCODEHASH keep their current cost; clients are expected to map code hash to size so size lookups stay O(1).

"First access" is tracked by a new per-transaction set, accessed_code_in_addresses, similar to the warm/cold sets from EIP-2929. It starts with the sender, the recipient and all precompiles. No change to the state structure is required.

Sample code

The extra gas rules as pseudocode:

CODE_SIZE_UNIT = 24576
COLD_ACCOUNT_CODE_ACCESS_COST_PER_UNIT = 2600
CREATE_DATA_GAS = 200

def extra_create_gas(code_size):
    if code_size <= CODE_SIZE_UNIT:
        return 0
    return (code_size - CODE_SIZE_UNIT) * CREATE_DATA_GAS

def extra_load_gas(code_size, addr, accessed_code_in_addresses):
    if code_size <= CODE_SIZE_UNIT or addr in accessed_code_in_addresses:
        cost = 0
    else:
        cost = (code_size - 1) // CODE_SIZE_UNIT * COLD_ACCOUNT_CODE_ACCESS_COST_PER_UNIT
    accessed_code_in_addresses.add(addr)
    return cost

# Example: a 60 KiB contract (61440 bytes), first call in the tx
# (61440 - 1) // 24576 = 2  ->  2 * 2600 = 5200 extra gas

Things to know

  • Status: Stagnant. It was never scheduled for a network upgrade.
  • Its "Security Considerations" section was left as TBD.
  • Existing contracts are unaffected; only contracts deployed before EIP-170 could already exceed the limit.
  • Raising the limit has been revisited in later proposals such as EIP-7907 (metering contract code size) and EIP-7954 (increasing the maximum contract size). Initcode limits are a separate matter covered by EIP-3860.

#evm #core #contract-size #gas

Details

Authors
Qi Zhou (@qizhou)
Status
Stagnant
Type
Standards Track / Core
Created
2022-04-21
Requires

Machine-readable: Markdown · JSON