---
eip: 7793
label: EIP-7793
title: Conditional Transactions
status: Stagnant
type: Standards Track
category: Core
created: 2024-10-17
requires: 7843
official: https://eips.ethereum.org/EIPS/eip-7793
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7793.md
canonical: https://eips.huatuo.xyz/zh/eip-7793/
lang: zh
tldr: 提议一种仅在特定 slot 和区块内特定位置才有效的交易类型，外加 TXINDEX opcode，使加密 mempool 能够阻止构建者对解密后的交易重新排序。
tags: [transactions, mev, encrypted-mempool, opcode, core]
---

# EIP-7793: Conditional Transactions

> Transactions that only executes at a specific index and slot

**TL;DR:** 提议一种仅在特定 slot 和区块内特定位置才有效的交易类型，外加 TXINDEX opcode，使加密 mempool 能够阻止构建者对解密后的交易重新排序。

## 它解决什么问题？

加密 mempool 旨在防止抢跑：交易在仍处于加密状态时被排序，然后解密并放在区块的顶部。薄弱环节在最后一步。看得到解密内容的区块构建者可能会重新排序，或在中间插入自己的交易。

EIP-7793 让协议能够强制执行约定的顺序。交易可以精确声明它必须落在哪个 slot、区块中的哪个索引；在其他任何位置，它都是无效的。

## 它如何运作

- **新的交易类型 `0x05`**（[EIP-2718](/eip-2718/) 信封）。其字段与 [EIP-4844](/eip-4844/) 的 blob 交易一致，另外增加两个：`conditional_slot` 和 `conditional_tx_index`（均为 `uint64`）。`blob_versioned_hashes` 可以为空。
- **有效性规则。** 只有当交易被包含在该 slot 且位于该索引时才有效。slot 检查依赖 [EIP-7843](/eip-7843/)，它把 slot 编号加入区块头。任一字段取值为 `-1` 则禁用对应的检查。
- **签名**与其他带类型的交易一样，针对 `keccak256(0x05 || rlp([...除 y_parity、r、s 外的所有字段]))`。
- **`TXINDEX` opcode（`0x4c`，2 gas）** 压入当前交易的 `conditional_tx_index`，如果不是条件交易则压入 `-1`。

为什么要新增交易类型，而不是只用一个返回当前索引的 opcode？预先声明索引能让有效性保持静态，构建者就不必去求解依赖执行结果的复杂排布约束。

## 示例代码

RLP 载荷布局（伪代码）：

```python
COND_TX_TYPE = 0x05

payload = rlp([
    chain_id, nonce,
    max_priority_fee_per_gas, max_fee_per_gas, gas_limit,
    to, value, data, access_list,
    max_fee_per_blob_gas, blob_versioned_hashes,   # may be []
    conditional_slot,       # uint64, or -1 = any slot
    conditional_tx_index,   # uint64, or -1 = any index
    y_parity, r, s,
])
raw_tx = bytes([COND_TX_TYPE]) + payload

# Block validity (sketch)
def check(tx, block, index_in_block):
    if tx.conditional_slot != -1:
        assert tx.conditional_slot == block.header.slot_number   # EIP-7843
    if tx.conditional_tx_index != -1:
        assert tx.conditional_tx_index == index_in_block
```

## 需要注意

- **状态：Stagnant。** 它尚未被安排进任何升级，也没有测试用例。
- 它面向的是加密 mempool 设计，而不是通用钱包使用：普通用户很少知道自己的交易应当占据的确切索引。
- 错过其 slot 或索引的条件交易就是无效的，之后无法再被包含；必须重新签名。
- opcode 字节和交易类型编号只是提议，如果该提案被重新启动，可能与其他 EIP 冲突。


---

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