---
eip: 7685
label: EIP-7685
title: General purpose execution layer requests
status: Final
type: Standards Track
category: Core
created: 2024-04-14
official: https://eips.ethereum.org/EIPS/eip-7685
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7685.md
canonical: https://eips.huatuo.xyz/zh/eip-7685/
lang: zh
tldr: 在执行区块头中为合约触发的请求（存款、提款、合并）提供一个通用通道，再由共识层处理，已随 Pectra 上线。
tags: [core, consensus, staking, pectra, block-header]
---

# EIP-7685: General purpose execution layer requests

> A general purpose bus for sharing EL triggered requests with the CL

**TL;DR:** 在执行区块头中为合约触发的请求（存款、提款、合并）提供一个通用通道，再由共识层处理，已随 Pectra 上线。

## 它解决什么问题？

越来越多的验证者由智能合约控制：质押池、再质押协议、由 DAO 运营的节点集合。这些合约常常需要通知信标链做某件事，比如让某个验证者退出，或转移它的余额。在 Pectra 之前，许多此类操作只能由验证者的签名密钥触发，因此由合约控制的方案不得不依赖持有该密钥的受信任运营者。

每增加一个"执行层要求共识层做 X"的功能，原本都可能要在区块头里加一个专用字段。EIP-7685 则定义了一条通用总线，这样新增请求类型时无需再次改动区块结构。

## 它如何运作

- 某一类型的**请求**列表是一个字节串：`request_type ++ request_data`。类型占一个字节；数据对本 EIP 而言是不透明的，每种请求类型自行定义编码。
- 处理区块时，执行客户端收集不同类型的请求列表，通常是在区块末尾读取系统合约。
- 区块头新增一个 32 字节字段 **`requests_hash`**，对所有请求做出承诺：

```python
def compute_requests_hash(block_requests):
    m = sha256()
    for r in block_requests:          # ordered by request_type, ascending
        if len(r) > 1:                # skip types with empty request_data
            m.update(sha256(r).digest())
    return m.digest()
```

- 请求按类型升序排列；同一类型内部的顺序由该类型的 EIP 决定。空列表会被跳过，所以没有任何请求的区块，其 `requests_hash` 恒为 `sha256(b"")`。
- 共识层接收实际的请求数据，对其验证并应用。之所以称为"请求"，是因为执行层无法完全验证它们，最终决定权在信标链。

在 Pectra 升级中激活的请求类型（[EIP-7600](/eip-7600/)）：

| 类型 | 请求 | 定义于 |
| --- | --- | --- |
| `0x00` | 验证者存款 | [EIP-6110](/eip-6110/) |
| `0x01` | 由 EL 触发的提款 / 退出 | [EIP-7002](/eip-7002/) |
| `0x02` | 合并（consolidation） | [EIP-7251](/eip-7251/) |

## 示例代码

在 TypeScript（ethers v6）中计算 `requests_hash`，输入为各类型的字节串：

```ts
import { sha256, concat, getBytes } from "ethers";

// Each entry: one byte type prefix followed by that type's request_data.
export function requestsHash(requests: Uint8Array[]): string {
  const sorted = [...requests].sort((a, b) => a[0] - b[0]);
  const parts = sorted
    .filter((r) => r.length > 1)          // drop empty request lists
    .map((r) => getBytes(sha256(r)));
  return sha256(parts.length ? concat(parts) : new Uint8Array());
}

// No requests at all → sha256 of empty input
console.log(requestsHash([])); // 0xe3b0c442...b855
```

## 需要注意

- 状态为 **Final**：它已与上述三种请求类型一起随 Pectra 上线。
- 本 EIP 没有规定请求从哪里来，也没有规定如何验证。作者推荐使用系统合约存储请求，并在区块后的系统调用中清空，EIP-7002 和 EIP-7251 就是这样工作的。
- `request_data` 有意设计为不透明的字节，而不是 RLP，为未来的请求类型使用 SSZ 或定长格式留出空间。
- 执行客户端与共识客户端之间的 Engine API 消息携带完整的请求列表，以便信标节点处理它们，并与 `requests_hash` 核对。


---

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