Skip to content

Commit 4711c4d

Browse files
author
Docs Syncer
committed
CI: 9da2d48
1 parent 1bf369b commit 4711c4d

File tree

2 files changed

+358
-16
lines changed

2 files changed

+358
-16
lines changed

docs/reference/contracts/libs/zkp/Groth16VerifierHelper.md

Lines changed: 107 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,35 @@ library Groth16VerifierHelper
99
```
1010

1111
This library is used to simplify the interaction with autogenerated contracts
12-
that use [snarkjs](https://www.npmjs.com/package/snarkjs) to verify Groth16 ZK proofs.
12+
that use [hardhat-zkit](https://github.com/dl-solarity/hardhat-zkit) to verify Groth16 ZK proofs.
1313

14-
The main problem with these contracts is that the verification function always has the same signature, except for one parameter.
14+
The main problem with the ZK verifier contracts is that the verification function always has the same signature, except for one parameter.
1515
The `input` parameter is a static array `uint256`, the size of which depends on the number of public outputs of ZK proof,
1616
therefore the signatures of the verification functions may be different for different schemes.
1717

1818
With this library there is no need to create many different interfaces for each circuit.
1919
Moreover, the library functions accept dynamic arrays of public signals, so you don't need to convert them manually to static ones.
2020
## Structs info
2121

22+
### Groth16Proof
23+
24+
```solidity
25+
struct Groth16Proof {
26+
Groth16VerifierHelper.ProofPoints proofPoints;
27+
uint256[] publicSignals;
28+
}
29+
```
30+
31+
Structure representing a Groth16 proof.
32+
33+
34+
Parameters:
35+
36+
| Name | Type | Description |
37+
| :------------ | :--------------------------------------- | :------------------------------------------- |
38+
| proofPoints | struct Groth16VerifierHelper.ProofPoints | The proof data points |
39+
| publicSignals | uint256[] | The public signals associated with the proof |
40+
2241
### ProofPoints
2342

2443
```solidity
@@ -29,6 +48,21 @@ struct ProofPoints {
2948
}
3049
```
3150

51+
Represents proof points used in a Groth16 proof.
52+
53+
54+
Parameters:
55+
56+
| Name | Description |
57+
| :--- | :---------- |
58+
59+
60+
61+
Return values:
62+
63+
| Name | Type | Description |
64+
| :--- | :--- | :---------- |
65+
3266

3367
## Errors info
3468

@@ -50,6 +84,33 @@ error FailedToCallVerifyProof()
5084

5185
### verifyProof
5286

87+
```solidity
88+
function verifyProof(
89+
address verifier_,
90+
Groth16VerifierHelper.Groth16Proof memory groth16Proof_
91+
) internal view returns (bool)
92+
```
93+
94+
Function to call the `verifyProof` function on the `verifier` contract.
95+
The Groth16 ZK proof is wrapped in a structure for convenience
96+
97+
98+
Parameters:
99+
100+
| Name | Type | Description |
101+
| :------------ | :---------------------------------------- | :------------------------------------ |
102+
| verifier_ | address | The address of the verifier contract |
103+
| groth16Proof_ | struct Groth16VerifierHelper.Groth16Proof | The Groth16 proof to be verified |
104+
105+
106+
Return values:
107+
108+
| Name | Type | Description |
109+
| :--- | :--- | :-------------------------------------------- |
110+
| [0] | bool | true if the proof is valid, false - otherwise |
111+
112+
### verifyProof
113+
53114
```solidity
54115
function verifyProof(
55116
address verifier_,
@@ -59,16 +120,16 @@ function verifyProof(
59120
```
60121

61122
Function to call the `verifyProof` function on the `verifier` contract.
62-
The ZK proof points are wrapped in a structure for convenience
123+
The Groth16 ZK proof points are wrapped in a structure for convenience
63124

64125

65126
Parameters:
66127

67128
| Name | Type | Description |
68129
| :----------- | :--------------------------------------- | :---------------------------------------------------- |
69130
| verifier_ | address | the address of the autogenerated `Verifier` contract |
70-
| proofPoints_ | struct Groth16VerifierHelper.ProofPoints | the ProofPoints struct with ZK proof points |
71-
| pubSignals_ | uint256[] | the array of the ZK proof public signals |
131+
| proofPoints_ | struct Groth16VerifierHelper.ProofPoints | the ProofPoints struct with Groth16 ZK proof points |
132+
| pubSignals_ | uint256[] | the array of the Groth16 ZK proof public signals |
72133

73134

74135
Return values:
@@ -97,10 +158,10 @@ Parameters:
97158
| Name | Type | Description |
98159
| :---------- | :------------ | :---------------------------------------------------- |
99160
| verifier_ | address | the address of the autogenerated `Verifier` contract |
100-
| a_ | uint256[2] | the A point of the ZK proof |
101-
| b_ | uint256[2][2] | the B point of the ZK proof |
102-
| c_ | uint256[2] | the C point of the ZK proof |
103-
| pubSignals_ | uint256[] | the array of the ZK proof public signals |
161+
| a_ | uint256[2] | the A point of the Groth16 ZK proof |
162+
| b_ | uint256[2][2] | the B point of the Groth16 ZK proof |
163+
| c_ | uint256[2] | the C point of the Groth16 ZK proof |
164+
| pubSignals_ | uint256[] | the array of the Groth16 ZK proof public signals |
104165

105166

106167
Return values:
@@ -111,6 +172,36 @@ Return values:
111172

112173
### verifyProofSafe
113174

175+
```solidity
176+
function verifyProofSafe(
177+
address verifier_,
178+
Groth16VerifierHelper.Groth16Proof memory groth16Proof_,
179+
uint256 pubSignalsCount_
180+
) internal view returns (bool)
181+
```
182+
183+
Function to call the `verifyProof` function on the `verifier` contract.
184+
The Groth16 ZK proof is wrapped in a structure for convenience
185+
The length of the `groth16Proof_.publicSignals` arr must be strictly equal to `pubSignalsCount_`
186+
187+
188+
Parameters:
189+
190+
| Name | Type | Description |
191+
| :--------------- | :---------------------------------------- | :-------------------------------------- |
192+
| verifier_ | address | The address of the verifier contract. |
193+
| groth16Proof_ | struct Groth16VerifierHelper.Groth16Proof | The Groth16 proof to be verified. |
194+
| pubSignalsCount_ | uint256 | The expected number of public signals. |
195+
196+
197+
Return values:
198+
199+
| Name | Type | Description |
200+
| :--- | :--- | :--------------------------------- |
201+
| [0] | bool | Whether the proof is valid or not. |
202+
203+
### verifyProofSafe
204+
114205
```solidity
115206
function verifyProofSafe(
116207
address verifier_,
@@ -121,7 +212,7 @@ function verifyProofSafe(
121212
```
122213

123214
Function to call the `verifyProof` function on the `verifier` contract.
124-
The ZK proof points are wrapped in a structure for convenience
215+
The Groth16 ZK proof points are wrapped in a structure for convenience
125216
The length of the `pubSignals_` arr must be strictly equal to `pubSignalsCount_`
126217

127218

@@ -130,8 +221,8 @@ Parameters:
130221
| Name | Type | Description |
131222
| :--------------- | :--------------------------------------- | :---------------------------------------------------- |
132223
| verifier_ | address | the address of the autogenerated `Verifier` contract |
133-
| proofPoints_ | struct Groth16VerifierHelper.ProofPoints | the ProofPoints struct with ZK proof points |
134-
| pubSignals_ | uint256[] | the array of the ZK proof public signals |
224+
| proofPoints_ | struct Groth16VerifierHelper.ProofPoints | the ProofPoints struct with Groth16 ZK proof points |
225+
| pubSignals_ | uint256[] | the array of the Groth16 ZK proof public signals |
135226
| pubSignalsCount_ | uint256 | the number of public signals |
136227

137228

@@ -163,10 +254,10 @@ Parameters:
163254
| Name | Type | Description |
164255
| :--------------- | :------------ | :---------------------------------------------------- |
165256
| verifier_ | address | the address of the autogenerated `Verifier` contract |
166-
| a_ | uint256[2] | the A point of the ZK proof |
167-
| b_ | uint256[2][2] | the B point of the ZK proof |
168-
| c_ | uint256[2] | the C point of the ZK proof |
169-
| pubSignals_ | uint256[] | the array of the ZK proof public signals |
257+
| a_ | uint256[2] | the A point of the Groth16 ZK proof |
258+
| b_ | uint256[2][2] | the B point of the Groth16 ZK proof |
259+
| c_ | uint256[2] | the C point of the Groth16 ZK proof |
260+
| pubSignals_ | uint256[] | the array of the Groth16 ZK proof public signals |
170261
| pubSignalsCount_ | uint256 | the number of public signals |
171262

172263

0 commit comments

Comments
 (0)