> ## Documentation Index
> Fetch the complete documentation index at: https://docs.phylax.systems/llms.txt
> Use this file to discover all available pages before exploring further.

# Cheatcodes

> Understanding cheatcodes in the Phylax Credible Layer and why they exist

Cheatcodes are native Rust functions exposed to assertions through PhEVM. They provide state snapshots, call traces, storage changes, and transaction logs.

## Main Capabilities

Cheatcodes enable functionality that would be impossible or impractical with standard Solidity:

* **Snapshot state access**: Access blockchain state before or after a transaction or call with explicit `ForkId` snapshots
* **Callstack introspection**: Inspect call traces and execution flow in ways not possible with standard EVM tools
* **State change tracking**: Monitor specific storage slots and track how they change during transaction execution
* **Triggering assertions**: Define precise conditions for when assertions should execute with `onFnCall` and `onTxEnd` triggers
* **Cumulative flow tracking**: Register circuit-breaker triggers that collect ERC20 inflows or outflows into one bucket per block and evaluate the buckets over rolling windows

## Why Cheatcodes Exist

Standard Solidity cannot read earlier transaction snapshots or call traces. PhEVM cheatcodes expose this execution context so assertions can compare states and inspect calls.

The implementation uses native precompiles. These docs use the term **cheatcodes** for the assertion APIs.

## When to Use Cheatcodes

Use cheatcodes when a policy needs execution history or state from another snapshot. See [Use Case Mappings](https://docs.phylax.systems/credible/use-case-mappings/intro-use-case-mapping.md) for examples.

## Snapshot Read Guidance

Read only the snapshots needed by the policy.

> [!NOTE]
>
> Choose the assertion specification supported by your target Ethereum deployment. Reshiram (V2) helpers require V2 support in the enforcer; a local test passing does not establish deployment compatibility. Earlier Linea-specific restrictions are documented in [L2 Platform Notes](https://docs.phylax.systems/credible/l2-integrations/platform-and-compatibility.md#assertion-specifications).

Prefer Reshiram snapshot reads for new assertions. Use explicit `PhEvm.ForkId` values with `ph.loadStateAt()` for transaction-wide comparisons, or `ph.context()` with call-scoped `ForkId` values inside an `onFnCall` assertion.

### When to Use Pre-State

Read pre-state when the rule compares values across execution or checks that a value remains constant.

### When to Skip Pre-State

Read only post-state when the rule depends solely on the final value.

See [Cheatcodes Reference](https://docs.phylax.systems/credible/cheatcodes-reference.md) for API signatures.

## Next Steps

> [card] [Cheatcodes Reference](https://docs.phylax.systems/credible/cheatcodes-reference.md)
>
> Complete API reference for all available cheatcodes

> [card] [Writing Your Own Policies](./writing-your-own-policies)
>
> Define, implement, and test policies for your protocol.

> [card] [Use Case Mappings](https://docs.phylax.systems/credible/use-case-mappings/intro-use-case-mapping.md)
>
> See practical examples of cheatcodes in action

> [card] [Use Cases Book](https://docs.phylax.systems/assertions-book/assertions-book-intro.md)
>
> Real-world assertion examples and implementations


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.