-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Removing Contract Size Limit #1662
Comments
If your contract is 24KB or larger, your contract architecture needs a seriously big redesign |
Thank you for your feedback. That's a debatable point but I get why you think so. Contract size increases due to multiple factors that don't really add to the complexity of the code. For example,
Obviously, the contract size also increases when you add functionality. |
i agree with @maxsam4, we at NexusMutual have complex logic that are split into multiple smaller contract. Have a look here: https://github.com/somish/NexusMutual/tree/token/contracts |
I would support at least a minor increase in the smart contract max size, sure you can usually split logic into several contracts but with reason strings and developers learning more about options for Smart Contract design, I believe an increase (even if minor) is due. |
As a note, the contract size limit can be removed by implementing ERC1538. |
Yep, that is one way to do it but it's not optimal because of limitations like:
I am still collecting feedback on this. I think there are 3 basic ways that this proposal can go:
|
👍🏻 Agree with @maxsam4. Would also support the increase in contract size limit.
|
I agree with @maxsam4 , even after making use of library contracts, proxy patterns, breaking huge contracts to multiple smaller contracts, there still comes a point which requires the smart contracts' byte code to be extended beyond a certain limit. It's just not developer-friendly to restrict the developers to develop smart contracts to limited complexity. |
I also agree with the importance of fixing the contract size limit issue. |
I'm hitting the same limit. Libraries aren't enough.. I don't care about high(er) deploy costs at whatever level, for some larger contracts that need to deal with asset transfers, you need the transaction costs to be low and deploy cost means very little at scale. Meanwhile, cross-links (contracts with state to member contracts via interfaces) are useful as well. But they still run into the same issue as mentioned above. Increasing it to one of the earlier suggestions of 2^15 would be almost a substantial amount more headroom than currently. |
Thanks everyone for the feedback! I think I have got enough feedback to justify moving forward with this Idea. I will try to draft a proper proposal/document this weekend and will collect feedback on it via different mediums. |
I have summed up most of my thoughts regarding this in a small write up available at https://ethereum-magicians.org/t/removing-or-increasing-the-contract-size-limit/3045 Please have a look. All feedback is welcome. |
@maxsam4 over on Ethereum Classic we don't yet have a size limit and are debating adding EIP-170. This is a viable alternative, I have a question. Why do we need to cache the size data into the account tuple. Can't we do it without changing the account format? Cant we just have the EVM load a contract's bytecode and then determine the gas cost and charge it at that point? |
That introduces another attack vector where the attacker forces the EVM to load a huge contract even when there is not enough gas remaining to load it. If the size is not cached, EVM will be forced to fetch the large contract only to realize that there isn't enough gas left to load that contract in the first place. |
@maxsam4 I have a couple of arguments against that, if at least one of them is right, my amendment to your proposal should be fine.
Thanks |
@zmitton Thanks for your feedback! I am afraid that neither of those solutions will work. Here are some of my thoughts
To be honest, on the ETC side, if you are not planning on increasing block gas limit by much then it might be best to increase the price of all calls, delegate calls etc by a fixed amount and remove the contract size limit. With 8m block gas limit, there is a natural limit of ~40 KB. On the ETH front, there are talks to increase the gas limit by as much as 300% so that is not an as viable solution. |
But we don't need to force it. The consensus rule is that payment is dependent on bytecode length, and how that is implemented is up to the client. Caching the length data somewhere is simply an optimization, that can and (I would argue) should be done by any production client software. |
The point is that if there are reasonable ways to do it, then there isn't a problem implementing the rule. |
By the way, skimming through the link you posted, I don't think any of that stuff applies. It's mostly about Ethereum-specific design plans |
That's what the original proposal wants. However, you need to see the practical aspect as well. If the clients don't implement the optimization then it is ddos vector. Therefore, this proposal mandates the clients to implement this optimization. As with the gas mechanics, you set the price of any action to anything but the price is actually determined by practical costs. For some clients, the cost may differ but we try to pick a generic cost. Feel free to implement this however you wish in ETC but as ETH has so many clients, I think it is necessary to make this "optimization" mandatory so that all the current and future clients end up implementing it.
Yeah, I felt that too. |
ok thanks @maxsam4 I think I have a good understanding now. So I now realize that the difference mostly a backwards compatibility issue I was likely trying to avoid. i.e. having the extra field affects the tree hashing and therefore affects the root and therefore the consensus and is a hard fork. But of course changing the gas costs is a hard fork anyway, so it's all pretty similar. My way would affect a little less related software, but would make client implementation easier to screw up. Thanks for the ideas! |
@jbaylina had what I think was a great suggestion. |
Moloch v2 is currently struggling with this, for what it's worth. I hate libraries because of the indirection and overhead they introduce, and now I find myself refactoring, stripping comments, shortening events, and possibly shortening variable names just to make it fit... |
We are dealing with it at Synthetix as well on our main Synthetix contract. You can also try shortening revert reasons like we did 😒Although we've found the eth-gas-reporter tool by @cgewecke really helpful for this. |
We are suffering the same problem at the EIP-2020 on IoBuilders due the amount of logic. Eternal storage and contract size mixed together is a nice refactor duty :) |
Vitalik proposed something similar as a solution to limit witness size in stateless clients: https://ethereum-magicians.org/t/protocol-changes-to-bound-witness-size/3885 |
ERC1538 gets rid of the contract size limitation. I am not against getting rid of the native limitation in Ethereum, but I don't want to downplay the benefits of ERC1538.
ERC1538 only adds code if you don't want the other benefits that ERC1538 provides such as:
Which can be secured.
This is not true. The gas costs for internal functions are the same.
This is only true for lack of UI tooling. This standard actually provides better possibilities for UI tooling because it stores its ABI within it that can be retrieved. I am now looking for UI designers/programmers to help create user interfaces for ERC1538 contracts.
This again is a tooling matter that can be remedied by user interfaces with support for ERC1538. |
FYI - a hotfix is to use the optimizer (updated truffle-config to add this):
Worked for Moloch v2 but if it was bigger this would still be an issue. |
@ameensol lowering the |
Now there is the diamond standard for upgradeable contracts, that like ERC1538, solves the max contract size limit. Here are some reasons to use the diamond standard:
|
As an alternative solution to this problem, A few friends and I are proposing adding a simple router functionality in solc itself so that developers can safely workaround the 24kb limit without thinking much about edge cases. Feedback is welcome: ethereum/solidity#11102 |
There has been no activity on this issue for two months. It will be closed in a week if no further activity occurs. If you would like to move this EIP forward, please respond to any outstanding feedback or add a comment indicating that you have addressed all required feedback and are ready for a review. |
This issue was closed due to inactivity. If you are still pursuing it, feel free to reopen it and respond to any feedback or request a review in a comment. |
Is there examples of current protocols (still?) using ERC1538 ? |
Abstract
A contract size limit of 24kb was introduced by EIP #170 . To solve the following problem problem: "when a contract is called, even though the call takes a constant amount of gas, the call can trigger O(n) cost in terms of reading the code from disk, preprocessing the code for VM execution, and also adding O(n) data to the Merkle proof for the block's proof-of-validity". I think we can solve this problem while still allowing infinite contract size.
Motivation
Complex dApps require complex smart contracts. I have seen a lot of dApp developers struggle with this and a lot of alternative solutions are being used like using delegate calls. Delegate calls reduce code readability while developing and while verifying source code on tools like etherscan. They also introduce another attack surface and added complexity.
Specification
codeSize
apart from existing 4: [nonce,balance,storageRoot,codeHash]codeSize
of the account object.codeSize
should also be reset.CALL
,DELEGATECALL
,CALLCODE
etc should charge additionalX
(3?) gas per extra word if the contract code size is greater than 24kb.Rationale
The only reason why contract size was limited was to prevent people from exploiting the fixed costs. We can overcome this by making the costs variable. The
codeSize
element will help in calculating call cost before reading the whole contract and eventually throwing OOG. Merkle proofs will also be generated at fixed cost as we won't have to load the huge contracts from disk first. ThecodeSize
should be enough.Backwards Compatibility
We don't necessarily need to refactor the existing account arrays as all the existing accounts have less than 24kb of code so no extra cost has to be charged from calls being sent to them. We can assume
X = 0
if it's not available.This will mean that there are no backward compatibility issues.
This is just an early discussion Issue. I will create a properly formatted draft with specifications after getting some more feedback from the community.
References
#170
#659
https://github.com/ethereum/wiki/wiki/Patricia-Tree#tries-in-ethereum
The text was updated successfully, but these errors were encountered: