Export verifier calldata

pull/5057/head
ioedeveloper 3 months ago committed by Aniket
parent 4e0c5c5a9e
commit adce227503
  1. 49
      apps/circuit-compiler/src/app/actions/index.ts
  2. 13
      apps/circuit-compiler/src/app/components/generateProof.tsx
  3. 7
      apps/circuit-compiler/src/app/reducers/state.ts
  4. 2
      apps/circuit-compiler/src/app/types/index.ts
  5. 1
      apps/remix-ide/src/app/tabs/locales/en/circuit.json

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

@ -10,6 +10,19 @@ export function GenerateProof () {
return (
<div className="flex-column d-flex">
<div className="mt-2 custom-control custom-checkbox">
<input
className="custom-control-input"
type="checkbox"
title="Export Verifier Calldata"
id="circuitExportVerifierCalldata"
onChange={() => circuitApp.dispatch({ type: 'SET_EXPORT_VERIFIER_CALLDATA', payload: !circuitApp.appState.exportVerifierCalldata })}
checked={circuitApp.appState.exportVerifierCalldata}
/>
<label className="form-check-label custom-control-label pt-1" htmlFor="circuitExportVerifierCalldata">
<FormattedMessage id="circuit.exportVerifierCalldata" />
</label>
</div>
<button
className="btn btn-secondary btn-block d-block w-100 text-break mb-1 mt-1"
onClick={() => generateProof(circuitApp.plugin, circuitApp.appState, circuitApp.dispatch)}

@ -22,6 +22,7 @@ export const appInitialState: AppState = {
ptauValue: "final_14.ptau",
exportVerificationContract: true,
exportVerificationKey: true,
exportVerifierCalldata: true,
verificationKey: null,
zKey: null
}
@ -125,6 +126,12 @@ export const appReducer = (state = appInitialState, action: Actions): AppState =
exportVerificationKey: action.payload
}
case 'SET_EXPORT_VERIFIER_CALLDATA':
return {
...state,
exportVerifierCalldata: action.payload
}
case 'SET_SETUP_EXPORT_STATUS':
return {
...state,

@ -38,6 +38,7 @@ export interface ActionPayloadTypes {
SET_PTAU_VALUE: string,
SET_EXPORT_VERIFICATION_CONTRACT: boolean,
SET_EXPORT_VERIFICATION_KEY: boolean,
SET_EXPORT_VERIFIER_CALLDATA: boolean,
SET_SETUP_EXPORT_STATUS: SetupExportStatus,
SET_VERIFICATION_KEY: Record<string, any>,
SET_ZKEY: any
@ -69,6 +70,7 @@ export interface AppState {
ptauValue: string,
exportVerificationContract: boolean,
exportVerificationKey: boolean,
exportVerifierCalldata: boolean,
verificationKey: Record<string, any>,
zKey: Uint8Array
}

@ -20,5 +20,6 @@
"circuit.randomBeacon": "Ceremony: Random Beacon",
"circuit.exportVerifierContract": "Export verifier contract",
"circuit.exportVerificationKey": "Export verification key",
"circuit.exportVerifierCalldata": "Export verifier calldata",
"circuit.runSetup": "Run setup"
}

Loading…
Cancel
Save