Skip to content

Commit fdad9fb

Browse files
authored
fix(cheatcodes): recorded created account during broadcast (#6527)
Ensure that the appropriate caller is used to compute the deployed address during a CREATE/CREATE2 operation. As such, during broadcast, the configured wallet address is used rather than the current EVM caller.
1 parent 9093207 commit fdad9fb

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Diff for: crates/cheatcodes/src/inspector.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1102,9 +1102,6 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
11021102
) -> (InstructionResult, Option<Address>, Gas, Bytes) {
11031103
let gas = Gas::new(call.gas_limit);
11041104

1105-
// allow cheatcodes from the address of the new contract
1106-
let address = self.allow_cheatcodes_on_create(data, call);
1107-
11081105
// Apply our prank
11091106
if let Some(prank) = &self.prank {
11101107
if data.journaled_state.depth() >= prank.depth && call.caller == prank.prank_caller {
@@ -1171,6 +1168,10 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
11711168
}
11721169
}
11731170

1171+
// allow cheatcodes from the address of the new contract
1172+
// Compute the address *after* any possible broadcast updates, so it's based on the updated
1173+
// call inputs
1174+
let address = self.allow_cheatcodes_on_create(data, call);
11741175
// If `recordAccountAccesses` has been called, record the create
11751176
if let Some(recorded_account_diffs_stack) = &mut self.recorded_account_diffs_stack {
11761177
// Record the create context as an account access and create a new vector to record all

Diff for: testdata/cheats/RecordAccountAccesses.t.sol

+14
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,20 @@ contract RecordAccountAccessesTest is DSTest {
10851085
);
10861086
}
10871087

1088+
/// @notice Asserts interaction between broadcast and recording cheatcodes
1089+
function testIssue6514() public {
1090+
cheats.startStateDiffRecording();
1091+
cheats.startBroadcast();
1092+
1093+
StorageAccessor a = new StorageAccessor();
1094+
1095+
cheats.stopBroadcast();
1096+
Vm.AccountAccess[] memory called = cheats.stopAndReturnStateDiff();
1097+
assertEq(called.length, 1, "incorrect length");
1098+
assertEq(toUint(called[0].kind), toUint(Vm.AccountAccessKind.Create));
1099+
assertEq(called[0].account, address(a));
1100+
}
1101+
10881102
function startRecordingFromLowerDepth() external {
10891103
cheats.startStateDiffRecording();
10901104
assembly {

0 commit comments

Comments
 (0)