Skip to main content

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:

NameTypeDescription
proofPointsstruct Groth16VerifierHelper.ProofPointsThe proof data points
publicSignalsuint256[]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:

NameDescription

Return values:

NameTypeDescription

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:

NameTypeDescription
verifier_addressThe address of the verifier contract
groth16Proof_struct Groth16VerifierHelper.Groth16ProofThe Groth16 proof to be verified

Return values:

NameTypeDescription
[0]booltrue 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:

NameTypeDescription
verifier_addressthe address of the autogenerated Verifier contract
proofPoints_struct Groth16VerifierHelper.ProofPointsthe ProofPoints struct with Groth16 ZK proof points
pubSignals_uint256[]the array of the Groth16 ZK proof public signals

Return values:

NameTypeDescription
[0]booltrue 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:

NameTypeDescription
verifier_addressthe 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:

NameTypeDescription
[0]booltrue 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:

NameTypeDescription
verifier_addressThe address of the verifier contract.
groth16Proof_struct Groth16VerifierHelper.Groth16ProofThe Groth16 proof to be verified.
pubSignalsCount_uint256The expected number of public signals.

Return values:

NameTypeDescription
[0]boolWhether 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:

NameTypeDescription
verifier_addressthe address of the autogenerated Verifier contract
proofPoints_struct Groth16VerifierHelper.ProofPointsthe ProofPoints struct with Groth16 ZK proof points
pubSignals_uint256[]the array of the Groth16 ZK proof public signals
pubSignalsCount_uint256the number of public signals

Return values:

NameTypeDescription
[0]booltrue 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:

NameTypeDescription
verifier_addressthe 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_uint256the number of public signals

Return values:

NameTypeDescription
[0]booltrue if the proof is valid, false - otherwise