@@ -3,7 +3,6 @@ import type { CircomPluginClient } from "../services/circomPluginClient"
3
3
import { ActionPayloadTypes , AppState , ICircuitAppContext } from "../types"
4
4
import { GROTH16_VERIFIER , PLONK_VERIFIER } from './constant'
5
5
import { extractNameFromKey , extractParentFromKey } from '@remix-ui/helper'
6
- import { ethers } from 'ethers'
7
6
8
7
export const compileCircuit = async ( plugin : CircomPluginClient , appState : AppState ) => {
9
8
try {
@@ -60,39 +59,46 @@ export const runSetupAndExport = async (plugin: CircomPluginClient, appState: Ap
60
59
const zkey_final = { type : "mem" }
61
60
62
61
if ( appState . provingScheme === 'groth16' ) {
62
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'runSetupAndExport' , 'provingScheme' , 'groth16' ] )
63
63
await snarkjs . zKey . newZKey ( r1cs , ptau_final , zkey_final , zkLogger ( plugin , dispatch , 'SET_SETUP_EXPORT_FEEDBACK' ) )
64
64
const vKey = await snarkjs . zKey . exportVerificationKey ( zkey_final , zkLogger ( plugin , dispatch , 'SET_SETUP_EXPORT_FEEDBACK' ) )
65
65
66
66
if ( appState . exportVerificationKey ) {
67
67
await plugin . call ( 'fileManager' , 'writeFile' , `${ extractParentFromKey ( appState . filePath ) } /groth16/zk/keys/verification_key.json` , JSON . stringify ( vKey , null , 2 ) )
68
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'runSetupAndExport' , 'zKey.exportVerificationKey' , `${ extractParentFromKey ( appState . filePath ) } /groth16/zk/keys/verification_key.json` ] )
68
69
}
69
70
if ( appState . exportVerificationContract ) {
70
71
const templates = { groth16 : GROTH16_VERIFIER }
71
72
const solidityContract = await snarkjs . zKey . exportSolidityVerifier ( zkey_final , templates , zkLogger ( plugin , dispatch , 'SET_SETUP_EXPORT_FEEDBACK' ) )
72
73
73
74
await plugin . call ( 'fileManager' , 'writeFile' , `${ extractParentFromKey ( appState . filePath ) } /groth16/zk/build/zk_verifier.sol` , solidityContract )
75
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'runSetupAndExport' , 'zKey.exportSolidityVerifier' , `${ extractParentFromKey ( appState . filePath ) } /groth16/zk/build/zk_verifier.sol` ] )
74
76
}
75
77
dispatch ( { type : 'SET_ZKEY' , payload : zkey_final } )
76
78
dispatch ( { type : 'SET_VERIFICATION_KEY' , payload : vKey } )
77
79
} else if ( appState . provingScheme === 'plonk' ) {
80
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'runSetupAndExport' , 'provingScheme' , 'plonk' ] )
78
81
await snarkjs . plonk . setup ( r1cs , ptau_final , zkey_final , zkLogger ( plugin , dispatch , 'SET_SETUP_EXPORT_FEEDBACK' ) )
79
82
const vKey = await snarkjs . zKey . exportVerificationKey ( zkey_final , zkLogger ( plugin , dispatch , 'SET_SETUP_EXPORT_FEEDBACK' ) )
80
83
81
84
if ( appState . exportVerificationKey ) {
82
85
await plugin . call ( 'fileManager' , 'writeFile' , `${ extractParentFromKey ( appState . filePath ) } /plonk/zk/keys/verification_key.json` , JSON . stringify ( vKey , null , 2 ) )
86
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'runSetupAndExport' , 'zKey.exportVerificationKey' , `${ extractParentFromKey ( appState . filePath ) } /plonk/zk/keys/verification_key.json` ] )
83
87
}
84
88
if ( appState . exportVerificationContract ) {
85
89
const templates = { plonk : PLONK_VERIFIER }
86
90
const solidityContract = await snarkjs . zKey . exportSolidityVerifier ( zkey_final , templates , zkLogger ( plugin , dispatch , 'SET_SETUP_EXPORT_FEEDBACK' ) )
87
91
88
92
await plugin . call ( 'fileManager' , 'writeFile' , `${ extractParentFromKey ( appState . filePath ) } /plonk/zk/build/zk_verifier.sol` , solidityContract )
93
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'runSetupAndExport' , 'zKey.exportSolidityVerifier' , `${ extractParentFromKey ( appState . filePath ) } /plonk/zk/build/zk_verifier.sol` ] )
89
94
}
90
95
dispatch ( { type : 'SET_ZKEY' , payload : zkey_final } )
91
96
dispatch ( { type : 'SET_VERIFICATION_KEY' , payload : vKey } )
92
97
}
93
98
dispatch ( { type : 'SET_COMPILER_STATUS' , payload : 'idle' } )
94
99
dispatch ( { type : 'SET_SETUP_EXPORT_STATUS' , payload : 'done' } )
95
100
} catch ( e ) {
101
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'runSetupAndExport' , 'error' , e . message ] )
96
102
dispatch ( { type : 'SET_COMPILER_STATUS' , payload : 'errored' } )
97
103
console . error ( e )
98
104
}
@@ -124,21 +130,25 @@ export const generateProof = async (plugin: CircomPluginClient, appState: AppSta
124
130
125
131
plugin . call ( 'fileManager' , 'writeFile' , `${ extractParentFromKey ( appState . filePath ) } /groth16/zk/build/proof.json` , JSON . stringify ( proof , null , 2 ) )
126
132
plugin . call ( 'terminal' , 'log' , { type : 'log' , value : 'zk proof validity ' + verified } )
133
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'generateProof' , 'groth16.prove' , verified ] )
127
134
if ( appState . exportVerifierCalldata ) {
128
135
const calldata = await snarkjs . groth16 . exportSolidityCallData ( proof , publicSignals )
129
136
130
137
plugin . call ( 'fileManager' , 'writeFile' , `${ extractParentFromKey ( appState . filePath ) } /groth16/zk/build/verifierCalldata.json` , calldata )
138
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'generateProof' , 'groth16.exportSolidityCallData' , `${ extractParentFromKey ( appState . filePath ) } /groth16/zk/build/verifierCalldata.json` ] )
131
139
}
132
140
} else if ( appState . provingScheme === 'plonk' ) {
133
141
const { proof, publicSignals } = await snarkjs . plonk . prove ( zkey_final , wtns , zkLogger ( plugin , dispatch , 'SET_PROOF_FEEDBACK' ) )
134
142
const verified = await snarkjs . plonk . verify ( vKey , publicSignals , proof , zkLogger ( plugin , dispatch , 'SET_PROOF_FEEDBACK' ) )
135
143
136
144
plugin . call ( 'fileManager' , 'writeFile' , `${ extractParentFromKey ( appState . filePath ) } /plonk/zk/build/proof.json` , JSON . stringify ( proof , null , 2 ) )
137
145
plugin . call ( 'terminal' , 'log' , { type : 'log' , value : 'zk proof validity ' + verified } )
146
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'generateProof' , 'plonk.prove' , verified ] )
138
147
if ( appState . exportVerifierCalldata ) {
139
148
const calldata = await snarkjs . plonk . exportSolidityCallData ( proof , publicSignals )
140
149
141
150
plugin . call ( 'fileManager' , 'writeFile' , `${ extractParentFromKey ( appState . filePath ) } /plonk/zk/build/verifierCalldata.json` , calldata )
151
+ plugin . _paq . push ( [ 'trackEvent' , 'circuit-compiler' , 'generateProof' , 'plonk.exportSolidityCallData' , `${ extractParentFromKey ( appState . filePath ) } /plonk/zk/build/verifierCalldata.json` ] )
142
152
}
143
153
}
144
154
dispatch ( { type : 'SET_COMPILER_STATUS' , payload : 'idle' } )
0 commit comments