ERC-7992 Verifiable ML inference (ZKML) (Verifiable ML Model Inference (ZKML))
Draft · Other · created 2025-07-23
Standardizes a model registry and verifier interface so that smart contracts can verify, via zero-knowledge proof, the inference results of ML models they cannot execute directly.
Why it is needed
Smart contracts cannot execute large ML models directly, nor can they simply trust model output values passed by an oracle as-is. So far projects have taken one of three approaches: trusting a centralized server, simplifying the model to fit on-chain, or relying on a social consensus committee, none of which provide cryptographic guarantees. Zero-knowledge machine learning (ZKML) fills this trust gap by letting a prover show, concisely and privately, that a specific model produced a specific output from a specific input. But without a shared interface, the ABI and registry structure differ for every dApp/verifier pair, making them hard to combine and reuse.
What to implement
event ModelDeprecated(uint256 indexed modelId);: Signals that the given modelId has been deprecated so it is no longer used.function registerModel(ModelCommitment calldata commitment) external returns (uint256 modelId);: Registers a commitment containing the model's weight, circuit, and verification key hashes, and is issued a unique modelId.function updateModel(uint256 modelId, ModelCommitment calldata newCommitment) external;: Can only be called by the model owner; replaces the commitment content of an existing modelId with a new value.function deprecateModel(uint256 modelId) external;: Can only be called by the model owner; marks the given modelId as deprecated so it is no longer used.function getModel(uint256 modelId) external view returns (ModelCommitment memory commitment, bool deprecated, address owner);: Looks up the current commitment content, deprecation status, and owner address for a given modelId.function proofSystemOf(uint256 modelId) external view returns (bytes4);: Looks up the identifier for which proof system a given model uses.function registry() external view returns (address registryAddress);: Looks up the address of the registry contract this verifier references.event InferenceStored(bytes32 indexed inferenceId);: Signals that a verified inference record has been stored.function getInference(bytes32 inferenceId) external view returns (uint256 modelId, bytes32 inputCommitment, bytes memory output);: Looks up a stored inference record by inferenceId.
In depth
Model commitments and modelId
A ModelCommitment consists of modelHash (weights + architecture), circuitHash (the proof circuit or AIR), vkHash (verification key), proofSystemId, and an optional off-chain metadata uri. Calling registerModel issues a unique modelId corresponding to this commitment. Implementations may decide their own policy on whether to allow version updates under a single modelId or require a new modelId for every change, but that policy must be documented.
proofSystemId derivation rule
proofSystemId must be the first 4 bytes of bytes4(keccak256(abi.encodePacked(<proof-system-name-version>))). Here the string consists of lowercase letters and hyphens, for example forms like "groth16-bn254-v1", "plonk-bn254-v2", or "stark-airfoo-v1". This approach guarantees deterministic, collision-free identifiers across implementations.
Registry interface
IERCZKMLRegistry provides registerModel, updateModel, deprecateModel, and getModel. The registry must expose an owner for each model, and implementations must have some ownership/access-control mechanism, whether a simple owner store, ERC-173, or role-based access control. updateModel and deprecateModel can only be called by that model's owner, and getModel returns the current commitment content, deprecation status, and owner address together.
verifyInference behavior and errors
verifyInference first fetches the modelId's commitment from the registry and verifies the proof. It must revert if the proof is invalid (InvalidProof), does not match the model (ModelMismatch), the input commitment differs (InputCommitmentMismatch), the output does not match (OutputMismatch), the proof system is unsupported (UnsupportedProofSystem), or the model has been deprecated (VerificationRefused_ModelDeprecated). Completing successfully itself signifies validity, and it is recommended to emit an InferenceVerified event at that point. It is recommended that the verifier hold no state beyond emitting the event; stateful functionality can be added via extensions.
Input commitments and output schema
inputCommitment is a hash commitment over both private inputs and inputs declared as public; it must apply domain separation, and must include a nonce or salt when the case is one-time or potentially non-deterministic. output is ABI-encoded bytes, and consuming parties must agree on its schema; it can optionally be further verified with an outputCommitment, but that is not included in the minimal interface.
Optional storage extension
When replay is a concern (e.g. non-deterministic models or one-time inferences), inputCommitment must include a source of uniqueness such as a nonce or salt. IERCZKMLStorageExtension's verifyAndStoreInference verifies the proof and then stores a record under inferenceId = keccak256(abi.encodePacked(modelId, inputCommitment, output)), allowing modelId, inputCommitment, and output to be looked up again via getInference.
Design rationale
Having verifyInference return nothing on success and revert on failure eliminates an unnecessary boolean return, saving gas, and aligns with recent Solidity patterns such as OpenZeppelin's SafeERC20. Separating the registry from the verifier allows each to be upgraded independently, and keeping proof and output as opaque bytes avoids binding the standard to a specific proof system or output schema.
Proposal status
This ERC is currently in Draft status, meaning it is a draft whose details may still change or whose discussion may remain stalled.
Things to watch out for
- Replay attacks: When inputs must be unique, inputCommitment must include a nonce or salt, and the contract may also directly track inferenceIds that have already been used.
- Model commitment drift: Updating a commitment may invalidate existing proofs, so consumers should pin a reference to a specific modelId and commitment hash, or check the deprecation status.
- Hash domain separation: A distinguishing prefix such as "ZKML_MODEL_V1" should be used so that hashes from different contexts do not collide.
- Output value ambiguity: If the schema of the output bytes is not verified or committed to, maliciously tampered output can pass through unchanged.
- Denial of service (DoS) from verification computation: Proof verification costs can be heavy, so off-chain verification combined with a succinct on-chain proof, or batching and aggregation, should be considered.