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

--miner.callGasLimit implementation is wrong #1645

Open
MicaiahReid opened this issue Nov 23, 2021 · 5 comments
Open

--miner.callGasLimit implementation is wrong #1645

MicaiahReid opened this issue Nov 23, 2021 · 5 comments

Comments

@MicaiahReid
Copy link
Contributor

The purpose of the miner.callGasLimit option is to set a cap on gas that is used in an eth_call/eth_estimateGas RPC call (as in geth's --rpc.gascap option). The purpose of this option is to prevent a DOS attack wherein a contract is uploaded with an infinite loop and eth_call is used on that contract, causing miners to work very very hard.

Currently, it's used as a default gas limit for a transaction that is calling eth_call/eth_estimateGas.

Fix it!

@anishnaik
Copy link

anishnaik commented Jun 30, 2022

Is there an update on this? I believe this is causing differential behavior b/w the latest release of ganache and the deprecated ganache-cli@6.12.2

eth_estimateGas is throwing an out-of-gas error when extremely large contracts are being deployed with the latest release (v7.3.2). This does not occur with the old ganache-cli. My working assumption is that it is because miner.callGasLimit is not being correctly used.

To reproduce, you can try to deploy ComptrollerHarness using hardhat (instead of saddle) + ganache.

This is the ganache-cli command:
ganache-cli --deterministic --gasLimit 10000000000000000 --allowUnlimitedContractSize

This is the ganache command:
ganache --deterministic --gasLimit 10000000000000000 --chain.allowUnlimitedContractSize

The ganache command returns the following error in hardhat:

     ProviderError: VM Exception while processing transaction: out of gas
      at HttpProvider.request (node_modules/hardhat/src/internal/core/providers/http.ts:78:19)
      at GanacheGasMultiplierProvider._getMultipliedGasEstimation (node_modules/hardhat/src/internal/core/providers/gas-providers.ts:72:59)
      at GanacheGasMultiplierProvider.request (node_modules/hardhat/src/internal/core/providers/gas-providers.ts:309:19)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

 {'message': 'VM Exception while processing transaction: out of gas', 'stack': 'RuntimeError: VM Exception while processing transaction: out of gas\n    at exactimate (/usr/local/lib/node_modules/ganache/dist/node/1.js:2:113332)', 'code': -32000, 'name': 'RuntimeError', 'data': {'hash': None, 'programCounter': 97, 'result': '0x', 'reason': None, 'message': 'out of gas'}}

The current working solution is to specify a gasLimit directly to the call for await ComptrollerHarness.deploy({gasLimit: some_limit}); however, this seems to hint at a larger problem.

@davidmurdoch
Copy link
Member

@anishnaik, gasLimit sets --miner.blockGasLimit and has nothing to do with the call gas limit. Use --miner.callGasLimit to change the call gas limit (which currently defaults to 50_000_000).

The v6 of ganache-cli used a different default value (Number.MAX_SAFE_INTEGER). We didn't list this as a breaking change because we were aligning with geth's default, so it was considered a fix at the time, but in retrospect it definitely should have made the breaking changes list; I've opened a PR to add this to the list of breaking changes: #3320

Sorry for any headache this has caused!

@anishnaik
Copy link

anishnaik commented Jun 30, 2022

Hi @davidmurdoch thank you for your response. I should have mentioned that I set the --gasLimit super high as a failsafe in case the gas per block was not large enough for the deploy call. Additionally, I also should have noted that even when I made --miner.callGasLimit = 9_007_199_254_740_991 which is (0x1fffffffffffff), the eth_estimateGas call still fails. This is why I placed this comment under this issue because it seems like the --miner.callGasLimit arg is not impacting eth_estimateGas calls. No matter how large I make --miner.callGasLimit, eth_estimateGas always fails. Note that with the old ganache-cli, I don't have to touch the value of --callGasLimit, which is 0x1fffffffffffff by default.

Based on this discussion in the geth github (ethereum/go-ethereum#18973) my hunch is that @MicaiahReid's point might be causing some whacky behavior.

The last thing I want to note is that the documentation on the npm website might be off? Based on your feedback, callGasLimit's default value is 50_000_000. However, according to the documentation found here, --miner.callGasLimit is documented to be 0x1fffffffffffff by default.

@anishnaik
Copy link

anishnaik commented Jun 30, 2022

Hi @davidmurdoch I have created a test environment for you / your team to go through this:
You can clone https://github.com/anishnaik/ganache-bug and checkout the bug branch.

The testing script is called deploy.js.

Ganache@7.3.2
Terminal 1

npm uninstall -g ganache-cli (if applicable)
npm install -g ganache
ganache -d -l 100000000000 --chain.allowUnlimitedContractSize --miner.callGasLimit 0x1fffffffffffff

Terminal 2

npm install
npx hardhat test deploy.js

This should fail with the following error:

  Deploy contracts for Echidna
    1) Deploy


  0 passing (110ms)
  1 failing

  1) Deploy contracts for Echidna
       Deploy:
     ProviderError: VM Exception while processing transaction: out of gas
      at HttpProvider.request (node_modules/hardhat/src/internal/core/providers/http.ts:78:19)
      at GanacheGasMultiplierProvider._getMultipliedGasEstimation (node_modules/hardhat/src/internal/core/providers/gas-providers.ts:72:59)
      at GanacheGasMultiplierProvider.request (node_modules/hardhat/src/internal/core/providers/gas-providers.ts:309:19)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

You can try to set a gasLimit for the deploy() call and if it is large enough, the test will pass.

ganache-cli@6.12.2
Terminal 1

npm uninstall -g ganache
npm install -g ganache-cli
ganache-cli -d --gasLimit 100000000000 --allowUnlimitedContractSize

Terminal 2

npx hardhat test deploy.js

This test should pass

This could also be a dependency issue in the hardhat environment?

Environment
MacBook Pro w/ Apple M1 Max
Hardhat v2.9.9
Ganache@7.3.2
ganache-cli@6.12.2

@davidmurdoch
Copy link
Member

Thanks for the additional information, we'll look into it! I've opened #3322 to correct the documentation issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Backlog
Development

No branches or pull requests

4 participants