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:
| Name | Type | Description |
|---|---|---|
| proofPoints | struct PlonkVerifierHelper.ProofPoints | The proof data points |
| publicSignals | uint256[] | The public signals associated with the proof |
ProofPoints
struct ProofPoints {
uint256[24] proofData;
}
Structure holding the proof data points.
Parameters:
| Name | Type | Description |
|---|---|---|
| proofData | uint256[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:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | The address of the verifier contract |
| plonkProof_ | struct PlonkVerifierHelper.PlonkProof | The Plonk proof to be verified |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | true 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:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | the address of the autogenerated Verifier contract |
| proofPoints_ | struct PlonkVerifierHelper.ProofPoints | the ProofPoints struct with Plonk ZK proof points |
| pubSignals_ | uint256[] | the array of the Plonk 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[24] memory proofData_,
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 |
| proofData_ | uint256[24] | the Plonk proof data |
| pubSignals_ | uint256[] | the array of the Plonk ZK proof public signals |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | true 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:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | The address of the verifier contract |
| plonkProof_ | struct PlonkVerifierHelper.PlonkProof | The Plonk proof to be verified |
| pubSignalsCount_ | uint256 | The expected number of public signals |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | true 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:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | the address of the autogenerated Verifier contract |
| proofPoints_ | struct PlonkVerifierHelper.ProofPoints | the ProofPoints struct with the Plonk proof data |
| pubSignals_ | uint256[] | the array of the Plonk 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[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:
| Name | Type | Description |
|---|---|---|
| verifier_ | address | the 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_ | uint256 | the number of public signals |
Return values:
| Name | Type | Description |
|---|---|---|
| [0] | bool | true if the proof is valid, false - otherwise |