From adce22750339eac652b7a7f7f83cede8ff3efb7b Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Mon, 12 Aug 2024 17:10:44 +0100 Subject: [PATCH] Export verifier calldata --- .../circuit-compiler/src/app/actions/index.ts | 49 +++++-------------- .../src/app/components/generateProof.tsx | 13 +++++ .../src/app/reducers/state.ts | 7 +++ apps/circuit-compiler/src/app/types/index.ts | 2 + .../src/app/tabs/locales/en/circuit.json | 1 + 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/apps/circuit-compiler/src/app/actions/index.ts b/apps/circuit-compiler/src/app/actions/index.ts index 2bde44a559..9c0197fe18 100644 --- a/apps/circuit-compiler/src/app/actions/index.ts +++ b/apps/circuit-compiler/src/app/actions/index.ts @@ -112,47 +112,22 @@ export const generateProof = async (plugin: CircomPluginClient, appState: AppSta const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns, zkLogger(plugin)) const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, zkLogger(plugin)) - console.log('zk proof validity', verified) - await plugin.call('fileManager', 'writeFile', `${extractParentFromKey(appState.filePath)}/groth16/zk/build/input.json`, JSON.stringify({ - _pA: [proof.pi_a[0], proof.pi_a[1]], - _pB: [[proof.pi_b[0][1], proof.pi_b[0][0]], [proof.pi_b[1][1], proof.pi_b[1][0]]], - _pC: [proof.pi_c[0], proof.pi_c[1]], - _pubSignals: publicSignals, - }, null, 2)) + plugin.call('terminal', 'log', { type: 'log', value: 'zk proof validity ' + verified }) + if (appState.exportVerifierCalldata) { + const calldata = await snarkjs.groth16.exportSolidityCallData(proof, publicSignals) + + plugin.call('fileManager', 'writeFile', `${extractParentFromKey(appState.filePath)}/groth16/zk/build/verifierCalldata.json`, calldata) + } } else if (appState.provingScheme === 'plonk') { const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns, zkLogger(plugin)) const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, zkLogger(plugin)) - console.log('zk proof validity', verified) - await plugin.call('fileManager', 'writeFile', `${extractParentFromKey(appState.filePath)}/plonk/zk/build/input.json`, JSON.stringify({ - _proof: [ - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[0]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[1]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.B[0]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.B[1]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.C[0]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.C[1]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.Z[0]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.Z[1]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.T1[0]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.T1[1]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.T2[0]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.T2[1]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.T3[0]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.T3[1]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.Wxi[0]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.Wxi[1]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.Wxiw[0]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.Wxiw[1]).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_a).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_b).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_c).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_s1).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_s2).toHexString(), 32), - ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_zw).toHexString(), 32), - ], - _pubSignals: publicSignals - }, null, 2)) + plugin.call('terminal', 'log', { type: 'log', value: 'zk proof validity ' + verified }) + if (appState.exportVerifierCalldata) { + const calldata = await snarkjs.plonk.exportSolidityCallData(proof, publicSignals) + + plugin.call('fileManager', 'writeFile', `${extractParentFromKey(appState.filePath)}/plonk/zk/build/verifierCalldata.json`, calldata) + } } dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) dispatch({ type: 'SET_PROOF_FEEDBACK', payload: null }) diff --git a/apps/circuit-compiler/src/app/components/generateProof.tsx b/apps/circuit-compiler/src/app/components/generateProof.tsx index 9235813e45..84f3a018f0 100644 --- a/apps/circuit-compiler/src/app/components/generateProof.tsx +++ b/apps/circuit-compiler/src/app/components/generateProof.tsx @@ -10,6 +10,19 @@ export function GenerateProof () { return (
+
+ circuitApp.dispatch({ type: 'SET_EXPORT_VERIFIER_CALLDATA', payload: !circuitApp.appState.exportVerifierCalldata })} + checked={circuitApp.appState.exportVerifierCalldata} + /> + +