Skip to content

Commit 3b33986

Browse files
ioedeveloperAniket-Engg
authored andcommitted
Track setup and proof generation
1 parent 8053a01 commit 3b33986

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

apps/circuit-compiler/src/app/actions/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { CircomPluginClient } from "../services/circomPluginClient"
33
import { ActionPayloadTypes, AppState, ICircuitAppContext } from "../types"
44
import { GROTH16_VERIFIER, PLONK_VERIFIER } from './constant'
55
import { extractNameFromKey, extractParentFromKey } from '@remix-ui/helper'
6-
import { ethers } from 'ethers'
76

87
export const compileCircuit = async (plugin: CircomPluginClient, appState: AppState) => {
98
try {
@@ -60,39 +59,46 @@ export const runSetupAndExport = async (plugin: CircomPluginClient, appState: Ap
6059
const zkey_final = { type: "mem" }
6160

6261
if (appState.provingScheme === 'groth16') {
62+
plugin._paq.push(['trackEvent', 'circuit-compiler', 'runSetupAndExport', 'provingScheme', 'groth16'])
6363
await snarkjs.zKey.newZKey(r1cs, ptau_final, zkey_final, zkLogger(plugin, dispatch, 'SET_SETUP_EXPORT_FEEDBACK'))
6464
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final, zkLogger(plugin, dispatch, 'SET_SETUP_EXPORT_FEEDBACK'))
6565

6666
if (appState.exportVerificationKey) {
6767
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`])
6869
}
6970
if (appState.exportVerificationContract) {
7071
const templates = { groth16: GROTH16_VERIFIER }
7172
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates, zkLogger(plugin, dispatch, 'SET_SETUP_EXPORT_FEEDBACK'))
7273

7374
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`])
7476
}
7577
dispatch({ type: 'SET_ZKEY', payload: zkey_final })
7678
dispatch({ type: 'SET_VERIFICATION_KEY', payload: vKey })
7779
} else if (appState.provingScheme === 'plonk') {
80+
plugin._paq.push(['trackEvent', 'circuit-compiler', 'runSetupAndExport', 'provingScheme', 'plonk'])
7881
await snarkjs.plonk.setup(r1cs, ptau_final, zkey_final, zkLogger(plugin, dispatch, 'SET_SETUP_EXPORT_FEEDBACK'))
7982
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final, zkLogger(plugin, dispatch, 'SET_SETUP_EXPORT_FEEDBACK'))
8083

8184
if (appState.exportVerificationKey) {
8285
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`])
8387
}
8488
if (appState.exportVerificationContract) {
8589
const templates = { plonk: PLONK_VERIFIER }
8690
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates, zkLogger(plugin, dispatch, 'SET_SETUP_EXPORT_FEEDBACK'))
8791

8892
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`])
8994
}
9095
dispatch({ type: 'SET_ZKEY', payload: zkey_final })
9196
dispatch({ type: 'SET_VERIFICATION_KEY', payload: vKey })
9297
}
9398
dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })
9499
dispatch({ type: 'SET_SETUP_EXPORT_STATUS', payload: 'done' })
95100
} catch (e) {
101+
plugin._paq.push(['trackEvent', 'circuit-compiler', 'runSetupAndExport', 'error', e.message])
96102
dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' })
97103
console.error(e)
98104
}
@@ -124,21 +130,25 @@ export const generateProof = async (plugin: CircomPluginClient, appState: AppSta
124130

125131
plugin.call('fileManager', 'writeFile', `${extractParentFromKey(appState.filePath)}/groth16/zk/build/proof.json`, JSON.stringify(proof, null, 2))
126132
plugin.call('terminal', 'log', { type: 'log', value: 'zk proof validity ' + verified })
133+
plugin._paq.push(['trackEvent', 'circuit-compiler', 'generateProof', 'groth16.prove', verified])
127134
if (appState.exportVerifierCalldata) {
128135
const calldata = await snarkjs.groth16.exportSolidityCallData(proof, publicSignals)
129136

130137
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`])
131139
}
132140
} else if (appState.provingScheme === 'plonk') {
133141
const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK'))
134142
const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK'))
135143

136144
plugin.call('fileManager', 'writeFile', `${extractParentFromKey(appState.filePath)}/plonk/zk/build/proof.json`, JSON.stringify(proof, null, 2))
137145
plugin.call('terminal', 'log', { type: 'log', value: 'zk proof validity ' + verified })
146+
plugin._paq.push(['trackEvent', 'circuit-compiler', 'generateProof', 'plonk.prove', verified])
138147
if (appState.exportVerifierCalldata) {
139148
const calldata = await snarkjs.plonk.exportSolidityCallData(proof, publicSignals)
140149

141150
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`])
142152
}
143153
}
144154
dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })

apps/circuit-compiler/src/app/services/circomPluginClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class CircomPluginClient extends PluginClient {
2020
private lastParsedFiles: Record<string, string> = {}
2121
private lastCompiledFile: string = ''
2222
private compiler: typeof compilerV215 & typeof compilerV216 & typeof compilerV217 & typeof compilerV218
23-
private _paq = {
23+
public _paq = {
2424
push: (args) => {
2525
this.call('matomo' as any, 'track', args)
2626
}

0 commit comments

Comments
 (0)