In certain tests the actual test is run in a factory or helper contract. However, since we execute all CREATEs and CALLs on zkEVM, cheatcodes are no longer accessible within these factories.
contract Helper is Test {
event Added(uint8 indexed sum);
function exec() public {
vm.expectEmit();
emit Added(3);
Calculator calc = new Calculator();
uint8 sum = calc.add(1, 2);
assertEq(3, sum);
}
}
contract ZkCheatcodeZkVmSkipTest is Test {
Helper helper;
function setUp() external {
helper = new Helper();
vm.allowCheatcodes(address(helper));
vm.makePersistent(address(helper));
}
function testHelper() external {
helper.exec();
}
}
Solution
Adds a cheatcode vm.zkVmSkip() that skips the next CREATE or CALL, and executes it on the EVM instead. This effectively delays the zkEVM execution to the next stack depth.
Additionally, for ease of use, contracts deployed in skip mode are recorded and all calls to them is redirected to EVM instead of zkEVM.
Motivation
In certain tests the actual test is run in a factory or helper contract. However, since we execute all CREATEs and CALLs on zkEVM, cheatcodes are no longer accessible within these factories.
Solution
Adds a cheatcode
vm.zkVmSkip()
that skips the next CREATE or CALL, and executes it on the EVM instead. This effectively delays the zkEVM execution to the next stack depth.Additionally, for ease of use, contracts deployed in skip mode are recorded and all calls to them is redirected to EVM instead of zkEVM.