Groth16VerifierHelper
Overview
License: MIT
library Groth16VerifierHelper
This library is used to simplify the interaction with autogenerated contracts that use hardhat-zkit to verify Groth16 ZK proofs.
The main problem with the ZK verifier contracts is that the verification function always has the same signature, except for one parameter.
The input parameter is a static array uint256, the size of which depends on the number of public outputs of ZK proof,
therefore the signatures of the verification functions may be different for different schemes.
With this library there is no need to create many different interfaces for each circuit. Moreover, the library functions accept dynamic arrays of public signals, so you don't need to convert them manually to static ones.
Structs info
Groth16Proof
struct Groth16Proof {
Groth16VerifierHelper.ProofPoints proofPoints;
uint256[] publicSignals;
}
Structure representing a Groth16 proof.
Parameters:
| Name | Type | Description |
|---|---|---|
| proofPoints | struct Groth16VerifierHelper.ProofPoints | The proof data points |
| publicSignals | uint256[] | The public signals associated with the proof |
ProofPoints
struct ProofPoints {
uint256[2] a;
uint256[2][2] b;
uint256[2] c;
}
Represents proof points used in a Groth16 proof.
Parameters:
| Name | Description |
|---|
Return values:
| Name | Type | Description |
|---|
Errors info
InvalidPublicSignalsCount
error InvalidPublicSignalsCount(uint256 arrayLength, uint256 pubSignalsCount)
FailedToCallVerifyProof
error FailedToCallVerifyProof()
Functions info
verifyProof
function verifyProof(
address verifier_,
Groth16VerifierHelper.Groth16Proof memory groth16Proof_
) internal view returns (bool)
Function to call the verifyProof function on the verifier contract.
The Groth16 ZK proof is wrapped in a structure for convenience
Parameters:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | The address of the verifier contract |
| groth16Proof_ | struct Groth16VerifierHelper.Groth16Proof | The Groth16 proof to be verified |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | true if the proof is valid, false - otherwise |
verifyProof
function verifyProof(
address verifier_,
Groth16VerifierHelper.ProofPoints memory proofPoints_,
uint256[] memory pubSignals_
) internal view returns (bool)
Function to call the verifyProof function on the verifier contract.
The Groth16 ZK proof points are wrapped in a structure for convenience
Parameters:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | the address of the autogenerated Verifier contract |
| proofPoints_ | struct Groth16VerifierHelper.ProofPoints | the ProofPoints struct with Groth16 ZK proof points |
| pubSignals_ | uint256[] | the array of the Groth16 ZK proof public signals |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | true if the proof is valid, false - otherwise |
verifyProof
function verifyProof(
address verifier_,
uint256[2] memory a_,
uint256[2][2] memory b_,
uint256[2] memory c_,
uint256[] memory pubSignals_
) internal view returns (bool)
Function to call the verifyProof function on the verifier contract
Parameters:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | the address of the autogenerated Verifier contract |
| a_ | uint256[2] | the A point of the Groth16 ZK proof |
| b_ | uint256[2][2] | the B point of the Groth16 ZK proof |
| c_ | uint256[2] | the C point of the Groth16 ZK proof |
| pubSignals_ | uint256[] | the array of the Groth16 ZK proof public signals |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | true if the proof is valid, false - otherwise |
verifyProofSafe
function verifyProofSafe(
address verifier_,
Groth16VerifierHelper.Groth16Proof memory groth16Proof_,
uint256 pubSignalsCount_
) internal view returns (bool)
Function to call the verifyProof function on the verifier contract.
The Groth16 ZK proof is wrapped in a structure for convenience
The length of the groth16Proof_.publicSignals arr must be strictly equal to pubSignalsCount_
Parameters:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | The address of the verifier contract. |
| groth16Proof_ | struct Groth16VerifierHelper.Groth16Proof | The Groth16 proof to be verified. |
| pubSignalsCount_ | uint256 | The expected number of public signals. |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | Whether the proof is valid or not. |
verifyProofSafe
function verifyProofSafe(
address verifier_,
Groth16VerifierHelper.ProofPoints memory proofPoints_,
uint256[] memory pubSignals_,
uint256 pubSignalsCount_
) internal view returns (bool)
Function to call the verifyProof function on the verifier contract.
The Groth16 ZK proof points are wrapped in a structure for convenience
The length of the pubSignals_ arr must be strictly equal to pubSignalsCount_
Parameters:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | the address of the autogenerated Verifier contract |
| proofPoints_ | struct Groth16VerifierHelper.ProofPoints | the ProofPoints struct with Groth16 ZK proof points |
| pubSignals_ | uint256[] | the array of the Groth16 ZK proof public signals |
| pubSignalsCount_ | uint256 | the number of public signals |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | true if the proof is valid, false - otherwise |
verifyProofSafe
function verifyProofSafe(
address verifier_,
uint256[2] memory a_,
uint256[2][2] memory b_,
uint256[2] memory c_,
uint256[] memory pubSignals_,
uint256 pubSignalsCount_
) internal view returns (bool)
Function to call the verifyProof function on the verifier contract
The length of the pubSignals_ arr must be strictly equal to pubSignalsCount_
Parameters:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | the address of the autogenerated Verifier contract |
| a_ | uint256[2] | the A point of the Groth16 ZK proof |
| b_ | uint256[2][2] | the B point of the Groth16 ZK proof |
| c_ | uint256[2] | the C point of the Groth16 ZK proof |
| pubSignals_ | uint256[] | the array of the Groth16 ZK proof public signals |
| pubSignalsCount_ | uint256 | the number of public signals |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | true if the proof is valid, false - otherwise |