---
eip: 7512
label: ERC-7512
title: Onchain Representation for Audits
status: Draft
type: Standards Track
category: ERC
created: 2023-09-05
requires: 712
official: https://eips.ethereum.org/EIPS/eip-7512
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7512.md
canonical: https://eips.huatuo.xyz/zh/eip-7512/
lang: zh
tldr: 一种草案格式，让审计方对审计的 EIP-712 摘要签名，使合约可以在链上检查某个特定部署是否经过可信方审计，以及它实现了哪些 ERC。
tags: [audit, security, eip-712, signatures]
---

# ERC-7512: Onchain Representation for Audits

> Proposal to define a contract parseable representation of Audit reports.

**TL;DR:** 一种草案格式，让审计方对审计的 EIP-712 摘要签名，使合约可以在链上检查某个特定部署是否经过可信方审计，以及它实现了哪些 ERC。

## 它解决什么问题？

如今的审计报告是网站上的 PDF。想要只接受经过审计的代码的合约，例如注册新代币的跨链桥或安装模块的智能账户，没有任何机器可读的方式来检查某个部署是否经过审查、由谁审查，以及针对哪些标准。

ERC-7512 定义了一种紧凑的、已签名的**审计摘要**，合约可以验证它。例如，跨链桥运营方可以列出它信任的审计方密钥，并允许任何人提交由其中某个密钥为该确切合约地址和链签名的摘要来注册代币。

## 它如何运作

摘要是一个类型化结构：

- **Auditor**：`name`、`uri`，以及 `authors` 列表。
- **Contract**：`chainId`（[EIP-155](/eip-155/) 链 ID，以 `bytes32` 表示）和 `deployment` 地址。一份摘要只覆盖一个合约实例。
- **AuditSummary**：审计方、`issuedAt`、`ercs`（合约完整实现的 ERC 编号列表，可以为空）、被审计的合约、`auditHash`（原始报告的哈希）和 `auditUri`。

审计方用 [EIP-712](/eip-712/) 类型化数据对 `AuditSummary` 签名，并把结果附加为带有 `signedAt` 和 `Signature { type, data }` 的 `SignedAuditSummary`。支持的签名类型有 `SECP256K1`、`SECP256R1`、`ERC1271`（智能合约签名者，参见 [ERC-1271](/eip-1271/)）和 `BLS`（编码方式仍待确定）。

审计发现和严重程度被有意排除在外；摘要只表明"此实例已被审计"以及"它实现了这些 ERC"。

## 示例代码

用 ethers v6 对摘要签名（类型遵循规范中的结构）：

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

const domain = { name: "ERC-7652: Onchain Audit Representation", version: "1.0" }; // as written in the spec
const types = {
  Auditor: [{ name: "name", type: "string" }, { name: "uri", type: "string" }, { name: "authors", type: "string[]" }],
  Contract: [{ name: "chainId", type: "bytes32" }, { name: "deployment", type: "address" }],
  AuditSummary: [
    { name: "auditor", type: "Auditor" },
    { name: "issuedAt", type: "uint256" },
    { name: "ercs", type: "uint256[]" },
    { name: "auditedContract", type: "Contract" },
    { name: "auditHash", type: "bytes32" },
    { name: "auditUri", type: "string" },
  ],
};

const summary = {
  auditor: { name: "Example Audits", uri: "https://example.com", authors: ["Alice"] },
  issuedAt: 1700000000,
  ercs: [20],
  auditedContract: { chainId: zeroPadValue(toBeHex(1), 32), deployment: tokenAddress },
  auditHash: keccak256(toUtf8Bytes(reportPdfContents)),
  auditUri: "https://example.com/reports/token.pdf",
};

const sig = await auditorWallet.signTypedData(domain, types, summary);
```

## 需要注意

- 状态为 **Draft**，参考实现标记为 TBD。
- 规范文本中的域名写作 "ERC-7652"，尽管该提案是 ERC-7512；实现应遵循最终规范确定的内容。
- 已签名的摘要**不是**安全保证。规范指出，集成方必须自行判断审计方和覆盖范围。
- 一切都取决于审计方的密钥管理。目前还没有标准的审计方密钥注册表或撤销机制；预期由审计方自行公布其密钥。
- 代理和可升级合约没有被涉及：摘要绑定的是地址，而不是其背后的代码。


---

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