What you fork a chain in foundry, what chain data does it copy? Does it copy OPCODEs and their gas as well?


1 Answer 1


Two values determine the behaviour of the fork tests in foundry:

  1. --fork-url and --fork-block-number: It simply fetches block states at specific block numbers such as chain ID, block timestamp, block coinbase, gas price etc. It plays a role in calculating the fee paid (in wei) per gas.

  2. --evm_version: It determines the EVM opcode and associated gas units. It plays a role in determining the gas consumption of your execution regardless of the forked state.

Let's have a look at the bytecodes created with different values for evm_version:

The latter uses PUSH0 while the former uses PUSH1 0, regardless of the value passed to --fork-block-number.

So, when you try to test your code containing an opcode not supported by the evm version set in the Foundry profile, it throws a "NotActivated" error.

When you try to deploy a bytecode containing unsupported opcode by the chain, the test would pass in the foundry if the opcode is supported by evm version but you probably will not be able to deploy it on-chain. The bytecode generated by foundry would contain unsupported opcode.

Some reference:

  1. https://book.getfoundry.sh/reference/config/solidity-compiler?highlight=evm_version#evm_version
  2. https://docs.soliditylang.org/en/latest/using-the-compiler.html#setting-the-evm-version-to-target

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.