matter-labs / foundry-zksync

Fork of Foundry tailored for zkSync environment
Apache License 2.0
299 stars 130 forks source link

Specifying `--block-gas-limit` doesn't do anything for `--zksync` #580

Closed dontonka closed 1 month ago

dontonka commented 2 months ago

Component

Forge

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.0.2 (df011e0 2024-09-17T00:19:22.777559581Z)

What command(s) is the bug in?

forge test --block-gas-limit=30000000000 --chain-id=324 --zksync --zk-force-evmla

Operating System

Windows

Describe the bug

Hello, I'm doing some test with --zksync and get few failures due to the block gas limit being too small. Overriding --block-gas-limit works properly on non-ZkSync Era EVM (so when not providing --zksync, but not otherwise).

Be aware that forge still seems to at least ingest the parameter properly as forcing a wrong value will make it complain right away and not even execute the command, but somehow it doesn't seem to apply it during execution and seems to be always hardcoded to ~78M (at least in my environment).

elfedy commented 1 month ago

@dontonka this seems to be in line with how our foundry implementation works:

  1. Tests are executed on the EVM.
  2. Whenever a CALL/CREATE is found that call is intercepted and an instance of the ZkSync Era VM spawn to execute that transaction. The tx result is taken and we report the gas spent back to the evm, among the rest of the relevant tx result values. For this transaction, we set the gas limit to the tx sender's balance, capped to 2 ^ 32 -1. However, there's a system constant that caps the actual gas limit used to 80M. The gas limit above that is paid for by the caller, but then refunded. The 78M that you see is that cap minus the overhead gas which is deducted before executing the transaction.

block-gas-limit will allways apply on the root evm transaction of the tests, it won't cascade down to Era VM txs due to the difference in environments (Although if the Era VM tx consumes more gas than the block gas limit, the evm will fail with out of gas). Modifying the system constant in any way is out of scope for now and maybe not desirable.