foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat: Make eth_call gas limit configurable

Open Theo- opened this issue 3 years ago • 8 comments

Component

Anvil

Describe the feature you would like

Using a multicall contract to read a lot of data at once is a common use case. Anvil caps the gas limit of eth_call to the maximum gas limit of a block. I'm running into EVM error CallerGasLimitMoreThenBlock when trying to read lots of data from a multicall contract (> 100 calls)

Additional context

For any eth_call, set the gas limit to 18446744073709551615 (the maximum possible value)

Theo- avatar Nov 29 '22 00:11 Theo-

there's the --gas-limit argument to set this to any value.

      --gas-limit <GAS_LIMIT>
          The block gas limit

I guess we could add an alias for max?

mattsse avatar Nov 29 '22 10:11 mattsse

@mattsse this argument is very useful when calling evm_mine to create new block, I don't think the same limit should apply to eth_call. What is the reasoning behind limiting the gas_limit on a eth_call?

Btw, I really appreciate how responsive the Foundry/Anvil team is ✨ thank you all for the great work

Theo- avatar Nov 29 '22 15:11 Theo-

eth_call is executed without creating a transaction on the chain, and instead returns the result as it would if included in a block. So we don't want to return a success if the call would actually fail if mined.

but I'm not sure if the same applies to hardhat.

there's also anvil_setBlockGasLimit that you can use to set the block gaslimit an the fly.

mattsse avatar Nov 29 '22 18:11 mattsse

anvil doesn't seem to respect the block gas limit for eth_call because setting the gas limit to 18446744073709551615 still results in CallerGasLimitMoreThenBlock (which has a misspelling by the way). This issue from a month ago reports the same bug and is also still open. Will this be fixed?

sewinter avatar Dec 04 '22 00:12 sewinter

Experienced the same issue while forking Goerli, call via multicall which were working on Goerli go CallerGasLimitMoreThenBlock for some reason in anvil.

Alexintosh avatar Jan 19 '23 16:01 Alexintosh

I think that setting the env var mentioned here will probably fix it. I'm not a rust dev though, so I'm not sure how to do this exactly. Can someone weigh in?

sewinter avatar Jan 22 '23 20:01 sewinter

Same behaviour here. I made a mainnet fork using anvil and changed the gas limit to 100M, but when I cast call my contract's view function (contract which needed the --via-ir flag btw), I get the CallerGasLimitMoreThenBlock error when I put a gas limit higher than 30M (which iirc is the original block gas limit)

raphdeknop avatar Jan 24 '23 00:01 raphdeknop

I get the CallerGasLimitMoreThenBlock error when I put a gas limit higher than 30M (which iirc is the original block gas limit)

can't reproduce this, sorry.

This issue is a bit difficult for me to understand, because:

  • block gas limit
  • call gas limit

are configurable

and CallerGasLimitMoreThanBlock is a constraint violation, so I'm actually not sure what the issue here is. If you set the tx gas limit > block gas limit, it should fail even in eth_call, no?

that being said, I'll enable the optional_block_gas_limit feature and add a new flag.

mattsse avatar Feb 10 '23 09:02 mattsse