-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
base: master
Are you sure you want to change the base?
Add EIP: Remove Contract Code Size Limit #9483
Conversation
File
|
EIPS/eip-remove-codesize-limit.md
Outdated
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)) |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
EIPS/eip-remove-codesize-limit.md
Outdated
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
EIPS/eip-remove-codesize-limit.md
Outdated
@@ -0,0 +1,55 @@ | |||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eip: 7907
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit 06d6325 (as a parent of b09e3a7) contains errors. |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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).
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. |
This is amazing! |
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: