---
eip: 7945
label: ERC-7945
title: Confidential Transactions Supported Token
status: Final
type: Standards Track
category: ERC
created: 2025-05-09
requires: 20
official: https://eips.ethereum.org/EIPS/eip-7945
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7945.md
canonical: https://eips.huatuo.xyz/zh/eip-7945/
lang: zh
tldr: 一个最小化的、类 ERC-20 的接口，面向余额和转账金额均被加密的同质化代币，使钱包和应用无需绑定某一种证明系统即可支持机密代币。
tags: [token, privacy, confidential, zk, standard]
---

# ERC-7945: Confidential Transactions Supported Token

> Outlines a fungible token interface that hides per-account balances, boosting privacy in dApps

**TL;DR:** 一个最小化的、类 ERC-20 的接口，面向余额和转账金额均被加密的同质化代币，使钱包和应用无需绑定某一种证明系统即可支持机密代币。

## 它解决什么问题？

在普通的 [ERC-20](/eip-20/) 代币上，每个余额和每笔转账金额都是公开的。这对工资发放、资金管理、受监管机构以及许多商业支付来说是个障碍。

机密代币的设计已经存在（例如规范引用的 Zether 方案），但每个项目都自创接口。钱包很难判断某个代币是否支持机密转账，也不知道该如何调用。ERC-7945 只标准化账户模型中最小的共同接口，使不同的加密方案、证明系统和合规流程可以放在相同的函数名背后。

## 它如何运作

余额、金额和授权额度都是不透明的 `bytes`。代币自己决定其中包含什么（例如同态 ElGamal 密文），以及 `_proof` 必须证明什么。

| 函数 | 用途 |
| --- | --- |
| `confidentialBalanceOf(owner)` | 某账户的加密余额 |
| `confidentialTransfer(to, value, proof)` | 转移加密金额；证明失败则 revert |
| `confidentialApprove(spender, value, proof)` | 预留一份加密的授权额度 |
| `confidentialAllowance(owner, spender)` | 剩余的加密授权额度 |
| `confidentialTransferFrom(from, to, value, proof)` | 使用授权额度进行支出 |

对于 Zether 风格的代币，转账证明通常要证明：密文已针对发送方和接收方正确加密，隐藏的金额非负，并且发送方隐藏的余额足以支付。

`confidentialApprove` 与 ERC-20 的 `approve` 不同：它把调用者的加密余额**拆分**为授权额度部分和剩余部分。再次调用时，会先把旧的授权额度合并回去，然后再设置新的额度。

事件 `ConfidentialTransfer(spender, from, to, value)` 和 `ConfidentialApproval(...)` 与 ERC-20 的事件相对应。`name`、`symbol` 和 `decimals` 是可选的元数据。`confidentialTotalSupply()` 访问器是可选的，因为可读的明文总供应量会暴露铸造和销毁的金额。

## 示例代码

```solidity
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.19;

interface IERC7945 {
    function confidentialBalanceOf(address owner) external view returns (bytes memory);
    function confidentialTransfer(address to, bytes memory value, bytes memory proof) external;
    function confidentialTransferFrom(address from, address to, bytes memory value, bytes memory proof) external;
    function confidentialApprove(address spender, bytes memory value, bytes memory proof) external;
    function confidentialAllowance(address owner, address spender) external view returns (bytes memory);

    event ConfidentialTransfer(address indexed spender, address indexed from, address indexed to, bytes value);
    event ConfidentialApproval(address indexed owner, address indexed spender, bytes currentAllowancePart, bytes allowancePart);
}
```

使用 ethers v6 的客户端流程（加密和生成证明来自代币自己的 SDK）：

```ts
const encBalance = await token.confidentialBalanceOf(me);
const balance = decryptWithMyKey(encBalance);            // implementation-specific
const { ciphertext, proof } = await prover.transfer(balance, 25n, me, recipientPubKey);
await (await token.confidentialTransfer(recipient, ciphertext, proof)).wait();
```

## 需要注意

- **状态：Final。** 接口已经确定，但密码学部分完全由实现自行定义，因此两个合规的代币仍可能需要不同的客户端 SDK。
- 地址仍然是公开的：它隐藏的是金额和余额，而不是谁与谁交易。关于发送方/接收方隐私，请参阅 [ERC-8086](/eip-8086/) 中基于 note 的设计。
- 通过同时用审计者的密钥加密金额，可以在不改变函数签名的情况下实现审计。
- 代币可以同时实现 ERC-20（“fat token”），并提供在明文余额和机密余额之间转移价值的函数。
- 以明文金额铸造和销毁会泄露信息；规范建议避免这样做。


---

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