0

Let's say I want to do a simple call to a public view function, what's the limit of instructions I can pass to this function?

For example

function something() public view returns (uint256) {
return 1 + 1 + 1 + 1 * 2;
}

Is there a limit written somewhere to the theoretical "gas" that the EVM will willingly compute?

2

The answer to this question is actually much more interesting than it seems :-).

If you're doing this call on-chain then you're limited by the block gas limit minus the amount of gas that you need to use to be able to trigger the call in the first place.

However... if you're doing this off-chain (e.g., a front-end is using the eth_call RPC method) then your actual limit will fully depend on the specific node you're querying! Check out the following line of code from go-ethereum:

result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, 5*time.Second, s.b.RPCGasCap())

Nodes are allowed to set a gas limit higher than the block gas limit specifically for RPC calls like eth_call in the form of the s.b.RPCGasCap() variable being passed into the DoCall function. However, Geth also has a built-in timeout of 5*time.Second = 5 seconds so calls will automatically fail if they haven't completed after that amount of time. Nodes can choose to modify this timeout if they'd like, but I assume most nodes leave this untouched.

So the real (and unsatisfying) answer is "it depends". I believe node providers like Infura do set this RPC gas cap to be much higher than the block gas limit by about 2x (~60m gas?). I'm not 100% sure though, I would have to do some experimentation to figure that out.

0

That would be the block gas limit. Any transaction that is more expensive than the block gas limit would automatically revert since you can't have a transaction spread across multiple blocks.

2
  • 2
    A transaction with higher gas than the block gas limit will not be executed and it will remain in the pending pool.
    – Ismael
    Sep 4 at 22:14
  • wasnt aware of that, assumed it just reverted. Thanks for the precision :)
    – Foxxxey
    Sep 4 at 22:59

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.