Overview

Precompiles are PhEVM(Phylax EVM) specific instructions that are implemented in native code instead of EVM bytecode. Precompiles additionally can communicate with Internal APIs. Currently the PhEVM supports all existing precompiles in Ethereum up to Dancun, and introduces a few new classes of precompiles:

  1. Manipulation of the PhEVM state
  2. Forking of the state of one or multiple EVM networks
  3. Utilities that make assertions more useful and easier to write

Precompile Interface

A list of available precompiles in Ajax as follows:

load

Loads a storage slot from an address.

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

mockCall

Mocks a call to an address, returning specified data.

function mockCall(address callee, bytes calldata data, bytes calldata returnData) external

Forking

forkPreState

Updates the currently active fork to the state before the transaction that triggered the assertion.

function forkPreState() external

forkPostState

Updates the currently active fork to the state after the transaction that triggered the assertion.

function forkPostState() external

getLogs

Gets all the logs that were emitted by the latest applied transaction.


/// An Ethereum log
struct Log {
    // The topics of the log, including the signature, if any.
    bytes32[] topics;
    // The raw data of the log.
    bytes data;
    // The address of the log's emitter.
    address emitter;
}

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

getTransaction

Get the transaction that triggered the current assertion.

/// A transaction
struct Transaction {
    // The address of the transaction's emitter.
    address from;
    // The address of the transaction's receiver.
    address to;
    // The amount of Ether sent with the transaction.
    uint256 value;
    // The calldata of the transaction.
    bytes data;
}

function getTransaction() external returns (Transaction memory tx)

Implementation Notes

Precompiles are implemented in PhEVM. Assertions are able to call a pre-specified address or set of addresses that implement the interface described above.

Example usage, not finalized interface:


interface PrecompileInterface {
  function assertEq(bool left, bool right) external pure;
  ...
}

abstract contract AssertionBase {
  PrecompileInterface phEVM;
}

contract Assertion is AssertionBase {

  function assertion_foo() external {
    phEVM.assertEq(true, true);
  }
}