---
eip: 7873
label: EIP-7873
title: EOF - TXCREATE and InitcodeTransaction type
status: Stagnant
type: Standards Track
category: Core
created: 2025-01-31
requires: 3540, 3670, 3860, 7620
official: https://eips.ethereum.org/EIPS/eip-7873
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7873.md
canonical: https://eips.huatuo.xyz/zh/eip-7873/
lang: zh
tldr: 提议了一个 TXCREATE opcode 和一种携带 initcode blob 的新类型 6 InitcodeTransaction，为 EOF 提供部署合约的方式，因为 EOF 禁止了传统的创建交易以及 CREATE/CREATE2。
tags: [eof, evm, contract-creation, transactions, stagnant]
---

# EIP-7873: EOF - TXCREATE and InitcodeTransaction type

> Adds a `TXCREATE` instruction to EOF and an accompanying transaction type allowing to create EOF contracts from transaction data

**TL;DR:** 提议了一个 TXCREATE opcode 和一种携带 initcode blob 的新类型 6 InitcodeTransaction，为 EOF 提供部署合约的方式，因为 EOF 禁止了传统的创建交易以及 CREATE/CREATE2。

## 它解决什么问题？

EVM 对象格式（EOF，[EIP-3540](/eip-3540/)）移除了代码的可观察性。因此 EOF 合约无法通过传统途径部署：创建交易（`to` 为空）、`CREATE` 或 `CREATE2`。[EIP-7620](/eip-7620/) 增加了 `EOFCREATE`，但它只能部署已经嵌入现有合约中的子容器。

EOA 或工厂合约仍然需要一种办法来部署在交易时才提供的**任意** EOF 代码，包括不依赖 nonce 的确定性反事实（counterfactual）地址。EIP-7873 提供了这种办法。

## 它如何运作

**新的交易类型** `InitcodeTransaction`，类型为 `0x06`。它是在 [EIP-1559](/eip-1559/) 交易基础上增加一个 `initcodes` 字段：1 到 256 个字节串组成的列表，每个都非空且不超过 `MAX_INITCODE_SIZE`。必须设置 `to`：该交易调用一个使用 `TXCREATE` 的合约（例如工厂合约）。initcode 字节按 calldata 的方式计费，包括 [EIP-7623](/eip-7623/) 的下限。在交易验证阶段不会进行 EOF 验证，以避免对内存池发起 DoS。

**新的指令** `TXCREATE`（`0xed`），EOF 代码和传统代码都可以使用：

1. 消耗 `32000` gas；在静态上下文中失败。
2. 弹出 `tx_initcode_hash, salt, input_offset, input_size, value`。
3. 查找哈希匹配的 `initcodes` 条目。如果没有（或交易不是类型 6），则压入 `0`，且不消耗 initcode 的 gas。
4. 递归验证该容器；失败时压入 `0`（一种"轻量"失败）。
5. 以内存中的输入作为 calldata 运行它。成功时以 `RETURNCODE`（来自 EIP-7620）结束，存储部署容器，并压入新地址。

地址为 `keccak256(0xff || sender32 || salt)[12:]`，与 `EOFCREATE` 方案相同。是否把 initcode 哈希混入 `salt`，由调用方决定。

传统的创建交易（`to` 为空的类型 0、1 和 2）不会解析 EOF：以 `0xEF` 开头的输入只会执行未定义的 `0xEF` opcode 然后停止。

## 示例代码

新交易类型的编码（依据 [EIP-2718](/eip-2718/)）：

```
0x06 || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas,
             gas_limit, to, value, data, access_list, initcodes,
             y_parity, r, s])

signing hash = keccak256(0x06 || rlp([chain_id, nonce, max_priority_fee_per_gas,
             max_fee_per_gas, gas_limit, to, value, data, access_list, initcodes]))
```

`TXCREATE` 的栈使用，伪代码：

```python
# stack: tx_initcode_hash, salt, input_offset, input_size, value
initcode = find(tx.initcodes, lambda c: keccak256(c) == tx_initcode_hash)
if tx.type != 0x06 or initcode is None or not eof_validate(initcode):
    push(0)                     # light failure
else:
    new_address = keccak256(b"\xff" + pad32(sender) + salt)[12:]
    push(new_address if run_initcode(initcode, memory[input_offset:input_offset+input_size], value) else 0)
```

## 需要注意

- **状态：Stagnant**，EOF 本身（[EIP-3540](/eip-3540/)、[EIP-7620](/eip-7620/)）以及 EOF 元 EIP [EIP-7692](/eip-7692/) 也都是 Stagnant。这些都没有在以太坊主网上线。
- 它会让 [EIP-7698](/eip-7698/)（EOF 创建交易）变得不必要；规范建议可以撤回那个 EIP。
- 规范的 Security Considerations 一节只有"Needs discussion."。
- 部署的代码仍受 `MAX_CODE_SIZE`（24,576 字节，[EIP-170](/eip-170/)）限制，并按每字节 200 gas 计费。


---

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