---
eip: 2474
label: EIP-2474
title: Coinbase calls
status: Stagnant
type: Standards Track
category: Core
created: 2020-01-19
official: https://eips.ethereum.org/EIPS/eip-2474
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2474.md
canonical: https://eips.huatuo.xyz/zh/eip-2474/
lang: zh
tldr: 一项已停滞的提案：让区块生产者（block.coinbase）在区块开头无需签名交易即可直接调用合约，省去零 gas 价格中继交易的开销。
tags: [core, evm, coinbase, meta-transactions, stagnant]
---

# EIP-2474: Coinbase calls

> Allow contracts to be called directly by block.coinbase (block validator), without a transaction.

**TL;DR:** 一项已停滞的提案：让区块生产者（block.coinbase）在区块开头无需签名交易即可直接调用合约，省去零 gas 价格中继交易的开销。

## 它解决什么问题？

矿工或验证者有时想执行一个对自己有利的调用，而并不真正需要发送者身份。其动机场景是充当元交易（[EIP-1077](/eip-1077/)）的中继者：区块生产者把用户签名的请求提交给合约，并由该合约而不是通过 gas 费向它支付报酬。

目前唯一的做法是签署一笔普通交易，通常把 `gasPrice` 设为 0，因为生产者反正是自己付给自己。这笔交易仍然带有需要验证的签名（一次 `ecrecover`），尽管由此得到的 `msg.sender` 与这次调用无关。EIP-2474 提议去掉这部分开销。

## 它如何运作

这个提案很简短，许多细节留作"TBD"：

- 区块生产者（`block.coinbase`）可以包含**无交易的调用**。这些调用放在区块的最前面。
- 它们照常消耗区块 gas，但不支付 gas 费；被调用的合约逻辑应以其他方式补偿生产者。
- 在这类调用中，`tx.origin = block.coinbase`，整个调用栈的 gas 价格为 0。
- 在 coinbase 调用中不允许读取 `msg.sender`，读取会抛出异常，因为不存在签名的发送者。
- 除此之外，这些调用与普通调用行为一致。

## 示例代码

仅为示意；这种行为在以太坊上并不存在。一个中继者式合约，从不读取 `msg.sender`，并向生产该区块的人付款：

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract CoinbaseRelay {
    // Under EIP-2474, the block producer could call this without a signed tx.
    // It must not touch msg.sender, which would be invalid in a coinbase call.
    function relay(address target, bytes calldata data, uint256 reward) external {
        (bool ok, ) = target.call(data);
        require(ok, "call failed");
        payable(block.coinbase).transfer(reward); // compensation instead of gas fees
    }

    receive() external payable {}
}
```

## 需要注意

- 状态：**Stagnant**。它从未被排入任何网络升级，其 Rationale、Test Cases、Implementation 和 Security 各节也从未填写。
- 规范本身指出了一个风险：设置 `tx.origin = block.coinbase` 可能会破坏那些用 `tx.origin` 做授权的设计不当的合约。
- "以其他形式"向生产者付款，会让该功能与区块生产者特有的逻辑绑定，而这会与之后区块构建方式的变化（例如提议者/构建者分离）产生交互；该提案早于这些变化。
- 其他 gas 抽象和赞助执行的方案另行探索过，例如 [EIP-2711](/eip-2711/)（已撤回）以及后来的账户抽象工作。


---

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