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 storage and access record cheats #481

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 46 additions & 0 deletions src/Vm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ interface VmSafe {
RecurrentPrank
}

enum AccountAccessKind {
Call,
DelegateCall,
CallCode,
StaticCall,
Create,
SelfDestruct,
Resume
}

struct Log {
bytes32[] topics;
bytes data;
Expand Down Expand Up @@ -76,6 +86,35 @@ interface VmSafe {
bytes stderr;
}

struct ChainInfo {
uint256 forkId;
uint256 chainId;
}

struct AccountAccess {
ChainInfo chainInfo;
AccountAccessKind kind;
address account;
address accessor;
bool initialized;
uint256 oldBalance;
uint256 newBalance;
bytes deployedCode;
uint256 value;
bytes data;
bool reverted;
StorageAccess[] storageAccesses;
}

struct StorageAccess {
address account;
bytes32 slot;
bool isWrite;
bytes32 previousValue;
bytes32 newValue;
bool reverted;
}

// ======== EVM ========

// Gets the address for a given private key
Expand All @@ -98,6 +137,13 @@ interface VmSafe {
// Gets all accessed reads and write slot from a `vm.record` session, for a given address
function accesses(address target) external returns (bytes32[] memory readSlots, bytes32[] memory writeSlots);

// Record all account accesses as part of CREATE, CALL or SELFDESTRUCT opcodes in order,
// along with the context of the calls.
function startStateDiffRecording() external;

// Returns an ordered array of all account accesses from a `vm.startStateDiffRecording` session.
function stopAndReturnStateDiff() external returns (AccountAccess[] memory accesses);
mds1 marked this conversation as resolved.
Show resolved Hide resolved

// -------- Recording Map Writes --------

// Starts recording all map SSTOREs for later retrieval.
Expand Down
2 changes: 1 addition & 1 deletion test/Vm.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract VmTest is Test {
// inadvertently moved between Vm and VmSafe. This test must be updated each time a function is
// added to or removed from Vm or VmSafe.
function test_interfaceId() public {
assertEq(type(VmSafe).interfaceId, bytes4(0x1578a242), "VmSafe");
assertEq(type(VmSafe).interfaceId, bytes4(0x7006b885), "VmSafe");
assertEq(type(Vm).interfaceId, bytes4(0x316cedc3), "Vm");
}
}
Loading