Skip to main content
A policy is implemented as an assertion: EVM bytecode executed offchain in PhEVM. Precompiles provide the primitives teams use to express safety rules, from runtime enforcement of invariants to inflow circuit breakers, anomaly checks, and external data feeds such as risk signals. Available primitives depend on the assertion specification and target runtime. Assertion functions implement the checks; an assertion contract packages those functions with their trigger registrations. The policy defines the intended behavior and exceptions. Invariants are one possible requirement; policies can also constrain transitions, conditional effects, or rolling flows. Circuit breakers limit cumulative inflow or outflow across per-block buckets over a rolling window. See the terminology reference. Assertions describe invalid outcomes without predicting every exploit path. Participating builders enforce them before inclusion. See Ethereum Architecture for guards and routing.

Assertion Specifications

  • Legacy (V1) exposes the original PhEVM precompiles, including mutable fork switching with forkPreTx, forkPostTx, and forkPostCall.
  • Reshiram (V2) replaces mutable fork switching with immutable ForkId snapshot reads and adds newer transaction and call inspection precompiles.
Confirm which specification your target enforcer accepts before activation, on Ethereum or an L2. Library availability and local tests do not establish compatibility. The Assertion Specifications reference covers registration, API differences, migration, and deployment requirements.

How Assertions Work

Triggers select assertion functions for relevant transaction activity. PhEVM executes them against state snapshots. A participating builder excludes a candidate if an active production assertion fails.

Example: Compare Ownership at Transaction Boundaries

With an appropriate trigger, this rule rejects a final owner value that differs from the initial value, including a legitimate transfer. It does not distinguish authorization or detect a temporary change restored before transaction end. The ownership tutorial demonstrates that limit. A policy permitting transfers needs explicit exceptions and checks at the required observation boundaries.

What They Can Do That Regular Solidity Can’t

Assertions can read state before and after a transaction or matched call. They can inspect interactions across contracts and check their combined effects. Rules execute offchain with separate gas limits. Teams can update policy without changing protocol logic, once the required Ethereum guard is installed. See Cheatcodes for state access.

Common Use Cases

Policies can restrict administrative changes, token outflows, price deviations, and accounting violations. See the Catalog.

Constraints

The assertion gas budget is configured by the target runtime. Confirm that budget for the deployment you are testing; a local test runner or EVM block gas limit is a separate setting. Exceeding the limit invalidates the candidate. Use scoped triggers and test the maximum expected workload. See Gas Limits in Testing.

Policies for Historical Exploits

The exploit case studies discuss candidate policy checks against historical attacks. Read each example’s implementation status, enforcement assumptions, and replay evidence before treating it as demonstrated prevention.

Next Steps

Writing Your Own Policies

Define, implement, and test policies for your protocol.

Cheatcodes

Tools available for writing assertions

Triggers

Learn about assertion triggers and optimization

Use Cases Book

Real-world examples and implementations