11

I am trying to figure out how big could a contract be? Is it possible to have 10k functions? One million? More?

Is there any restriction on the function's body size?

Does a bigger contract need more gas to be deployed?

Is a bigger contract slower than a smaller one?

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143
StanislavL
  • 287
  • 3
  • 14
  • 4
    You can distribute your code over several of contracts. You do not need to deploy the code in a single transaction. – Mikko Ohtamaa May 04 '18 at 15:33
  • 1
    Now there is the Diamond Standard that solves the max size issue: https://github.com/ethereum/EIPs/issues/2535 – Nick Mudge Mar 23 '20 at 15:34

2 Answers2

13

Solidity contracts are compiled to EVM bytecode. Contract bytecode costs 200 gas per byte of bytecode, and since block gas limit is 8 million right now, you could theoretically get a ~40,000 (a little less since there's extra for deployment/tx data) byte contract deployed. It's unlikely that you'd be able to create a contract this size though since blocks don't usually have that much extra space already. Regarding execution speed, this is totally dependent on your implementation.

Edit: As pointed out by @Ismael, there's actually a 32kb limit per transaction as explained here. That page also says there's also a 24576 byte limit for contract size, so I stand corrected! The EIP for the contract byte limit can be found here.

Edit2: If you're looking for a formal explanation for the contract size limit, check out definition 97 of the yellow paper:

Yellow Paper Definition 97

That is, the output size of the final body code must not be bigger than 24576 bytes.

natewelch_
  • 12,021
  • 1
  • 29
  • 43
  • 3
    Also you have hard limit of 32kb per transaction https://ethereum.stackexchange.com/a/46612/. – Ismael May 04 '18 at 15:10
2

You can get around the contract size limitation by using the Transparent Contract Standard: https://github.com/ethereum/EIPs/issues/1538

mudgen
  • 159
  • 5