From 27b652e0d57c215d22744dedeb2590ab4f5684eb Mon Sep 17 00:00:00 2001 From: inphi Date: Tue, 5 Dec 2023 15:48:58 -0500 Subject: [PATCH] fix(cheatcodes): recorded created account during broadcast 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. --- crates/cheatcodes/src/inspector.rs | 7 ++++--- testdata/cheats/RecordAccountAccesses.t.sol | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index 2eef1975502b..b154955330af 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -1102,9 +1102,6 @@ impl Inspector for Cheatcodes { ) -> (InstructionResult, Option
, 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 { @@ -1171,6 +1168,10 @@ impl Inspector 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); // 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 diff --git a/testdata/cheats/RecordAccountAccesses.t.sol b/testdata/cheats/RecordAccountAccesses.t.sol index e27c2dd0c5f1..4ab707edbfac 100644 --- a/testdata/cheats/RecordAccountAccesses.t.sol +++ b/testdata/cheats/RecordAccountAccesses.t.sol @@ -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 {