6

I have two contracts A and B, both deploy and work correctly in ganache (they both use less than 6M gas). Now I want to create a third contract C that inherit both A and B.

contract C is A, B {
}

This contract C fails to deploy with out of gas exception. But gas should not be an issue because ganache is configured with a block gas limit of 4 billion.

After trial and error commenting out my code, I found it fails with a public function in contract B. After reordering functions I found it doesn't matter which function in particular, it will fail if there are more than N public functions in contract B.

Update: Trying the deploy the same contracts in a geth private testnet causes the error "oversized data". So I think is not the number of public functions but the resulting contract is too big.

  • So i take it your tried changing the last public function to internal or external ? – Kaki Master Of Time Apr 24 '18 at 13:14
  • 1
    Yes, changing function to internal or private will make it work. I didn't try external. – Ismael Apr 24 '18 at 13:19
  • what is the exact error you are seeing, any chance its 'Stack too deep'? – Lucas Hendren Apr 25 '18 at 0:09
  • @Legman As mentioned in the question the error out of gas when deploying the resulting contract. – Ismael Apr 25 '18 at 1:12
5

There is exactly one place in geth code where "oversized data" is thrown. It's in func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error.

Heuristic limit, reject transactions over 32KB to prevent DOS attacks

Moreover, there is also a limit for bytecode size of a smart contract. It's 24576 bytes (see protocol_params.go).

maxCodeSize can be set in genesis.json. 32KB for TX size limit is a hard-coded constant in the code.

  • I think you are right, it is not about public functions, it is just happen that public function generate more code and that little extra pushes the code beyond the accepted size. – Ismael Apr 25 '18 at 17:38
  • how to set maxCodeSize? is it under the config? – Nathan Aw Aug 2 '18 at 10:00
  • It‘s a constant in the code. – ivicaa Aug 2 '18 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.