---
eip: 7684
label: EIP-7684
title: Return deposits for distinct credentials
status: Stagnant
type: Standards Track
category: Core
created: 2024-04-12
official: https://eips.ethereum.org/EIPS/eip-7684
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7684.md
canonical: https://eips.huatuo.xyz/zh/eip-7684/
lang: zh
tldr: 提议：对已有验证者、但提款凭证（withdrawal credentials）不同的存款，不再作为追加存款，而是自动退回（扣除一笔罚金），从而堵住存款抢跑攻击。
tags: [staking, deposits, withdrawals, consensus, security]
---

# EIP-7684: Return deposits for distinct credentials

> Automatically withdraw deposits for existing validator records but with distinct execution withdrawal credentials

**TL;DR:** 提议：对已有验证者、但提款凭证（withdrawal credentials）不同的存款，不再作为追加存款，而是自动退回（扣除一笔罚金），从而堵住存款抢跑攻击。

## 它解决什么问题？

许多质押方案会拆分角色：一方运行验证者密钥，另一方提供 ETH。出资方需要通过存款所附带的**提款凭证（withdrawal credentials）**，保留对资金的最终控制权。

信标链处理存款时只看验证者公钥。如果该公钥对应的验证者已经存在，之后的任何存款都会被视为**追加存款（top-up）**，新存款中的提款凭证会被忽略。这就留下了抢跑攻击的空间：

1. 出资方为运营者的密钥广播一笔完整的 32 ETH 存款，使用出资方自己的提款凭证。
2. 运营者看到后，抢先让一笔针对同一密钥的小额存款被打包，使用*他自己的*提款凭证。
3. 出资方的大额存款最终作为追加存款，落到一个提款地址属于运营者的验证者上。

目前人们的变通办法是使用分布式密钥生成，或者先存入 1 ETH，等它被打包后再追加。两种做法都增加了麻烦，对无需信任的质押协议尤其如此。EIP-7684 把朴素存款的最坏损失限制在固定的 `RETURN_DEPOSIT_PENALTY` 以内。

## 它如何运作

这只是共识层的改动，执行层不受影响。详细规则位于 consensus-specs 仓库；EIP 将其概括如下：

- **`apply_deposit`**：如果存款指向已有验证者，但带有**不同的执行层提款凭证**，则不会入账，而是作为*待处理提款（pending withdrawal）*排入队列，退回到这些凭证中的地址。
- **`get_expected_withdrawals`**：待处理提款先于常规的提款扫描返回。
- **`process_withdrawals`**：支付完成后清空待处理提款队列。

被拒绝的存款无法在它出现的同一个区块中退款。在 [EIP-6110](/eip-6110/) 之后，存款来自执行负载，因此执行客户端需要在触发提款的存款存在之前就知道这些提款。所以被拒绝的存款会在之后的 slot 中支付；为简单起见，规范在紧接着的下一个 slot 处理所有待处理项。

## 示例代码

存款规则的简化伪代码：

```python
def apply_deposit(state, pubkey, withdrawal_credentials, amount, signature):
    index = find_validator_index(state, pubkey)
    if index is None:
        add_new_validator(state, pubkey, withdrawal_credentials, amount, signature)
        return

    existing = state.validators[index].withdrawal_credentials
    if is_execution_credential(withdrawal_credentials) and withdrawal_credentials != existing:
        # EIP-7684: do not top up someone else's validator; send the funds back
        refund = amount - RETURN_DEPOSIT_PENALTY
        state.pending_withdrawals.append(
            Withdrawal(address=withdrawal_credentials[12:], amount=refund)
        )
        return

    increase_balance(state, index, amount)  # normal top-up
```

## 需要注意

- **状态：Stagnant。**尚未排入任何硬分叉；主网上抢跑风险和常见的变通办法依然适用。
- 需要一次共识层硬分叉。
- 规范指出了一项代价：每个区块最坏情况下的提款数量会大幅上升（在 3000 万 gas 上限下，从固定的 16 个增至一千多个），给区块增加了未定价的工作量。罚金旨在抑制利用被拒绝存款发送垃圾交易的行为。
- 之后的变更，例如 [EIP-7251](/eip-7251/)（合并、更大的有效余额）和 [EIP-7002](/eip-7002/)（由执行层触发的提款），改变了存款与提款之间的相互作用，因此该设计在采用前需要重新审视。


---

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