Ganache-cli: Parameter gasLimit do not behave as expected

Created on 10 Sep 2017  路  12Comments  路  Source: trufflesuite/ganache-cli

Expected Behavior

If we specify a gasLimit when starting TestRPC using parameter --gasLimit=X, X being greater than the default limit of 0x47E7C4, transactions that exceed this limit and do not exceed X should be accepted.

Current Behavior

TestRPC rejects the transaction with out of gas error message. The gas usage output shows that the limit was not changed:

  Transaction: 0xcb637787dcf5e5ccc0c0652708de67354a0c23e070fc525ca8c782297705d069
  Contract created: 0xd270ec8b866675de42c82d336358bb8487e986da
  Gas usage: 4712388
  Block Number: 3
  Block Time: Sun Sep 10 2017 14:07:03 GMT+0400 (GST)
  Runtime Error: out of gas

If we start TestRPC using the command testrpc --gasLimit=0x87E7C4 and check the gas limit of the running instance using the nodejs code:

var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
console.log('gasLimit: ' + web3.eth.getBlock('latest').gasLimit);

We can see that the limit did change:

gasLimit: 8906692

But still, TestRPC rejects txs showing a gas usage of 4712388 as can be seem by the first print above.

Context

I got this error when trying to deploy a big smart contract for a private chain.

Your Environment

  • Version used: TestRPC v4.1.1
  • Environment name and version (e.g. PHP 5.4 on nginx 1.9.1): nodejs v6.11.1
  • Operating System and version: Linux Ubuntu 16.04

Most helpful comment

I can confirm that we still have this issue.
Now there is a hard limit at 6,721,975 no matter what number we give at the configuration.
It happens both in testrpc and truffle develop.

All 12 comments

I think I hit the same issue, 4.1.3 seems to have this issue as well, 4.0.0 seemed ok instead

I've just got this issue as well and have replicated @danielnovy results in regards to setting the gas limit and it not being honored.

I have a contract that imports 3 token contracts and uses them. I think I can confirm it isn't a code issue as if I remove reference to one of the tokens it works ok. It doesn't matter which one I remove, eg I can use token 1 & 2 or 2 & 3 or 1 & 3, as soon as I add the 3rd one in, I get the error @danielnovy reported above.

running in docker on OSX. Version EthereumJS TestRPC v4.1.3 (ganache-core: 1.1.3)

Going to try 4.0.0 see if I have any luck with that.

Tested, 4.0.0 works. I suggest to those who feel at odds about using an older version to avoid the global installation and instead opt for a local installation:
npm i -D ethereumjs-testrpc
./node_modules/.bin/testrpc -l 6e6 (6'000'000 gas limit, closer to current data on ethstats)

@danielnovy @makevoid @fridaystreet
Sadly enough, I believe that my previous statement was a false positive - whatever worked was unrelated.

But I've since found the actual issue: truffle's config. If you are seeing this:

Transaction: 0xcb637787dcf5e5ccc0c0652708de67354a0c23e070fc525ca8c782297705d069
  Contract created: 0xd270ec8b866675de42c82d336358bb8487e986da
  Gas usage: 4712388
  Block Number: 3
  Block Time: Sun Sep 10 2017 14:07:03 GMT+0400 (GST)
  Runtime Error: out of gas

What that tells you is how much truffle has sent for gas. If truffle tried to send more than the limit, you'd get error on truffle's side. The fix is simple:
truffle.js

{
      // ...
      host: "localhost",
      port: 8545,
      gas: 6000000, // <-- this line tells truffle about the spending
      network_id: "*" // Match any network id
      // ...
}

And so, I amend my previous statement: new versions of testrpc have no issue in them.

I can confirm that we still have this issue.
Now there is a hard limit at 6,721,975 no matter what number we give at the configuration.
It happens both in testrpc and truffle develop.

Same here a 6,721,975 hard limit! ignoring higher custom limit set at init.

Is there any progress on this?
We are still getting stuck on this hard limit of 6,721,975

This issue (we still exists on:
Ganache CLI v6.1.0 (ganache-core: 2.1.0)

It's still impossible to deploy a contract that is above 6.7 million gas limit.

I'm using a private Blockchain with custom genesis block setting the gas limit to 16,000,000.
I wish a could do the same on Ganache !

BTW, even the current gas limit on the main net is about 8,000,000 now..

Hey everyone!

Sorry!

Let me start off with: I'm sorry it's taken so long for one of the Truffle devs to address this issue. We're doing what we can to try to address all these Issues. With that said, thank you so much for being patient and pinging us on the problem!

Question for you

Am I correct to say "you only have this issue when deploying a large contract"? It's not like other transactions are reaching this limit (it'd be pretty hard to)? Please correct me if I'm wrong. The rest of this comment is geared around this assumption.

The 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 the limit, as it will still fail due to another check, and it will report out of gas.

What we're doing about it

There is a PR that I introduced in the ethereumjs-vm project to allow this EIP-170 check to be ignored.
While that PR has been merged, I still need to finish the PR to allow this to be incorporated into ganache-cli/core (https://github.com/trufflesuite/ganache-core/pull/79). Hopefully soon!

Very Important: What you should do about it!!

The feature that I am introducing in https://github.com/trufflesuite/ganache-core/pull/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.

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. There may be other reasons, but you're heading into advanced mode and you should proceed cautiously. We don't want users to flip this flag to "move on" in development only to find that won't deploy to Rinkeby/Ropsten/Mainnet.

Thanks again!

Let me know if you have any questions

Yes @seesemichaelj your assumption is correct.
Thank you very much!

The code that supports the allowUnlimitedContractSize flag in Ganache was merged in https://github.com/trufflesuite/ganache-core/pull/126. This should be in the next release of ganache-cli.

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.

The flag was added to ganache-cli in https://github.com/trufflesuite/ganache-cli/pull/550

Was this page helpful?
0 / 5 - 0 ratings