---
eip: 7906
label: EIP-7906
title: Transaction Assertions via State Diff Opcode
status: Draft
type: Standards Track
category: Core
created: 2025-02-21
requires: 2929, 8141
official: https://eips.ethereum.org/EIPS/eip-7906
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7906.md
canonical: https://eips.huatuo.xyz/eip-7906/
lang: en
tldr: "Adds opcodes that let an assertion frame at the end of a frame transaction read the transaction's full state diff and events, and roll back its effects if they are not what the user expected."
tags: [evm, opcodes, security, wallets, account-abstraction]
---

# EIP-7906: Transaction Assertions via State Diff Opcode

> Opcodes that expose a transaction's state diff to on-chain assertions that can reject the transaction's outcome

**TL;DR:** Adds opcodes that let an assertion frame at the end of a frame transaction read the transaction's full state diff and events, and roll back its effects if they are not what the user expected.

## What problem does it solve?

When you sign a transaction, your wallet can show you the call data, but it usually cannot tell you with certainty what the contracts you call will actually do. Users end up "blind signing", and a malicious or buggy contract can drain balances in ways nobody reviewed.

EIP-7906 flips the question from "what code will run?" to "what was the outcome?". A wallet or dApp attaches an on-chain check to the transaction, for example "my USDC balance may drop by at most 100, and no new approvals may appear". If the final state breaks that rule, the transaction's effects are discarded.

## How it works

The proposal builds on frame transactions from [EIP-8141](/eip-8141/) and adds a new frame mode, `ASSERT`:

- `ASSERT` frames must form a contiguous suffix at the end of the transaction, so they see its final outcome.
- They run like a `STATICCALL`: read-only, and `APPROVE` is not allowed inside them.
- If an `ASSERT` frame reverts or halts, the whole execution body is rolled back to the state right after the payer was approved. The transaction still stays valid and included, and gas is still paid.

Three new opcodes are valid only inside an `ASSERT` frame (anywhere else they halt):

| Opcode | Byte | What it does |
| --- | --- | --- |
| `TXTRACE` | `0xb6` | Enumerates the diff: counts and entries for balance changes, storage changes, deployed contracts, emitted events, plus gas payer and pre-charge |
| `TXDIFF` | `0xb7` | Looks up one entry by key, e.g. a given address's balance or a given storage slot before/after |
| `EVENTDATACOPY` | `0xb8` | Copies an event's non-indexed data into memory |

"Before" means the state at the start of the transaction; "after" is the current state. Intermediate writes are invisible, and multiple writes to one slot collapse into one entry. Each `TXTRACE` call costs a warm storage read as defined by [EIP-2929](/eip-2929/). Protocol-emitted logs such as [EIP-7708](/eip-7708/) ETH transfer logs count as events too.

The gas payer's balance change includes the gas pre-charge, so an assertion that checks net ETH outflow should subtract it.

## Sample code

Illustrative pseudocode for an assertion that limits how much ETH the sender can lose:

```python
# runs inside an ASSERT frame
MAX_LOSS = 10**17  # 0.1 ETH, chosen by the wallet

n = TXTRACE(0x00, 0)                     # number of addresses whose balance changed
for i in range(n):
    if TXTRACE(0x03, i) == SENDER:       # TXTRACE_BALANCE_ADDRESS
        before = TXTRACE(0x04, i)        # TXTRACE_BALANCE_BEFORE
        after  = TXTRACE(0x05, i)        # TXTRACE_BALANCE_AFTER
        if TXTRACE(0x15, 0) == SENDER:   # sender is also the gas payer
            before -= TXTRACE(0x14, 0)   # ignore the gas pre-charge
        if before - after > MAX_LOSS:
            REVERT()                     # whole execution body is undone
```

Note the operand order: `TXTRACE` takes `param` from the top of the stack and the index second.

## Things to know

- **Status: Draft.** It depends on [EIP-8141](/eip-8141/), which itself is not final, so opcode numbers, params and gas costs may change.
- Assertions only work in EIP-8141 frame transactions. Legacy and EIP-1559 transactions cannot use them.
- A failed assertion does not refund gas: the user still pays for the work done. It protects funds, not fees.
- Slots cleared by a storage wipe that the transaction never wrote are not enumerated by `TXTRACE`, but a keyed `TXDIFF` lookup still reports them.
- The value depends on wallets generating sensible assertions; the opcodes are only the enforcement mechanism.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-7906
