PhEVM Cheatcodes
Overview of the cheatcodes made available for the Phylax Credible Layer
Overview
Cheatcodes are PhEVM (Phylax EVM) specific instructions implemented in native code instead of EVM bytecode. They can communicate with Internal APIs and support all existing Ethereum cheatcodes up to Dancun, plus new capabilities for:
- Manipulation of the PhEVM state
- Forking of state from one or multiple EVM networks
- Utilities for writing and managing assertions
Storage Operations
load
Loads a storage slot from an address.
State Management
forkPreState
Updates the active fork to the state before the triggering transaction. Useful for:
- Checking chain state before a transaction
- Comparing values between pre and post states
forkPostState
Updates the active fork to the state after the triggering transaction. Useful for:
- Verifying chain state after a transaction
- Comparing values between pre and post states
Transaction Data
getLogs
Retrieves all logs emitted by the latest transaction.
getCallInputs
Gets the call inputs of all the calls made in the current transaction and returns them in an array of CallInputs
structs.
This is a useful precompile to use for intra-transaction assertions such as checking if the price reported by an oracle deviates from an allowed range, which could be a sign of an oracle manipulation.
Internal calls are not actual EVM calls but rather a Solidity language feature. They are not traced by the CallTracer and will not result in
CallInputs
or trigger call-based assertions. However, using thethis
keyword (e.g.,this.functionName()
) creates an external call that will be traced and can trigger assertions.Example:
State Change Tracking
getStateChanges
Returns state changes for a contract’s storage slot within the current call stack.
Helper Functions
The following helpers convert state changes to specific types. Each has three variants:
- Basic: Get changes for a single slot
- Mapping: Get changes using a mapping key
- Mapping with Offset: Get changes using a key and offset for complex storage
getStateChangesUint
Gets state changes for a storage slot as uint256 values.
Similar helper functions exist for:
getStateChangesAddress
: Convert to address valuesgetStateChangesBool
: Convert to boolean valuesgetStateChangesBytes32
: Get raw bytes32 values
Each of these functions follows the same pattern with basic, mapping, and mapping-with-offset variants.
Triggers
Triggers determine when your assertion functions will be executed. You can register
different types of triggers in your assertion’s triggers()
function.
Call Triggers
Call triggers execute your assertion when specific contract calls occur.
Example:
Storage Triggers
Storage triggers execute your assertion when contract storage changes.
Example:
Balance Triggers
Executes assertion on ETH balance changes.
Combining Triggers
Triggers can be combined for comprehensive coverage: