@@ -8,6 +8,8 @@ import { expect } from "chai";
8
8
import { before } from "mocha" ;
9
9
import { stub , SinonStub } from "sinon" ;
10
10
11
+ import * as snarkjs from "snarkjs" ;
12
+
11
13
import { HardhatUserConfig } from "hardhat/config" ;
12
14
13
15
import {
@@ -25,7 +27,6 @@ import { cleanUp, useEnvironment } from "@test-helpers";
25
27
import { getNormalizedFullPath } from "@src/utils/path-utils" ;
26
28
import { getCompileCacheEntry , getSetupCacheEntry } from "../utils" ;
27
29
28
- import { HardhatZKit } from "@src/types/hardhat-zkit" ;
29
30
import { BaseCircomCompilerFactory } from "@src/core" ;
30
31
import { CircomCompilerDownloader } from "@src/core/compiler/CircomCompilerDownloader" ;
31
32
@@ -58,7 +59,7 @@ describe("ZKit tasks", async function () {
58
59
return circuitFullPaths ;
59
60
}
60
61
61
- async function checkMake ( config : HardhatUserConfig , zkit : HardhatZKit ) {
62
+ async function checkMake ( config : HardhatUserConfig ) {
62
63
const cacheFullPath : string = getNormalizedFullPath ( config . paths ! . root ! , "cache" ) ;
63
64
64
65
expect ( fsExtra . readdirSync ( cacheFullPath ) ) . to . be . deep . eq ( [
@@ -70,7 +71,9 @@ describe("ZKit tasks", async function () {
70
71
expect ( entry ) . to . be . deep . eq ( await getSetupCacheEntry ( entry . circuitSourceName , entry . r1csSourcePath ) ) ;
71
72
} ) ;
72
73
73
- getZkitCircuitFullPaths ( config ) . forEach ( ( path , index ) => {
74
+ const circuitFullPaths = getZkitCircuitFullPaths ( config ) ;
75
+
76
+ circuitFullPaths . forEach ( ( path , index ) => {
74
77
expect ( fsExtra . readdirSync ( path ) ) . to . be . deep . eq ( [
75
78
`${ circuitNames [ index ] } .r1cs` ,
76
79
`${ circuitNames [ index ] } .sym` ,
@@ -84,12 +87,15 @@ describe("ZKit tasks", async function () {
84
87
const ptauFullPath : string = getNormalizedFullPath ( config . paths ! . root ! , "zkit/ptau" ) ;
85
88
expect ( fsExtra . readdirSync ( ptauFullPath ) ) . to . be . deep . eq ( [ "powers-of-tau-8.ptau" ] ) ;
86
89
87
- const circuit = await zkit . getCircuit ( "Multiplier2" ) ;
88
- await expect ( circuit ) . with . witnessInputs ( { in1 : "3" , in2 : "7" } ) . to . have . witnessOutputs ( [ "21" ] ) ;
90
+ const proof = await snarkjs . groth16 . fullProve (
91
+ { in : [ "3" , "7" , "2" ] } ,
92
+ `${ circuitFullPaths [ 1 ] } /Multiplier3Arr_js/Multiplier3Arr.wasm` ,
93
+ `${ circuitFullPaths [ 1 ] } /Multiplier3Arr.zkey` ,
94
+ ) ;
89
95
90
- const proof = await circuit . generateProof ( { in1 : "4" , in2 : "2" } ) ;
96
+ const verifier = JSON . parse ( fsExtra . readFileSync ( ` ${ circuitFullPaths [ 1 ] } /Multiplier3Arr.vkey.json` ) . toString ( ) ) ;
91
97
92
- await expect ( circuit ) . to . verifyProof ( proof ) ;
98
+ expect ( await snarkjs . groth16 . verify ( verifier , proof . publicSignals , proof . proof ) ) . to . be . true ;
93
99
}
94
100
95
101
function updateInclude ( filePath : string , newIncludePath : string ) {
@@ -342,7 +348,7 @@ describe("ZKit tasks", async function () {
342
348
await this . hre . run ( { scope : ZKIT_SCOPE_NAME , task : TASK_CIRCUITS_COMPILE } ) ;
343
349
await this . hre . run ( { scope : ZKIT_SCOPE_NAME , task : TASK_CIRCUITS_SETUP } ) ;
344
350
345
- await checkMake ( this . hre . config , this . hre . zkit ) ;
351
+ await checkMake ( this . hre . config ) ;
346
352
} ) ;
347
353
} ) ;
348
354
@@ -352,7 +358,7 @@ describe("ZKit tasks", async function () {
352
358
it ( "should correctly compile circuits and generate vkey, zkey files" , async function ( ) {
353
359
await this . hre . run ( { scope : ZKIT_SCOPE_NAME , task : TASK_CIRCUITS_MAKE } ) ;
354
360
355
- await checkMake ( this . hre . config , this . hre . zkit ) ;
361
+ await checkMake ( this . hre . config ) ;
356
362
} ) ;
357
363
} ) ;
358
364
@@ -362,7 +368,7 @@ describe("ZKit tasks", async function () {
362
368
it ( "should correctly generate verifiers after running the verifiers task" , async function ( ) {
363
369
await this . hre . run ( { scope : ZKIT_SCOPE_NAME , task : TASK_GENERATE_VERIFIERS } ) ;
364
370
365
- await checkMake ( this . hre . config , this . hre . zkit ) ;
371
+ await checkMake ( this . hre . config ) ;
366
372
367
373
const verifiersFullPath : string = getNormalizedFullPath ( this . hre . config . paths . root , "contracts/verifiers" ) ;
368
374
expect ( fsExtra . readdirSync ( verifiersFullPath ) ) . to . be . deep . eq ( circuitNames . map ( ( name ) => `${ name } Verifier.sol` ) ) ;
@@ -392,7 +398,7 @@ describe("ZKit tasks", async function () {
392
398
const cacheDir : string = getNormalizedFullPath ( this . hre . config . paths . root , "cache" ) ;
393
399
const zkitDir : string = getNormalizedFullPath ( this . hre . config . paths . root , "zkit" ) ;
394
400
395
- await checkMake ( this . hre . config , this . hre . zkit ) ;
401
+ await checkMake ( this . hre . config ) ;
396
402
397
403
await this . hre . run ( { scope : ZKIT_SCOPE_NAME , task : TASK_ZKIT_CLEAN } ) ;
398
404
0 commit comments