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

fix(cheatcodes): expectSafeMemory + stopExpectSafeMemory #7686

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

clabby
Copy link
Contributor

@clabby clabby commented Apr 16, 2024

Overview

Fixes the stopExpectSafeMemory cheatcode by allowing for the memory allocation of the stopExpectSafeMemory selector as well as the potentially out-of-bounds read performed in the CALL operation to the cheatcode contract.

Currently, forge reports incorrectly that memory safety was violated in a memory safe region of a test, if the free memory pointer was updated to [exclusiveUpperBound-31, exclusiveUpperBound] during execution and is followed by a stopExpectSafeMemory call.

To fix this, we allow for MSTORE operations that store the selector bytes for stopExpectSafeMemory, as well as CALL operations that are to the cheatcode address and contain the stopExpectSafeMemory selector in the first 4 bytes of the call arguments, even if they write/read from outside of the allowed region(s).

@clabby clabby changed the title fix(cheatcodes): expectSafeMemory w/ new forge-std fix(cheatcodes): expectSafeMemory + stopExpectSafeMemory Apr 16, 2024
Fixes the `stopExpectSafeMemory` by allowing for the memory allocation
of the `stopExpectSafeMemory` selector as well as the potentially
out-of-bounds read performed in the `CALL` operation.

Currently, forge reports incorrectly that memory safety was violated in
a memory safe region of a test, if the free memory pointer was updated
to `[exclusiveUpperBound-31, exclusiveUpperBound]`.

To fix this, we allow for `MSTORE` operations that store the selector
bytes for `stopExpectSafeMemory` outside of the allowed region, as well
as `CALL` operations that are to the cheatcode address and contain the
`stopExpectSafeMemory` selector in the first 4 bytes of the call
arguments.
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

pedantic, nits

pending @klkvr

crates/cheatcodes/src/inspector.rs Outdated Show resolved Hide resolved
crates/cheatcodes/src/inspector.rs Outdated Show resolved Hide resolved
@mattsse mattsse merged commit 24536cd into foundry-rs:master Apr 16, 2024
19 checks passed
@clabby clabby deleted the cl/fix-expect-safe-mem branch April 16, 2024 18:54
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.

3 participants