---
eip: 3074
label: EIP-3074
title: AUTH and AUTHCALL opcodes
status: Withdrawn
type: Standards Track
category: Core
created: 2020-10-15
requires: 155
official: https://eips.ethereum.org/EIPS/eip-3074
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3074.md
canonical: https://eips.huatuo.xyz/zh/eip-3074/
lang: zh
tldr: "提议新增 AUTH 和 AUTHCALL 操作码，让 EOA 只需签名一次就能把控制权委托给一个\"invoker\"合约，从而实现批处理和代付 gas；已撤回，被 EIP-7702 取代。"
tags: [eoa, account-abstraction, opcodes, sponsored-transactions, core]
---

# EIP-3074: AUTH and AUTHCALL opcodes

> Allow externally owned accounts to delegate control to a contract.

**TL;DR:** 提议新增 AUTH 和 AUTHCALL 操作码，让 EOA 只需签名一次就能把控制权委托给一个"invoker"合约，从而实现批处理和代付 gas；已撤回，被 EIP-7702 取代。

## 它解决什么问题？

外部拥有账户（EOA）每笔交易只能做一次调用，而且必须用 ETH 支付 gas。用户希望获得批处理（一次完成 approve 和 swap）、gas 赞助（由别人付费）、过期时间等智能钱包功能，而不必把资金迁移到新的合约钱包。

一个关键动机是**赞助交易**：许多账户持有有价值的代币却没有 ETH，没有 ETH 就连换取 ETH 的兑换交易都付不起。EIP-3074 没有为每个功能都在新的交易类型中固化，而是让 EOA 能把控制权**委托**给一个可以实现任意逻辑的合约。

## 它如何运作

两个新操作码：

**`AUTH`（0xf6）** 接收一个 `authority` 地址和一段保存 `yParity, r, s, commit` 的内存范围。它验证对以下内容的 secp256k1 签名：

```
keccak256(MAGIC || chainId || nonce || invokerAddress || commit)   // MAGIC = 0x04
```

如果签名者等于 `authority`（且 `authority` 没有代码），它会设置帧内局部的上下文变量 `authorized = authority` 并返回 1；否则清除 `authorized` 并返回 0。成本：3,100，加上内存扩展，再加上 `authority` 为 warm/cold 时的 100/2,600。

**`AUTHCALL`（0xf7）** 的工作方式与 `CALL` 类似，但被调用方看到的是 `msg.sender == authorized`，并且 `value` 取自 authorized 账户的余额。如果 `authorized` 未设置，则执行无效。没有 2,300 gas 的津贴，所以转账价值的额外成本是 6,700 而不是 9,000。

执行这些操作码的合约就是 **invoker**。用户对特定的 invoker 地址和一个 `commit` 哈希签名；安全的 invoker 会根据调用细节（target、calldata、value、gas、它自己的重放 nonce）重新计算 `commit`，仅在两者匹配时才继续。把 EOA 当前的 `nonce` 包含在已签名消息中，意味着 EOA 发出的任何一笔普通交易都会撤销所有未完成的授权。

## 示例代码

计算 EOA 为 `AUTH` 签名的摘要（ethers v6，示意）：

```ts
import { concat, keccak256, toBeHex, zeroPadValue, Wallet, Signature } from "ethers";

const MAGIC = "0x04";
const digest = keccak256(concat([
  MAGIC,
  toBeHex(chainId, 32),
  toBeHex(await provider.getTransactionCount(eoa.address), 32), // current nonce
  zeroPadValue(invokerAddress, 32),
  commit, // bytes32: invoker-defined hash of the intended call(s)
]));

// raw signature over the digest (no EIP-191 prefix)
const sig = Signature.from(eoa.signingKey.sign(digest));
// memory passed to AUTH: yParity(1) || r(32) || s(32) || commit(32)
const authData = concat([toBeHex(sig.yParity, 1), sig.r, sig.s, commit]);
```

## 需要注意

- **状态：Withdrawn（已撤回）。** 撤回原因是"被 [EIP-7702](/eip-7702/) 取代"。EIP-7702（Set Code for EOAs）接过了同样的目标并最终上线。
- 有缺陷或恶意的 invoker 几乎可以完全控制所有为它签过名的 EOA。规范要求 invoker 不可升级，并敦促用户只为经过充分审查的 invoker 签名。
- 允许 `authorized == tx.origin` 会打破"`msg.sender == tx.origin` 只在顶层调用中成立"的假设，这会影响那些用该检查来防范三明治攻击或重入的合约。
- `AUTH` 拒绝有代码的账户，遵循 [EIP-3607](/eip-3607/) 的思路。
- 若想在不改动协议的情况下通过合约钱包实现账户抽象，请参阅 [ERC-4337](/eip-4337/)。


---

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