@@ -205,6 +205,78 @@ describe("Semaphore", () => {
205
205
} )
206
206
207
207
describe ( "# verifyProof" , ( ) => {
208
+ const groupId = 10
209
+ const message = 2
210
+ const identity = new Identity ( "0" )
211
+
212
+ const group = new Group ( )
213
+
214
+ group . addMembers ( members )
215
+
216
+ let fullProof : SemaphoreProof
217
+
218
+ before ( async ( ) => {
219
+ await semaphoreContract [ "createGroup(uint256,address)" ] ( groupId , accounts [ 0 ] )
220
+
221
+ await semaphoreContract . addMembers ( groupId , members )
222
+
223
+ fullProof = await generateProof ( identity , group , message , group . root as string , 10 )
224
+ } )
225
+
226
+ it ( "Should not verify a proof if the group does not exist" , async ( ) => {
227
+ const transaction = semaphoreContract . verifyProof ( 11 , 1 , 0 , message , 0 , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] )
228
+
229
+ await expect ( transaction ) . to . be . revertedWithCustomError ( semaphoreContract , "Semaphore__GroupDoesNotExist" )
230
+ } )
231
+
232
+ it ( "Should not verify a proof if the Merkle tree root is not part of the group" , async ( ) => {
233
+ const transaction = semaphoreContract . verifyProof ( groupId , 1 , 0 , message , 0 , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] )
234
+
235
+ await expect ( transaction ) . to . be . revertedWithCustomError (
236
+ semaphoreContract ,
237
+ "Semaphore__MerkleTreeRootIsNotPartOfTheGroup"
238
+ )
239
+ } )
240
+
241
+ it ( "Should verify a proof for an onchain group" , async ( ) => {
242
+ const validProof = await semaphoreContract . verifyProof (
243
+ groupId ,
244
+ fullProof . merkleRoot ,
245
+ fullProof . nullifier ,
246
+ fullProof . message ,
247
+ fullProof . merkleRoot ,
248
+ fullProof . proof
249
+ )
250
+
251
+ expect ( validProof ) . to . equal ( true )
252
+ } )
253
+
254
+ it ( "Should not verify a proof if the Merkle tree root is expired" , async ( ) => {
255
+ const groupId = 2
256
+
257
+ const group = new Group ( )
258
+
259
+ group . addMembers ( [ members [ 0 ] , members [ 1 ] ] )
260
+
261
+ const fullProof = await generateProof ( identity , group , message , group . root as string , 10 )
262
+
263
+ const transaction = semaphoreContract . verifyProof (
264
+ groupId ,
265
+ fullProof . merkleRoot ,
266
+ fullProof . nullifier ,
267
+ fullProof . message ,
268
+ fullProof . merkleRoot ,
269
+ fullProof . proof
270
+ )
271
+
272
+ await expect ( transaction ) . to . be . revertedWithCustomError (
273
+ semaphoreContract ,
274
+ "Semaphore__MerkleTreeRootIsExpired"
275
+ )
276
+ } )
277
+ } )
278
+
279
+ describe ( "# validateProof" , ( ) => {
208
280
const message = 2
209
281
const identity = new Identity ( "0" )
210
282
const groupOneMemberId = 6
@@ -234,23 +306,8 @@ describe("Semaphore", () => {
234
306
)
235
307
} )
236
308
237
- it ( "Should not verify a proof if the group does not exist" , async ( ) => {
238
- const transaction = semaphoreContract . verifyProof ( 10 , 1 , 0 , message , 0 , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] )
239
-
240
- await expect ( transaction ) . to . be . revertedWithCustomError ( semaphoreContract , "Semaphore__GroupDoesNotExist" )
241
- } )
242
-
243
- it ( "Should not verify a proof if the Merkle tree root is not part of the group" , async ( ) => {
244
- const transaction = semaphoreContract . verifyProof ( 2 , 1 , 0 , message , 0 , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] )
245
-
246
- await expect ( transaction ) . to . be . revertedWithCustomError (
247
- semaphoreContract ,
248
- "Semaphore__MerkleTreeRootIsNotPartOfTheGroup"
249
- )
250
- } )
251
-
252
309
it ( "Should throw an exception if the proof is not valid" , async ( ) => {
253
- const transaction = semaphoreContract . verifyProof (
310
+ const transaction = semaphoreContract . validateProof (
254
311
groupId ,
255
312
fullProof . merkleRoot ,
256
313
fullProof . nullifier ,
@@ -262,8 +319,8 @@ describe("Semaphore", () => {
262
319
await expect ( transaction ) . to . be . revertedWithCustomError ( semaphoreContract , "Semaphore__InvalidProof" )
263
320
} )
264
321
265
- it ( "Should verify a proof for an onchain group with one member correctly" , async ( ) => {
266
- const transaction = semaphoreContract . verifyProof (
322
+ it ( "Should validate a proof for an onchain group with one member correctly" , async ( ) => {
323
+ const transaction = semaphoreContract . validateProof (
267
324
groupOneMemberId ,
268
325
fullProofOneMember . merkleRoot ,
269
326
fullProofOneMember . nullifier ,
@@ -273,7 +330,7 @@ describe("Semaphore", () => {
273
330
)
274
331
275
332
await expect ( transaction )
276
- . to . emit ( semaphoreContract , "ProofVerified " )
333
+ . to . emit ( semaphoreContract , "ProofValidated " )
277
334
. withArgs (
278
335
groupOneMemberId ,
279
336
fullProofOneMember . merkleRoot ,
@@ -284,8 +341,8 @@ describe("Semaphore", () => {
284
341
)
285
342
} )
286
343
287
- it ( "Should verify a proof for an onchain group with more than one member correctly" , async ( ) => {
288
- const transaction = semaphoreContract . verifyProof (
344
+ it ( "Should validate a proof for an onchain group with more than one member correctly" , async ( ) => {
345
+ const transaction = semaphoreContract . validateProof (
289
346
groupId ,
290
347
fullProof . merkleRoot ,
291
348
fullProof . nullifier ,
@@ -295,7 +352,7 @@ describe("Semaphore", () => {
295
352
)
296
353
297
354
await expect ( transaction )
298
- . to . emit ( semaphoreContract , "ProofVerified " )
355
+ . to . emit ( semaphoreContract , "ProofValidated " )
299
356
. withArgs (
300
357
groupId ,
301
358
fullProof . merkleRoot ,
@@ -306,8 +363,8 @@ describe("Semaphore", () => {
306
363
)
307
364
} )
308
365
309
- it ( "Should not verify the same proof for an onchain group twice" , async ( ) => {
310
- const transaction = semaphoreContract . verifyProof (
366
+ it ( "Should not validate the same proof for an onchain group twice" , async ( ) => {
367
+ const transaction = semaphoreContract . validateProof (
311
368
groupId ,
312
369
fullProof . merkleRoot ,
313
370
fullProof . nullifier ,
@@ -321,28 +378,5 @@ describe("Semaphore", () => {
321
378
"Semaphore__YouAreUsingTheSameNullifierTwice"
322
379
)
323
380
} )
324
-
325
- it ( "Should not verify a proof if the Merkle tree root is expired" , async ( ) => {
326
- const groupId = 2
327
- const group = new Group ( )
328
-
329
- group . addMembers ( [ members [ 0 ] , members [ 1 ] ] )
330
-
331
- const fullProof = await generateProof ( identity , group , message , group . root as string , 10 )
332
-
333
- const transaction = semaphoreContract . verifyProof (
334
- groupId ,
335
- fullProof . merkleRoot ,
336
- fullProof . nullifier ,
337
- fullProof . message ,
338
- fullProof . merkleRoot ,
339
- fullProof . proof
340
- )
341
-
342
- await expect ( transaction ) . to . be . revertedWithCustomError (
343
- semaphoreContract ,
344
- "Semaphore__MerkleTreeRootIsExpired"
345
- )
346
- } )
347
381
} )
348
382
} )
0 commit comments