Skip to main content

PlonkVerifierHelper

Overview​

License: MIT​

library PlonkVerifierHelper

This library is used to simplify the interaction with autogenerated contracts that use hardhat-zkit to verify Plonk 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​

PlonkProof​

struct PlonkProof {
PlonkVerifierHelper.ProofPoints proofPoints;
uint256[] publicSignals;
}

Structure representing a Plonk proof.

Parameters:

NameTypeDescription
proofPointsstruct PlonkVerifierHelper.ProofPointsThe proof data points
publicSignalsuint256[]The public signals associated with the proof

ProofPoints​

struct ProofPoints {
uint256[24] proofData;
}

Structure holding the proof data points.

Parameters:

NameTypeDescription
proofDatauint256[24]The array of proof-related data

Errors info​

InvalidPublicSignalsCount​

error InvalidPublicSignalsCount(uint256 arrayLength, uint256 pubSignalsCount)

FailedToCallVerifyProof​

error FailedToCallVerifyProof()

Functions info​

verifyProof​

function verifyProof(
address verifier_,
PlonkVerifierHelper.PlonkProof memory plonkProof_
) internal view returns (bool)

Function to call the verifyProof function on the verifier contract. The Plonk ZK proof is wrapped in a structure for convenience

Parameters:

NameTypeDescription
verifier_addressThe address of the verifier contract
plonkProof_struct PlonkVerifierHelper.PlonkProofThe Plonk proof to be verified

Return values:

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

verifyProof​

function verifyProof(
address verifier_,
PlonkVerifierHelper.ProofPoints memory proofPoints_,
uint256[] memory pubSignals_
) internal view returns (bool)

Function to call the verifyProof function on the verifier contract. The Plonk ZK proof points are wrapped in a structure for convenience

Parameters:

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

Return values:

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

verifyProof​

function verifyProof(
address verifier_,
uint256[24] memory proofData_,
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
proofData_uint256[24]the Plonk proof data
pubSignals_uint256[]the array of the Plonk ZK proof public signals

Return values:

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

verifyProofSafe​

function verifyProofSafe(
address verifier_,
PlonkVerifierHelper.PlonkProof memory plonkProof_,
uint256 pubSignalsCount_
) internal view returns (bool)

Function to call the verifyProof function on the verifier contract. The Plonk ZK proof is wrapped in a structure for convenience. The length of the plonkProof_.publicSignals arr must be strictly equal to pubSignalsCount_

Parameters:

NameTypeDescription
verifier_addressThe address of the verifier contract
plonkProof_struct PlonkVerifierHelper.PlonkProofThe Plonk proof to be verified
pubSignalsCount_uint256The expected number of public signals

Return values:

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

verifyProofSafe​

function verifyProofSafe(
address verifier_,
PlonkVerifierHelper.ProofPoints memory proofPoints_,
uint256[] memory pubSignals_,
uint256 pubSignalsCount_
) internal view returns (bool)

Function to call the verifyProof function on the verifier contract. The Plonk proof data are wrapped in a structure for code consistency The length of the pubSignals_ arr must be strictly equal to pubSignalsCount_

Parameters:

NameTypeDescription
verifier_addressthe address of the autogenerated Verifier contract
proofPoints_struct PlonkVerifierHelper.ProofPointsthe ProofPoints struct with the Plonk proof data
pubSignals_uint256[]the array of the Plonk 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[24] memory proofData_,
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
proofData_uint256[24]the Plonk proof data
pubSignals_uint256[]the array of the Plonk ZK proof public signals
pubSignalsCount_uint256the number of public signals

Return values:

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