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 vm.assume cheatcode #240

Merged
merged 11 commits into from
Jan 29, 2024
Merged

feat: add vm.assume cheatcode #240

merged 11 commits into from
Jan 29, 2024

Conversation

aon
Copy link

@aon aon commented Jan 26, 2024

What πŸ’»

  • Add vm.assume cheatcode, that allows for skipping fuzz test runs when a given condition is not met.

Why βœ‹

  • Continue adding support for foundry

Evidence πŸ“·

image

Co-authored-by: Dustin Brickwood <dustinbrickwood204@gmail.com>
crates/era-cheatcodes/src/cheatcodes.rs Outdated Show resolved Hide resolved
crates/era-cheatcodes/src/cheatcodes.rs Outdated Show resolved Hide resolved
crates/era-cheatcodes/src/cheatcodes.rs Show resolved Hide resolved
crates/evm/evm/src/executors/fuzz/mod.rs Outdated Show resolved Hide resolved
crates/era-cheatcodes/src/cheatcodes.rs Show resolved Hide resolved
tracing::debug!("!!! FORCING REVERT");
tracing::debug!(?error, pc, "Forcing revert");

self.return_data = Some(error.reason);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.to_return_data() takes care of encoding. Probably that's why you are having padding issues and cannot exact match

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! error is of type ForceRevertError (see below). In the impl there's option to instantiate using abi encoding or just the raw bytes. In the case of this PR we use ForceRevertError::raw given we don't want the abi encoding to return the string. But since the revert reason (same as return data) is a Vec<U256> it will inevitably still have padding.

#[derive(Debug, Clone)]
struct ForceRevertError {
    reason: Vec<U256>,
}

impl ForceRevertError {
    fn abi_encode(reason: Vec<u8>) -> Self {
        Self { reason: reason.to_return_data() }
    }

    fn raw(reason: Vec<u8>) -> Self {
        Self { reason: reason.chunks(32).map(U256::from_big_endian).collect_vec() }
    }
}

Source: https://github.com/matter-labs/foundry-zksync/blob/aon-add-assume-cheatcode/crates/era-cheatcodes/src/cheatcodes.rs#L192C1-L205C2

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But don't we actually want the abi encoded reason. I can't think of anything in solidity that isn't abi encoded.

Copy link
Author

@aon aon Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit c3cd15d

@aon aon merged commit 53afdbe into main Jan 29, 2024
10 checks passed
@aon aon deleted the aon-add-assume-cheatcode branch January 29, 2024 14:31
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.

None yet

4 participants