EIPs Explained

ERC-1922 · Stagnant · ERC · 2018-09-14

ERC-1922: zk-SNARK Verifier Standard

Proposes one generic verify(proof, inputs, verificationKeyId) function for on-chain zk-SNARK verifier contracts, so applications can call any verifier the same way.

What problem does it solve?

zk-SNARKs let someone prove a statement about private data, for example "this transaction is valid", without revealing the data. On Ethereum, the proof is checked by a verifier contract, typically using the alt_bn128 pairing precompiles (EIP-196, EIP-197).

Each proving system and each tool generated verifiers with its own function signature and its own way of passing the proof. ERC-1922, originally proposed by EY, defines one minimal interface so that private-transaction, private-computation and scaling applications can call any compliant verifier in the same way.

How it works

The standard has a single required function, alongside ERC-165 interface detection:

verify(uint256[] proof, uint256[] inputs, bytes32 verificationKeyId) returns (bool)
  • proof: the proof flattened into a one-dimensional uint256 array. A dynamic array is used because different proving schemes (the spec mentions PGHR13, Groth16 and GM17) produce proofs of different sizes. The contract decides how to unflatten it.
  • inputs: the public inputs to the circuit, also as uint256[].
  • verificationKeyId: which circuit this proof is for. Verification keys are stored on-chain once, and callers refer to them by a bytes32 ID rather than re-sending the key every time. How IDs are assigned is up to the implementation; how keys are loaded is out of scope.

verify must return true for a valid proof and false otherwise.

Sample code

The interface, and an application that only accepts actions backed by a valid proof:

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

interface IZkVerifier /* is ERC165 */ {
    function verify(
        uint256[] calldata proof,
        uint256[] calldata inputs,
        bytes32 verificationKeyId
    ) external returns (bool result);
}

contract PrivateVoting {
    IZkVerifier public immutable verifier;
    bytes32 public immutable voteCircuit;
    mapping(uint256 => bool) public nullifierUsed;

    constructor(IZkVerifier v, bytes32 vkId) {
        verifier = v;
        voteCircuit = vkId;
    }

    function castVote(uint256[] calldata proof, uint256[] calldata inputs) external {
        uint256 nullifier = inputs[0];
        require(!nullifierUsed[nullifier], "already voted");
        require(verifier.verify(proof, inputs, voteCircuit), "invalid proof");
        nullifierUsed[nullifier] = true;
        // ... record the vote from inputs[1]
    }
}

Things to know

  • Status: Stagnant. The spec still contains many TODOs, and it never calculated its own ERC-165 interface ID.
  • verify is declared non-view, so implementations may emit events or record state, but callers cannot rely on a staticcall.
  • The standard does not cover loading verification keys or the trusted setup; any secret setup randomness ("toxic waste") must be destroyed, or false proofs become possible.
  • Generated verifiers from common tools (the spec names ZoKrates) did not follow this interface, and current tooling generally emits its own verifier signatures. Pairing gas costs were later reduced by EIP-1108.

#zk-snark #zero-knowledge #verifier #privacy #interface

Details

Authors
Michael Connor <[email protected]>, Chaitanya Konda <[email protected]>, Duncan Westland <[email protected]>
Status
Stagnant
Type
Standards Track / ERC
Created
2018-09-14
Requires

Machine-readable: Markdown · JSON