ERC-1922 zk-SNARK verifier standard

Stagnant · Other · created 2018-09-14

A standard that defines a common verify function for contracts that verify zk-SNARK proofs, taking a proof, public inputs, and a verification key identifier and returning the verification result as true/false.

Why it is needed

zk-SNARKs are a core technology used for private transactions, private computation, and scalability solutions that bundle transactions to increase throughput. But if each verifier contract has different function names and parameter formats, any application that wants to use this technology must build separate integration code for each verifier, and must interpret the limited information coming out of verification differently depending on the verifier. This standard was first proposed by EY and arose from the need for enterprises to keep contract, transaction, and supply chain activity private while still benefiting from blockchain and smart contracts. Without a common interface, every project trying to implement private transactions or scaling solutions has to redesign its verification logic integration from scratch, which is inefficient.

What to implement

In depth

Performing verification with a single verify function

This standard centers on a single function, verify(proof, inputs, verificationKeyId). This function MUST return true if the proof passes all checks and false if it does not. Verification is performed via an elliptic curve pairing operation.

Why are proof and inputs one-dimensional uint256[] arrays?

Both proof and inputs are defined as dynamic uint256[] arrays. uint256 is a type suited to elliptic curve operations over a finite field, and is also the type used in Christian Reitwiessner's pairing library. The arrays are dynamic because proof size varies depending on the proof generation scheme used, such as PGHR13, G16, or GM17. A one-dimensional array was used instead of a struct because dynamic arrays are easier to pass between functions in Solidity, and any proof or struct can be flattened and passed as an array. The responsibility for interpreting a flattened array falls to the implementation.

Referring to the verification key via verificationKeyId

The verification key (vk) only needs to be stored on chain once per circuit, after which every incoming (proof, inputs) pair can be verified against that stored vk. Resending the entire vk with every proof submission is unnecessary from a gas cost standpoint, so this standard defines verificationKeyId, a unique bytes32 identifier that points to a vk. The specific method for mapping a vk to a verificationKeyId is left to the implementation.

How to put the verification key on chain is outside the standard's scope

This interface does not specify a function for registering the verification key (vk) itself on the blockchain. A compliant contract MUST be able to accept (proof, inputs) proof pairs for at least one in-scope vk, and MUST be able to resolve a verificationKeyId that unambiguously refers to each such in-scope vk.

ERC-165 and prerequisite standards

Every compliant contract must implement ERC-165 alongside this standard's interface (with a caveat). ERC-165's supportsInterface(bytes4 interfaceID) lets you query whether a contract supports this standard. This specification also assumes ERC-196 (precompile for alt_bn128 elliptic curve addition and scalar multiplication) and ERC-197 (precompile for alt_bn128 optimal ate pairing checks).

The relationship between C, lambda, pk, vk, w, x, and pi

Terminology follows libsnark notation. For a circuit C, a proving key pk and verification key vk are generated during the trusted setup using a random value lambda, as (pk, vk) = G(lambda, C). lambda is called 'toxic waste': anyone who knows it can make a false proof pass as true, so it must be discarded. The prover produces a proof pi = P(pk, x, w) using the secret witness w and the public input x, and the verification function V implemented by the verify function returns V(vk, x, pi) = 1 if a w exists satisfying C(x,w)=1, and 0 otherwise.

This is not yet a finalized proposal

This ERC is in Stagnant status. The specification still has TODO markers throughout, and items such as how to compute the interface identifier and how to remain compatible with Verifier.sol contracts generated by existing compilers like ZoKrates are not yet filled in. It may progress further or remain stalled.

Original ERC · ← ERCs