|
|
@ -19,12 +19,20 @@ export const compileCircuit = async (plugin: CircomPluginClient, appState: AppSt |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const computeWitness = async (plugin: CircomPluginClient, status: string, witnessValues: Record<string, string>) => { |
|
|
|
export const computeWitness = async (plugin: CircomPluginClient, appState: AppState, dispatch: ICircuitAppContext['dispatch'], status: string, witnessValues: Record<string, string>) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (status !== "computing") { |
|
|
|
if (status !== "computing") { |
|
|
|
const input = JSON.stringify(witnessValues) |
|
|
|
const input = JSON.stringify(witnessValues) |
|
|
|
|
|
|
|
const witness = await plugin.computeWitness(input) |
|
|
|
|
|
|
|
|
|
|
|
await plugin.computeWitness(input) |
|
|
|
if (appState.exportWtnsJson) { |
|
|
|
|
|
|
|
const wtns = await snarkjs.wtns.exportJson(witness) |
|
|
|
|
|
|
|
const wtnsJson = wtns.map(wtn => wtn.toString()) |
|
|
|
|
|
|
|
const fileName = extractNameFromKey(appState.filePath) |
|
|
|
|
|
|
|
const writePath = extractParentFromKey(appState.filePath) + `/.bin/${fileName.replace('.circom', '.wtn.json')}` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await plugin.call('fileManager', 'writeFile', writePath, JSON.stringify(wtnsJson, null, 2)) |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log('Existing witness computation in progress') |
|
|
|
console.log('Existing witness computation in progress') |
|
|
|
} |
|
|
|
} |
|
|
@ -110,6 +118,7 @@ export const generateProof = async (plugin: CircomPluginClient, appState: AppSta |
|
|
|
const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK')) |
|
|
|
const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK')) |
|
|
|
const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK')) |
|
|
|
const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugin.call('fileManager', 'writeFile', `${extractParentFromKey(appState.filePath)}/groth16/zk/build/proof.json`, JSON.stringify(proof, null, 2)) |
|
|
|
plugin.call('terminal', 'log', { type: 'log', value: 'zk proof validity ' + verified }) |
|
|
|
plugin.call('terminal', 'log', { type: 'log', value: 'zk proof validity ' + verified }) |
|
|
|
if (appState.exportVerifierCalldata) { |
|
|
|
if (appState.exportVerifierCalldata) { |
|
|
|
const calldata = await snarkjs.groth16.exportSolidityCallData(proof, publicSignals) |
|
|
|
const calldata = await snarkjs.groth16.exportSolidityCallData(proof, publicSignals) |
|
|
@ -120,6 +129,7 @@ export const generateProof = async (plugin: CircomPluginClient, appState: AppSta |
|
|
|
const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK')) |
|
|
|
const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK')) |
|
|
|
const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK')) |
|
|
|
const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, zkLogger(plugin, dispatch, 'SET_PROOF_FEEDBACK')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugin.call('fileManager', 'writeFile', `${extractParentFromKey(appState.filePath)}/plonk/zk/build/proof.json`, JSON.stringify(proof, null, 2)) |
|
|
|
plugin.call('terminal', 'log', { type: 'log', value: 'zk proof validity ' + verified }) |
|
|
|
plugin.call('terminal', 'log', { type: 'log', value: 'zk proof validity ' + verified }) |
|
|
|
if (appState.exportVerifierCalldata) { |
|
|
|
if (appState.exportVerifierCalldata) { |
|
|
|
const calldata = await snarkjs.plonk.exportSolidityCallData(proof, publicSignals) |
|
|
|
const calldata = await snarkjs.plonk.exportSolidityCallData(proof, publicSignals) |
|
|
|