---
eip: 7992
label: ERC-7992
title: Verifiable ML Model Inference (ZKML)
status: Draft
type: Standards Track
category: ERC
created: 2025-07-23
requires: 165
official: https://eips.ethereum.org/EIPS/eip-7992
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7992.md
canonical: https://eips.huatuo.xyz/zh/eip-7992/
lang: zh
tldr: 标准化的注册表与验证器接口，让智能合约可以接受零知识证明，证明某个特定的、已承诺的 ML 模型产生了给定的输出。
tags: [zk, zkml, ai, oracle, verifier]
---

# ERC-7992: Verifiable ML Model Inference (ZKML)

> Interfaces for registering ML model commitments and verifying zero-knowledge proofs of their inferences on-chain.

**TL;DR:** 标准化的注册表与验证器接口，让智能合约可以接受零知识证明，证明某个特定的、已承诺的 ML 模型产生了给定的输出。

## 它解决什么问题？

智能合约无法运行真正的机器学习模型，也没有理由信任一个声称“模型说了 X”的服务器。如今各项目要么信任中心化 API，要么把模型缩小到能放进链上，要么依赖委员会。

零知识机器学习（ZKML）让证明者可以证明：某个特定模型在特定输入上产生了特定输出，同时不泄露私有输入或权重。但每个项目的对接方式都不一样。ERC-7992 标准化了链上的边界：**哪个模型**（承诺的注册表）以及**这次推理是否有效**（只有一个函数的验证器），与证明系统无关。

## 它如何运作

**注册表（`IERCZKMLRegistry`）。** 所有者注册一个 `ModelCommitment` 并获得 `modelId`。该承诺包含：

- `modelHash` – 权重和架构
- `circuitHash` – 算术电路或 AIR
- `vkHash` – 验证密钥
- `proofSystemId` – 规范名称（如 `"groth16-bn254-v1"`）的 `keccak256` 的前 4 字节
- `uri` – 可选的链下元数据

只有所有者可以更新或弃用模型；`getModel` 返回承诺、弃用标志和所有者。

**验证器（`IERCZKMLVerifier`）。** `verifyInference(modelId, inputCommitment, output, proof)` 获取承诺，分派到正确的证明系统，并在**任何失败时 revert**；正常返回即表示证明有效。它应当触发 `InferenceVerified`。输入通过一个 `bytes32` 承诺绑定，在需要防重放时应包含 nonce；`output` 是 ABI 编码的字节，其模式需由使用方事先约定。

可选的存储扩展 `verifyAndStoreInference` 会以 `keccak256(modelId, inputCommitment, output)` 为键记录已验证的结果，供之后查询。

## 示例代码

在合约中使用已验证的推理：

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

interface IERCZKMLVerifier {
    function verifyInference(uint256 modelId, bytes32 inputCommitment, bytes calldata output, bytes calldata proof) external;
}

contract RiskGate {
    IERCZKMLVerifier public immutable verifier;
    uint256 public immutable modelId;
    mapping(bytes32 => bool) public used;

    constructor(IERCZKMLVerifier v, uint256 id) { verifier = v; modelId = id; }

    function act(bytes32 inputCommitment, bytes calldata output, bytes calldata proof) external {
        require(!used[inputCommitment], "replay");
        used[inputCommitment] = true;
        verifier.verifyInference(modelId, inputCommitment, output, proof); // reverts if invalid
        uint256 score = abi.decode(output, (uint256));
        require(score < 500, "too risky");
        // ...proceed
    }
}
```

用 ethers v6 计算 `proofSystemId`：

```ts
import { id } from "ethers";
const proofSystemId = id("groth16-bn254-v1").slice(0, 10); // bytes4
```

## 需要注意

- **状态：Draft。** 名称和错误集合仍可能改变。
- 验证器证明的是计算与已承诺的电路一致；该电路是否忠实地表示了模型，则是链下的信任与审计问题。
- 更新模型的承诺可能改变证明的含义。如规范所建议，使用方应固定一个 `modelId` 并检查是否已弃用。
- `modelId` 的所有权必须采用某种访问控制方案；[ERC-173](/eip-173/) 是提到的一种选择。
- 证明验证可能消耗大量 gas，因此规范把验证和存储作为两个独立的调用。


---

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