---
eip: 2972
label: EIP-2972
title: Wrapped Legacy Transactions
status: Withdrawn
type: Standards Track
category: Core
created: 2020-09-12
requires: 155, 2718
official: https://eips.ethereum.org/EIPS/eip-2972
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2972.md
canonical: https://eips.huatuo.xyz/zh/eip-2972/
lang: zh
tldr: 一个已撤回的想法：把传统交易包装进两种新的 EIP-2718 类型化信封（SSZ 编码的签名加上原始 RLP 载荷），这样既能淘汰传统编码，又不会使旧签名失效。
tags: [transactions, typed-transactions, ssz, rlp, withdrawn]
---

# EIP-2972: Wrapped Legacy Transactions

> Two new transaction types for wrapping legacy transactions with and without a chain ID.

**TL;DR:** 一个已撤回的想法：把传统交易包装进两种新的 EIP-2718 类型化信封（SSZ 编码的签名加上原始 RLP 载荷），这样既能淘汰传统编码，又不会使旧签名失效。

## 它解决什么问题？

[EIP-2718](/eip-2718/) 引入了类型化交易：`TransactionType || TransactionPayload`。客户端开发者希望区块中的每笔交易都使用这种信封，这样最终就能去掉对旧式 RLP 交易的特殊处理。

但传统交易不能简单地用新格式重新签名：有些是很久以前由无法产生新签名的密钥或设备签署的，资金可能会因此卡住。EIP-2972 试图通过定义与传统交易**签名兼容**的类型化交易来弥合这一点，使任何客户端都能自动把现有的传统交易重新编码为新形式。

## 它如何运作

两种交易类型，对应两种传统交易形态：

| 类型 | 编码 | 对应的传统形态 |
| --- | --- | --- |
| `0x00` | `0x00 ‖ ssz(yParity, r, s, rlp([nonce, gasPrice, gasLimit, to, value, data]))` | [EIP-155](/eip-155/) 之前，无链 ID |
| `0x01` | `0x01 ‖ ssz(yParity, r, s, rlp([nonce, gasPrice, gasLimit, to, value, data, chainId, 0, 0]))` | 带链 ID 的 EIP-155 |

关键思路：

- 内层 RLP 列表正是传统签名者所签署的内容，所以现有签名依然有效。
- 签名被提取到前面，作为固定大小的 SSZ 字段（`yParity`、`r`、`s`），因此验证者无需先解码 RLP 再从 `v` 中解出链 ID，就可以检查签名。
- 收据也有与之对应的类型化 SSZ 编码。
- 分叉之后，普通的 `rlp(nonce, …, v, r, s)` 交易将不再在区块中有效；节点在收到时会转换它们。

由于同一个签名既能生成传统编码也能生成包装编码，并且两者共享 nonce，所以最终只有一个能被打包。

## 示例代码

把 EIP-155 传统交易包装为类型 `0x01` 的伪代码：

```python
def wrap_legacy_155(tx):
    signed = rlp.encode([tx.nonce, tx.gas_price, tx.gas_limit, tx.to,
                         tx.value, tx.data, tx.chain_id, 0, 0])
    y_parity = (tx.v - 35 - 2 * tx.chain_id)  # recover parity from EIP-155 v
    # SSZ container: yParity (bool), r, s (bytes32), offset to signedData (uint32 LE)
    body = (bytes([y_parity]) + tx.r.to_bytes(32, "big") + tx.s.to_bytes(32, "big")
            + (69).to_bytes(4, "little") + signed)
    return b"\x01" + body
```

4 字节小端偏移量 69（`0x45000000`）就是规范指出 SSZ 编码等于 `yParity ‖ r ‖ s ‖ 0x45000000 ‖ rlp(...)` 的原因。

## 需要注意

- **状态：Withdrawn。** 这些交易的哈希和 Merkle 化在规范中仍被标记为 TODO。
- 以太坊走了另一条路：传统交易以原始 RLP 形式继续有效，与类型化交易并存。类型 `0x01` 后来在 [EIP-2930](/eip-2930/) 中被分配给了访问列表交易，所以这里的类型编号只有历史意义。
- 把交易和收据迁移到 SSZ 的目标，已由后来的其他独立提案继续推进。


---

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