ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.01k stars 5.7k forks source link

Warning or error if code is too large #2100

Closed chriseth closed 4 years ago

chriseth commented 7 years ago

Contract bytecode cannot exceed 0x6000 bytes (introduced with EIP-170 in Spurious Dragon) and the compiler should warn about this. Unfortunately, this cannot be a "regular" error since those have to be generated before code-generation is started. This is similar to warning about a fallback function taking too much gas: https://github.com/ethereum/solidity/issues/411

axic commented 7 years ago

We could introduce a new kind of exception instead of assert.

Also, this should depend on the target EVM version (#1117).

axic commented 5 years ago

Just like #411, perhaps it is better to implement this in the Remix static analyzer. @yann300 @soad003 what do you think?

wjmelements commented 4 years ago

Duping https://github.com/ethereum/solidity/issues/7913

In addition to the warning, which would be easy to add, I also request a flag to ask the compiler to attempt to constrain code size.

wjmelements commented 4 years ago

It is also possible to workaround size limit via delegatecall by deploying part of the code to another contract during construction. The primary contract would delegatecall to a secondary contract as its fallback function. This can chain infinitely, leveraging the fact that calldata can be larger than max contract size.

wjmelements commented 4 years ago

For the current block gas limit, it would be possible to do 2 full-sized contracts in this way, but a larger block gas limit might empower more in the future.

alcuadrado commented 4 years ago

I've seen many people hitting the EIP-170 contract size limit lately. Some examples of projects that come to my mind are Aragon Court, Synthetix, and Moloch v2.

I don't know if this is due to a change in Solidity, or because contracts are just getting larger, but this feature would be very helpful. Many users just see an OOG error and don't understand what's going on, so a warning when compiling would help.

I know this could be implemented in each tool (e.g. truffle, remix, embark, buidler, etc), but I think implementing it as a solc warning would be the simplest path to improve the situation for most users.

axic commented 4 years ago

@alcuadrado please check #8008 and the warning it produces. I think that should be good enough.

alcuadrado commented 4 years ago

Wow, that was fast! Thanks @axic

chriseth commented 4 years ago

The reason why we did not implement this in the beginning is because the complier should not issue any warnings after the analysis phase. I'm ok with dropping this requirement, if this is what people want, though.