|
|
|
@ -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 }) |
|
|
|
|