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): recorded created account during broadcast #6527

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,9 +1102,6 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
) -> (InstructionResult, Option<Address>, Gas, Bytes) {
let gas = Gas::new(call.gas_limit);

// allow cheatcodes from the address of the new contract
let address = self.allow_cheatcodes_on_create(data, call);

// Apply our prank
if let Some(prank) = &self.prank {
if data.journaled_state.depth() >= prank.depth && call.caller == prank.prank_caller {
Expand Down Expand Up @@ -1171,6 +1168,10 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
}
}

// allow cheatcodes from the address of the new contract
// Compute the address *after* any possible broadcast updates, so it's based on the updated
// call inputs
let address = self.allow_cheatcodes_on_create(data, call);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this changes the old, possibly incorrect, behavior. It might not matter, but now wallet deployed accounts are now allowed to executed cheatcodes.

// If `recordAccountAccesses` has been called, record the create
if let Some(recorded_account_diffs_stack) = &mut self.recorded_account_diffs_stack {
// Record the create context as an account access and create a new vector to record all
Expand Down
14 changes: 14 additions & 0 deletions testdata/cheats/RecordAccountAccesses.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,20 @@ contract RecordAccountAccessesTest is DSTest {
);
}

/// @notice Asserts interaction between broadcast and recording cheatcodes
function testIssue6514() public {
cheats.startStateDiffRecording();
cheats.startBroadcast();

StorageAccessor a = new StorageAccessor();

cheats.stopBroadcast();
Vm.AccountAccess[] memory called = cheats.stopAndReturnStateDiff();
assertEq(called.length, 1, "incorrect length");
assertEq(toUint(called[0].kind), toUint(Vm.AccountAccessKind.Create));
assertEq(called[0].account, address(a));
}

function startRecordingFromLowerDepth() external {
cheats.startStateDiffRecording();
assembly {
Expand Down