Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EIP: Remove Contract Code Size Limit #9483

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

charles-cooper
Copy link
Contributor

ATTENTION: ERC-RELATED PULL REQUESTS NOW OCCUR IN ETHEREUM/ERCS

--

When opening a pull request to submit a new EIP, please use the suggested template: https://github.com/ethereum/EIPs/blob/master/eip-template.md

We have a GitHub bot that automatically merges some PRs. It will merge yours immediately if certain criteria are met:

  • The PR edits only existing draft PRs.
  • The build passes.
  • Your GitHub username or email address is listed in the 'author' header of all affected PRs, inside .
  • If matching on email address, the email address is the one publicly listed on your GitHub profile.

@charles-cooper charles-cooper requested a review from eth-bot as a code owner March 14, 2025 16:10
@github-actions github-actions bot added c-new Creates a brand new proposal s-draft This EIP is a Draft t-core labels Mar 14, 2025
@eth-bot
Copy link
Collaborator

eth-bot commented Mar 14, 2025

File EIPS/eip-7907.md

Requires 1 more reviewers from @g11tech, @lightclient, @SamWilsn

@eth-bot eth-bot added e-consensus Waiting on editor consensus e-review Waiting on editor to review labels Mar 14, 2025
@eth-bot eth-bot changed the title add eip to remove codesize limit Add EIP: Remove Contract Code Size Limit Mar 14, 2025
@github-actions github-actions bot added the w-ci Waiting on CI to pass label Mar 14, 2025
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174.

1. Remove the contract code size limit of 24KB (`0x6000` bytes) introduced in EIP-170.
2. Change the gas schedule for opcodes which load code. Specifically, the `CALL`, `STATICCALL`, `DELEGATECALL`, `CALLCODE`, and `EXTCODESIZE` opcodes are modified so that `ceil32(excess_contract_size) * 2 // 32` gas is deducted, where `excess_contract_size = max(0, contract_size - 0x6000)`. (Cf. initcode metering: [EELS](https://github.com/ethereum/execution-specs/blob/1a587803e3e698407d204888b02342393f8b4fe5/src/ethereum/cancun/vm/gas.py#L269))
Copy link
Member

@chfast chfast Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which are the opcodes "which load code"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's in the line you commented on

Copy link
Contributor Author

@charles-cooper charles-cooper Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure whether EXTCODESIZE and EXTCODECOPY should be included - conceivably those could be optimized in a way that they don't load the whole code, but a cursory glance over some client implementations indicates that inspecting part of the code before physically loading the whole thing would be a bit tricky.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174.

1. Remove the contract code size limit of 24KB (`0x6000` bytes) introduced in EIP-170.
2. Change the gas schedule for opcodes which load code. Specifically, the `CALL`, `STATICCALL`, `DELEGATECALL`, `CALLCODE`, and `EXTCODESIZE` opcodes are modified so that `ceil32(excess_contract_size) * 2 // 32` gas is deducted, where `excess_contract_size = max(0, contract_size - 0x6000)`. (Cf. initcode metering: [EELS](https://github.com/ethereum/execution-specs/blob/1a587803e3e698407d204888b02342393f8b4fe5/src/ethereum/cancun/vm/gas.py#L269))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that with this change the gas cost of e.g. EXTCODESIZE is unbounded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. this is to reflect the cost of loading the full contract code from disk and adding to the witness. in practice, this is bounded by the max contract size you could deploy with current gas limits, which is about 35 million gas / 200 gas per byte, or 170KB.

also as i mentioned, the cost for EXTCODESIZE and EXTCODECOPY could be tweaked. iiuc the bytecode is stored on disk with RLP encoding. you can peek at the first few bytes of the RLP-encoded bytecode to find out the size. but i'm not sure this optimization is worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, and i should update the wording to clarify that this only applies to the access cost for cold contracts. it does not apply to contracts which have already been accessed in the transaction.

@@ -0,0 +1,55 @@
---
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eip: 7907

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

The commit 06d6325 (as a parent of b09e3a7) contains errors.
Please inspect the Run Summary for details.

@github-actions github-actions bot removed the w-ci Waiting on CI to pass label Mar 16, 2025
EIPS/eip-7907.md Outdated
eip: 7907
title: Remove Contract Code Size Limit
description: Removes the contract code size limit introduced in EIP-170 and adds a gas metering to code loading
author: Charles Cooper (@charles-cooper)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
author: Charles Cooper (@charles-cooper)
author: Charles Cooper (@charles-cooper), Qi Zhou (@qizhou)

Since this draws heavily from Qi Zhou's work I think he should be credited.

Qi Zhou (@qizhou)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually did not become aware of Qi's EIP until after i drafted it. i'm happy to credit him and add as an author if he requests it though.

cc @qizhou

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically the same EIP with different constants.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am glad to see the progress in increasing contract code size, which is a long pain for contract developers. Feel free to add me as a co-author; I would love to push the EIP further together.

Copy link
Contributor Author

@charles-cooper charles-cooper Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am glad to see the progress in increasing contract code size, which is a long pain for contract developers. Feel free to add me as a co-author; I would love to push the EIP further together.

please see 18bb9c1

EIPS/eip-7907.md Outdated
eip: 7907
title: Remove Contract Code Size Limit
description: Removes the contract code size limit introduced in EIP-170 and adds a gas metering to code loading
author: Charles Cooper (@charles-cooper)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am glad to see the progress in increasing contract code size, which is a long pain for contract developers. Feel free to add me as a co-author; I would love to push the EIP further together.


EIP-170 introduced a 24KB contract code size limit to prevent potential DoS attacks, as large contract code requires O(n) resource cost in terms of disk reads, VM preprocessing, and Merkle proof sizes, all of which are not directly compensated by gas fees. However, this hard limit restricts legitimate use cases for large contracts.

Rather than imposing an arbitrary size limit, this EIP proposes a gas-based solution that allows contracts of any size while ensuring that users loading very large contracts pay gas proportional to the additional resources they consume. This approach aligns with Ethereum's gas model philosophy of paying for the resources consumed.
Copy link
Contributor

@qizhou qizhou Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One side effect of the unlimited size of contract code is that it may break the p2p sync assumption - a large-size contract code may not fit in a single p2p packet. We found such an issue in geth ~2 years ago. It may be worth double-checking the issue in the latest clients.

Copy link

@cupOJoseph cupOJoseph Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the p2p packet size is an order of magnitude more than 24kb. Even just double or tripling this, without breaking anything else, would be a huge improvement for the developer experience.

We could spend a year researching the downstream effects of making it infinite, and optimizing gas costs, etc..

If there's a path to even just 1.5X'ing the limit without making much bigger protocol changes we need to do that ASAP. and I will gladly help with dev work if you need more hands to get it done, please just direct me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One side effect of the unlimited size of contract code is that it may break the p2p sync assumption - a large-size contract code may not fit in a single p2p packet. We found such an issue in geth ~2 years ago. It may be worth double-checking the issue in the latest clients.

How big was the packet? Because of the 200 gas per byte cost to deploy a contract, there is a code size limit implied by the transaction gas limit (currently around ~170kb).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devp2p eth wire packets can be up to 10 MB so I wouldn't be too worried about that.

However it does seem reasonable to set an explicit upper bound even if it isn't strictly necessary. The reason being, if we want to increase the gas limit, we want to minimize the number of things that scale with it.

Copy link
Contributor Author

@charles-cooper charles-cooper Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm willing to add an upper bound if it's a hard requirement from ACD. however, my hope is that we don't need another EIP + hard fork every time that we want to increase contract sizes, but rather that it scales naturally as gas limit increases.

i do understand though the peace of mind that comes with limits in the protocol. if we do add a limit, i would want to add to the EIP what considerations it is bounded by (disk space assumptions on the client? p2p?) so that when it comes up for discussion again, people know exactly what variables were considered during this EIP, rather than letting them guess about "unknown unknowns".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EIP-7825 may provide a de-facto limit. But we may want to add a hard coded limit anyway that is a function of that to ensure the code deposit can be paid. Otherwise it could be griefed by initcode.

Perhaps 63/64 of the tx gas cap divided by the code deposit cost per byte? that would be 147,656 bytes or just under 144.2K. A round binary number would be 147,456 (0x24000 or 144K, or 6x the current limit).

@cupOJoseph
Copy link

cupOJoseph commented Mar 18, 2025

Dear god yes this looks incredible. Thank god for @charles-cooper and @qizhou, you guys freaking rock!!!

I dont see any reason to make this more complex than it needs to be though. Even just raising the limit significantly will be a big help – without it needing to be infinite. If we can get to the 170 KB that is mentioned, or even close to it, without breaking anything else then that would be a humungous win and we should do it as fast as possible.

If making other changes to the protocol messes with the p2p packet size and is going to take longer to handle all the trade-offs, my preference (as a dev who has worked on MANY max size contracts) would be just get the simplest increase possible done.

@ColinPlatt
Copy link
Contributor

This is amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-new Creates a brand new proposal e-consensus Waiting on editor consensus e-review Waiting on editor to review s-draft This EIP is a Draft t-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants