Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cheatcode to skip zkEVM execution #569

Merged
merged 17 commits into from
Sep 16, 2024
Merged

feat: add cheatcode to skip zkEVM execution #569

merged 17 commits into from
Sep 16, 2024

Conversation

nbaztec
Copy link
Collaborator

@nbaztec nbaztec commented Sep 11, 2024

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.

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.

@nbaztec nbaztec requested a review from Karrq September 13, 2024 11:37
crates/cheatcodes/src/inspector.rs Show resolved Hide resolved
crates/cheatcodes/src/inspector.rs Outdated Show resolved Hide resolved
crates/cheatcodes/src/inspector.rs Outdated Show resolved Hide resolved
crates/cheatcodes/src/inspector.rs Outdated Show resolved Hide resolved
testdata/zk/Cheatcodes.t.sol Outdated Show resolved Hide resolved
testdata/zk/Cheatcodes.t.sol Outdated Show resolved Hide resolved
testdata/zk/Cheatcodes.t.sol Outdated Show resolved Hide resolved
@Karrq
Copy link
Contributor

Karrq commented Sep 13, 2024

🚀 🚀 🚀

@nbaztec nbaztec requested a review from Karrq September 13, 2024 15:45
Karrq
Karrq previously approved these changes Sep 13, 2024
crates/cheatcodes/src/inspector.rs Show resolved Hide resolved
crates/cheatcodes/src/inspector.rs Show resolved Hide resolved
@nbaztec nbaztec requested a review from Karrq September 13, 2024 20:32
@nbaztec nbaztec merged commit df011e0 into main Sep 16, 2024
11 checks passed
@nbaztec nbaztec deleted the nish-skip-zk-vm branch September 16, 2024 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants