Skip to content

Commit

Permalink
update Access kind to include Resumed account access
Browse files Browse the repository at this point in the history
Also rename cheats APIs
  • Loading branch information
Inphi committed Nov 15, 2023
1 parent 4e1dc51 commit 1da7115
Show file tree
Hide file tree
Showing 9 changed files with 655 additions and 300 deletions.
4 changes: 2 additions & 2 deletions crates/abi/abi/HEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ record()
accesses(address)(bytes32[], bytes32[])
skip(bool)

recordStateDiff()
getStateDiff()(AccountAccess[])
startStateDiffRecording()
stopAndReturnStateDiff()(AccountAccess[])

recordLogs()
getRecordedLogs()(Log[])
Expand Down
400 changes: 204 additions & 196 deletions crates/abi/src/bindings/hevm.rs

Large diffs are not rendered by default.

131 changes: 78 additions & 53 deletions crates/cheatcodes/assets/cheatcodes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 25 additions & 9 deletions crates/cheatcodes/defs/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,20 @@ interface Vm {
enum AccountAccessKind {
/// The account was called.
Call,
/// The account was created.
/// The account was called via delegatecall.
DelegateCall,
/// The account was called via callcode.
CallCode,
/// THe account was called via staticcall.
StaticCall,
/// THe account was created.
Create,
/// The account was selfdestructed.
SelfDestruct,
/// Synthetic access indicating the current context has resumed after a previous sub-context AccountAccess sub-context.
Resume,
/// Synthetic access indicating the current context has ended.
Return,
}

/// An Ethereum log. Returned by `getRecordedLogs`.
Expand Down Expand Up @@ -144,15 +154,21 @@ interface Vm {
bytes stderr;
}

/// The result of a `getStateDiff` call.
/// The result of a `stopAndReturnStateDiff` call.
struct AccountAccess {
/// What accessed the account.
address accessor;
/// The fork the access occurred. It's zero if no fork is active.
uint256 forkId;
/// The kind of account access that determines what the account is.
/// If kind is Call, DelegateCall, StaticCall or CallCode, then the account is the callee.
/// If kind is Create, then the account is the newly created account.
/// If kind is SelfDestruct, then the account is the selfdestruct recipient.
/// If kind is a Resume, then account represents a account context that has resumed.
AccountAccessKind kind;
/// The account that was accessed.
/// It's either the account created, callee or a selfdestruct recipient for CREATE, CALL or SELFDESTRUCT.
address account;
/// The kind of account access.
AccountAccessKind kind;
/// What accessed the account.
address accessor;
/// If the account was initialized or empty prior to the access.
/// An account is considered initialized if it has code, a
/// non-zero nonce, or a non-zero balance.
Expand Down Expand Up @@ -225,11 +241,11 @@ interface Vm {
/// Record all account accesses as part of CREATE, CALL or SELFDESTRUCT opcodes in order,
/// along with the context of the calls
#[cheatcode(group = Evm, safety = Safe)]
function recordStateDiff() external;
function startStateDiffRecording() external;

/// Returns an ordered array of all account accesses from a `vm.recordStateDiff` session.
/// Returns an ordered array of all account accesses from a `vm.startStateDiffRecording` session.
#[cheatcode(group = Evm, safety = Safe)]
function getStateDiff() external returns (AccountAccess[] memory accesses);
function stopAndReturnStateDiff() external returns (AccountAccess[] memory accesses);

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

Expand Down
8 changes: 4 additions & 4 deletions crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,15 @@ impl Cheatcode for revertToCall {
}
}

impl Cheatcode for recordStateDiffCall {
impl Cheatcode for startStateDiffRecordingCall {
fn apply(&self, state: &mut Cheatcodes) -> Result {
let Self {} = self;
state.recorded_account_diffs = Some(Default::default());
Ok(Default::default())
}
}

impl Cheatcode for getStateDiffCall {
impl Cheatcode for stopAndReturnStateDiffCall {
fn apply(&self, state: &mut Cheatcodes) -> Result {
let Self {} = self;
get_state_diff(state)
Expand Down Expand Up @@ -424,8 +424,8 @@ pub(super) fn journaled_account<'a, DB: DatabaseExt>(
/// array of [AccountAccess]. If there are no accounts were
/// recorded as accessed, an abi encoded empty array is returned.
///
/// In the case where `getStateDiff` is called at a lower
/// depth than `recordStateDiff`, multiple `Vec<RecordedAccountAccesses>`
/// In the case where `stopAndReturnStateDiff` is called at a lower
/// depth than `startStateDiffRecording`, multiple `Vec<RecordedAccountAccesses>`
/// will be flattened, preserving the order of the accesses.
fn get_state_diff(state: &mut Cheatcodes) -> Result {
let res = state
Expand Down
Loading

0 comments on commit 1da7115

Please sign in to comment.