Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Ganache fails to deploy contract with >29kb binary #674

Closed
XertroV opened this issue May 28, 2018 · 9 comments
Closed

Ganache fails to deploy contract with >29kb binary #674

XertroV opened this issue May 28, 2018 · 9 comments
Assignees

Comments

@XertroV
Copy link

XertroV commented May 28, 2018

Have added as much detail (+example you can clone) as I could in reasonable time, LKM if you need more deets.

Expected Behavior

  • Can deploy contract of any size

Current Behavior

With one of my contracts (links below) I cannot deploy the contract when it is above 29kb. Note: there might be other things going on but based on commenting out code (which is used it multiple places and not used in deployment) the deploy can succeed where otherwise it'd fail. Also, compiling is fine, and it's always the deployment step that fails.

I've confirmed that this is not a real out of gas error by setting the gas limits much higher than needed (20m).

Possible Solution

Not sure exactly what to do about it, but the problem exists in both EthereumJS TestRPC v6.0.3 (ganache-core: 2.0.2) and Ganache CLI v6.1.0 (ganache-core: 2.1.0)

Steps to Reproduce (for bugs)

  1. in another terminal window run ganache-cli -l 20000000 (20m gas limit per block)
  2. clone the repo: git clone https://github.com/secure-vote/sv-light-smart-contracts
  3. cd sv-light-smart-contracts
  4. git checkout test/ganache-size-working
  5. yarn test test/svLightIndex.js -- this should "work" in that some test fail but contracts deploy
  6. git checkout test/ganache-size-broken
  7. yarn test test/svLightIndex.js -- this fails - all test fail on out of gas

Context

Limits the size of contracts we can develop (note: although there might be some bad reasoning around mainnet (e.g. mainnet gas limit is X so what's the point supporting above X)) these conditions don't hold true for private networks.

Also it's often nice to be able to develop and then break up, as opposed to trying to break up just because ganache-cli doesn't work.

The error occurs in the tests (when broken) here: https://github.com/secure-vote/sv-light-smart-contracts/blob/cffb4ce137f1b299b68570ec11481f63547f00c4/test/svLightIndex.js#L77

I have set the default gas to use in truffle as 19m (see truffle.js) and I run ganache with a limit of 20m. Usually the gas to deploy is like 6.5m when everything is working, so this is not a real out of gas error.

This is the function where I'm commenting out the body:

working: https://github.com/secure-vote/sv-light-smart-contracts/blob/e1c095ab29f865dcc53ff6ccee609d934d885888/contracts/SVLightIndex.sol#L577
failing: https://github.com/secure-vote/sv-light-smart-contracts/blob/cffb4ce137f1b299b68570ec11481f63547f00c4/contracts/SVLightIndex.sol#L577

You can see the commit history in the branch f/brokenTestRPC

Your Environment

@cgewecke
Copy link

@XertroV This could be because ganache-cli implements EIP-170 which was included in the Byzantium fork and limits contract sizes. @seesemichaelj (one of the ganache engineers) has been working to make that optional although AFAIK those vm changes haven't made it into a build here yet.

If you need a short term workaround - ethereumjs-testrpc-sc is a coverage enabled ganache fork used by solidity-coverage which has EIP-170 turned off. (It's basically ganache-cli 6.1.0.)

$ npm install --save ethereumjs-testrpc-sc
$ ./node_modules/.bin/testrpc-sc --port 8545 --gasLimit 0xfffffffff # Example launch

@mikeseese
Copy link
Contributor

Thanks @cgewecke! It is correct that the ignore EIP 170 PR (trufflesuite/ganache#79) hasn't been merged yet due to me not completing the tests.

I'll follow up on this issue when it is merged and scheduled for release

@XertroV
Copy link
Author

XertroV commented May 28, 2018 via email

@mikeseese
Copy link
Contributor

That's a great suggestion @XertroV! I'll look into it

I'll keep this issue open until it's addressed in ganache-core for others to find it

@mikeseese mikeseese self-assigned this May 29, 2018
@ekreda
Copy link

ekreda commented Jun 4, 2018

Also waiting for this fix, as we have contracts over 6.7 m of Gas.

@mikeseese
Copy link
Contributor

mikeseese commented Jun 4, 2018

Hey everyone!

I just wanted to clear things up by explaining what's causing this issue.

This is not a problem of gas (despite the error is "out of gas"). EIP-170 states:

If block.number >= FORK_BLKNUM, then if contract creation initialization returns data with length of more than 0x6000 (2**14 + 2**13) bytes, contract creation fails with an out of gas error.

This means that the binary code that is being uploaded must be less than or equal to 0x6000 bytes (or 24 Kibibytes) to deploy. It won't matter how much gas you put, as it will still fail due to another check, and it will report out of gas.

The feature that I am introducing in trufflesuite/ganache#79 is supposed to be used for debugging purposes only! We strongly encourage you to determine what is causing your contract bytecode to be too big as it will not deploy to any Ethereum chain based off Spurious Dragon.

Note: It is likely that you are not optimizing your compilation. See https://solidity.readthedocs.io/en/develop/using-the-compiler.html?highlight=optimize for details.

The only reason that you should use the flag to allow larger contracts is if you're using a debugger which requires you to not optimize the compilation.

@mikeseese
Copy link
Contributor

The code that supports the allowUnlimitedContractSize flag in Ganache was merged in trufflesuite/ganache#126. This should be in the next release of Ganache.

This is only for debug purposes!

As previously mentioned, this issue should be addressed by optimizing the compilation of your contracts so they fit within the 0x6000 byte limit in EIP 170. The flag is only for debugging purposes which require the optimization to be disabled.

@w5pand
Copy link

w5pand commented Mar 28, 2019

The code that supports the allowUnlimitedContractSize flag in Ganache was merged in trufflesuite/ganache-core#126. This should be in the next release of Ganache.

This is only for debug purposes!

As previously mentioned, this issue should be addressed by optimizing the compilation of your contracts so they fit within the 0x6000 byte limit in EIP 170. The flag is only for debugging purposes which require the optimization to be disabled.

Is there a plan to add a setting to support fo "EIP-170" in "Gananche"?

@mikeseese
Copy link
Contributor

@w5pand #1020 is an open issue awaiting triage, but likely won't be implemented soon.

There is an advanced-user, non-supported method for enabling this for the GUI. You can read the comments here: trufflesuite/ganache#1019 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants