Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PhEvm

Git Source

Title: PhEvm

Author: Phylax Systems

Precompile interface for accessing transaction state within assertions

This interface provides access to the Credible Layer's execution environment, allowing assertions to inspect transaction state, logs, call inputs, and storage changes. The precompile is available at a deterministic address during assertion execution.

Functions

forkPreTx

Fork to the state before the assertion-triggering transaction

Allows inspection of pre-transaction state for comparison

function forkPreTx() external;

forkPostTx

Fork to the state after the assertion-triggering transaction

Allows inspection of post-transaction state for validation

function forkPostTx() external;

forkPreCall

Fork to the state before a specific call execution

Useful for inspecting state at specific points during transaction execution

function forkPreCall(uint256 id) external;

Parameters

NameTypeDescription
iduint256The call identifier from CallInputs.id

forkPostCall

Fork to the state after a specific call execution

Useful for inspecting state changes from specific calls

function forkPostCall(uint256 id) external;

Parameters

NameTypeDescription
iduint256The call identifier from CallInputs.id

load

Load a storage slot value from any address

function load(address target, bytes32 slot) external view returns (bytes32 data);

Parameters

NameTypeDescription
targetaddressThe address to read storage from
slotbytes32The storage slot to read

Returns

NameTypeDescription
databytes32The value stored at the slot

getLogs

Get all logs emitted during the transaction

Returns logs in emission order

function getLogs() external returns (Log[] memory logs);

Returns

NameTypeDescription
logsLog[]Array of Log structs containing all emitted events

getAllCallInputs

Get all call inputs for a target and selector (all call types)

Includes CALL, STATICCALL, DELEGATECALL, and CALLCODE

function getAllCallInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);

Parameters

NameTypeDescription
targetaddressThe target contract address
selectorbytes4The function selector to filter by

Returns

NameTypeDescription
callsCallInputs[]Array of CallInputs matching the criteria

getCallInputs

Get call inputs for regular CALL opcode only

function getCallInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);

Parameters

NameTypeDescription
targetaddressThe target contract address
selectorbytes4The function selector to filter by

Returns

NameTypeDescription
callsCallInputs[]Array of CallInputs from CALL opcodes

getStaticCallInputs

Get call inputs for STATICCALL opcode only

function getStaticCallInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);

Parameters

NameTypeDescription
targetaddressThe target contract address
selectorbytes4The function selector to filter by

Returns

NameTypeDescription
callsCallInputs[]Array of CallInputs from STATICCALL opcodes

getDelegateCallInputs

Get call inputs for DELEGATECALL opcode only

function getDelegateCallInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);

Parameters

NameTypeDescription
targetaddressThe target/proxy contract address
selectorbytes4The function selector to filter by

Returns

NameTypeDescription
callsCallInputs[]Array of CallInputs from DELEGATECALL opcodes

getCallCodeInputs

Get call inputs for CALLCODE opcode only

function getCallCodeInputs(address target, bytes4 selector) external view returns (CallInputs[] memory calls);

Parameters

NameTypeDescription
targetaddressThe target contract address
selectorbytes4The function selector to filter by

Returns

NameTypeDescription
callsCallInputs[]Array of CallInputs from CALLCODE opcodes

getStateChanges

Get all state changes for a specific storage slot

Returns the sequence of values the slot held during transaction execution

function getStateChanges(address contractAddress, bytes32 slot)
    external
    view
    returns (bytes32[] memory stateChanges);

Parameters

NameTypeDescription
contractAddressaddressThe contract whose storage to inspect
slotbytes32The storage slot to get changes for

Returns

NameTypeDescription
stateChangesbytes32[]Array of values the slot held (in order of changes)

getAssertionAdopter

Get the assertion adopter address for the current transaction

The adopter is the contract that registered the assertion

function getAssertionAdopter() external view returns (address);

Returns

NameTypeDescription
<none>addressThe address of the assertion adopter contract

Structs

Log

Represents an Ethereum log emitted during transaction execution

Used by getLogs() to return transaction logs for inspection

struct Log {
    /// @notice The topics of the log, including the event signature if any
    bytes32[] topics;
    /// @notice The raw ABI-encoded data of the log
    bytes data;
    /// @notice The address of the contract that emitted the log
    address emitter;
}

CallInputs

Represents the inputs to a call made during transaction execution

Used by getCallInputs() and related functions to inspect call details

struct CallInputs {
    /// @notice The calldata of the call
    bytes input;
    /// @notice The gas limit of the call
    uint64 gas_limit;
    /// @notice The address of the bytecode being executed (code address)
    address bytecode_address;
    /// @notice The target address whose storage may be modified
    address target_address;
    /// @notice The address that initiated this call
    address caller;
    /// @notice The ETH value sent with the call
    uint256 value;
    /// @notice Unique identifier for this call, used with forkPreCall/forkPostCall
    uint256 id;
}