HashPinnedGroth16Verifier
Inherits: IGroth16Verifier
Title: HashPinnedGroth16Verifier
Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)
Example guard in front of the generic IGroth16Verifier: callers still pass the verifying key
in calldata, so no key is stored on chain, but only the key whose keccak256(abi.encode(vk))
was fixed at deployment is accepted. Same ABI as the generic verifier, bound to one circuit.
KEY PINNING, stored-hash pattern. The generic verifier checks a proof against whatever key it is
given, and whoever generates a key can know its trapdoor and forge a proof for any input. Checking
the key's hash against an immutable on every call leaves the caller no choice of key. Compute
vkHash off chain from the audited circuit's key in exactly the IGroth16Verifier.VerifyingKey
layout this contract receives (G2 pairs in (c1, c0) order). PinnedWithdrawVerifier shows the
constant pattern, for interfaces that do not carry the key.
EXAMPLE contract; not audited.
Note:
- security-contact: daveproxy80@gmail.com
Constants
groth16
The generic Groth16 verifier that a pinned key is forwarded to.
IGroth16Verifier public immutable groth16;vkHash
keccak256(abi.encode(vk)) of the only key this contract accepts.
bytes32 public immutable vkHash;Functions
constructor
constructor(IGroth16Verifier groth16_, bytes32 vkHash_);Parameters
| Name | Type | Description |
|---|---|---|
| groth16_ | IGroth16Verifier | A Groth16Verifier facet deployment, or a diamond that serves it. |
| vkHash_ | bytes32 | keccak256(abi.encode(vk)) of the circuit's verifying key. |
verifyProof
Verifies a Groth16 proof against vk for the given public input.
Reverts with HashPinnedGroth16Verifier__UnpinnedKey unless vk hashes to vkHash.
function verifyProof(VerifyingKey calldata vk, Proof calldata proof, uint256[] calldata input)
external
view
returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| vk | VerifyingKey | The verifying key for the circuit. MUST be a key the consumer pins (see KEY PINNING above), never one taken from an untrusted caller. |
| proof | Proof | The Groth16 proof. |
| input | uint256[] | The public inputs, in the circuit's public-signal order. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool | True iff the proof is valid for vk and input. |
Errors
HashPinnedGroth16Verifier__ZeroAddress
error HashPinnedGroth16Verifier__ZeroAddress();HashPinnedGroth16Verifier__ZeroHash
error HashPinnedGroth16Verifier__ZeroHash();HashPinnedGroth16Verifier__UnpinnedKey
Thrown when the supplied key is not the pinned one.
error HashPinnedGroth16Verifier__UnpinnedKey(bytes32 supplied);Parameters
| Name | Type | Description |
|---|---|---|
| supplied | bytes32 | keccak256(abi.encode(vk)) of the key the caller passed. |