Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines EIP-170, which introduces a rule that causes contract creation to fail with an out-of-gas error if the returned code exceeds the maximum permitted size.

The following specification is the basis for this explanation.

For other Ethereum improvement proposals, see the following page.

Parameters

Parameter Value
MAX_CODE_SIZE 0x6000 (2**14 + 2**13)
FORK_BLKNUM 2,675,000
CHAIN_ID 1 (Mainnet)

Specification

Blocks containing transactions in a blockchain have block numbers. FORK_BLKNUM identifies the block at which a particular protocol upgrade or fork takes effect. In this proposal, it specifies when the new contract creation rule becomes active.

Contract creation deploys a new smart contract to the blockchain. Initialization code executes and returns the bytecode that will become the deployed contract's code.

MAX_CODE_SIZE is the maximum permitted size of that deployed code. This limit is intended to support blockchain performance and security.

When a contract is created at or after FORK_BLKNUM, if its initialization code returns more than MAX_CODE_SIZE bytes, contract creation fails with an out-of-gas error.

Gas measures the computational resources required by operations such as transaction execution and contract creation. An out-of-gas error normally occurs when execution exceeds the gas allocated to it. Under EIP-170, oversized deployed code is specifically treated as an out-of-gas failure, even if the caller supplies additional gas.

Additional Considerations

Calling an Ethereum smart contract consumes gas, but may also involve additional costs that are not fully represented by the cost of the call itself.

Reading the contract code from disk, preprocessing it for execution in the virtual machine, and including data in Merkle proofs required to establish block validity can all incur costs proportional to code size, or O(n).

These secondary costs may be manageable at the gas limits considered when the proposal was written. However, they could become more problematic if gas limits increase dynamically over time.

Although the issue may not be as severe as other denial-of-service (DoS) attacks, it is particularly relevant to light clients, which verify evidence about blockchain validity without downloading all blockchain data.

The proposed solution is to cap the size of objects that can be stored on-chain. The limit was selected to be slightly above what was feasible under the gas limit at the time, reducing the immediate impact on existing usage.

This prevents deployed smart contract code from growing without bound as gas limits increase, helping contain associated resource costs and security risks.

References

Citation

Vitalik Buterin (@vbuterin), "EIP-170: Contract code size limit," Ethereum Improvement Proposals, no. 170, November 2016. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-170.

Conclusion

EIP-170 introduces a fixed upper bound on deployed smart contract code size and specifies an out-of-gas failure for contract creation that exceeds it.