simple setup

pull/5057/head
ioedeveloper 4 months ago committed by Aniket
parent 8886c10649
commit 862cf1645a
  1. 64
      apps/circuit-compiler/src/app/actions/index.ts
  2. 11
      apps/circuit-compiler/src/app/components/container.tsx
  3. 37
      apps/circuit-compiler/src/app/components/generateProof.tsx
  4. 7
      apps/circuit-compiler/src/app/reducers/state.ts
  5. 4
      apps/circuit-compiler/src/app/types/index.ts
  6. 1
      apps/remix-ide/src/app/tabs/locales/en/circuit.json

@ -76,3 +76,67 @@ export const runSetupAndExport = async (plugin: CircomPluginClient, appState: Ap
} }
} }
} }
export const generateProof = async (plugin: CircomPluginClient, appState: AppState) => {
// try {
// // @ts-ignore
// const r1csBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/calculate_hash.r1cs', { encoding: null });
// // @ts-ignore
// const r1cs = new Uint8Array(r1csBuffer);
// // @ts-ignore
// await remix.call('circuit-compiler', 'compile', 'circuits/calculate_hash.circom');
// // @ts-ignore
// const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/calculate_hash.wasm', { encoding: null });
// // @ts-ignore
// const wasm = new Uint8Array(wasmBuffer);
// const zkey_final = {
// type: "mem",
// data: new Uint8Array(JSON.parse(await remix.call('fileManager', 'readFile', 'scripts/groth16/zk/keys/zkey_final.txt')))
// }
// const wtns = { type: "mem" };
// const vKey = JSON.parse(await remix.call('fileManager', 'readFile', 'scripts/groth16/zk/keys/verification_key.json'))
// const value1 = '1234'
// const value2 = '2'
// const value3 = '3'
// const value4 = '4'
// const wrongValue = '5' // put this in the poseidon hash calculation to simulate a non matching hash.
// const signals = {
// value1,
// value2,
// value3,
// value4,
// hash: poseidon([value1, value2, value3, value4])
// }
// console.log('calculate')
// await snarkjs.wtns.calculate(signals, wasm, wtns);
// console.log('check')
// await snarkjs.wtns.check(r1cs, wtns, logger);
// console.log('prove')
// const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns);
// const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger);
// console.log('zk proof validity', verified);
// const templates = {
// groth16: await remix.call('fileManager', 'readFile', 'templates/groth16_verifier.sol.ejs')
// }
// const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates)
// await remix.call('fileManager', 'writeFile', 'scripts/groth16/zk/build/zk_verifier.sol', solidityContract)
// await remix.call('fileManager', 'writeFile', 'scripts/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))
// } catch (e) {
// }
}

@ -11,6 +11,7 @@ import { WitnessSection } from './witness'
import { CompilerFeedback } from './feedback' import { CompilerFeedback } from './feedback'
import { CompilerReport, PrimeValue } from '../types' import { CompilerReport, PrimeValue } from '../types'
import { SetupExports } from './setupExports' import { SetupExports } from './setupExports'
import { GenerateProof } from './generateProof'
export function Container () { export function Container () {
const circuitApp = useContext(CircuitAppContext) const circuitApp = useContext(CircuitAppContext)
@ -146,6 +147,16 @@ export function Container () {
</> </>
</Toggler> </Toggler>
</RenderIf> </RenderIf>
<RenderIf condition={circuitApp.appState.signalInputs.length > 0}>
<Toggler title='circuit.generateProof' dataId='generate_proof_toggler' show={!!circuitApp.appState.setupExportStatus}>
<>
<GenerateProof />
<RenderIf condition={circuitApp.appState.status !== 'proving'}>
<CompilerFeedback feedback={circuitApp.appState.proofFeedback} filePathToId={circuitApp.appState.filePathToId} openErrorLocation={handleOpenErrorLocation} hideWarnings={circuitApp.appState.hideWarnings} askGPT={askGPT} />
</RenderIf>
</>
</Toggler>
</RenderIf>
</div> </div>
</div> </div>
</article> </article>

@ -0,0 +1,37 @@
import { RenderIf } from "@remix-ui/helper"
import { FormattedMessage } from "react-intl"
import { generateProof } from "../actions"
import { CircuitAppContext } from "../contexts"
import { useContext } from "react"
export function GenerateProof () {
const circuitApp = useContext(CircuitAppContext)
const status = circuitApp.appState.status
const handleGenerateProof = async () => {
try {
circuitApp.dispatch({ type: 'SET_COMPILER_STATUS', payload: 'proving' })
await generateProof(circuitApp.plugin, circuitApp.appState)
circuitApp.dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })
} catch (e) {
circuitApp.dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' })
console.error(e)
}
}
return (
<div className="flex-column d-flex">
<button
className="btn btn-secondary btn-block d-block w-100 text-break mb-1 mt-1"
onClick={handleGenerateProof}
disabled={(status === "compiling") || (status === "computing") || (status === "proving") || (status === "exporting")}
data-id="compute_witness_btn"
>
<RenderIf condition={status === 'computing'}>
<i className="fas fa-sync fa-spin mr-2" aria-hidden="true"></i>
</RenderIf>
<FormattedMessage id="circuit.generateProof" />
</button>
</div>
)
}

@ -14,6 +14,7 @@ export const appInitialState: AppState = {
signalInputs: [], signalInputs: [],
compilerFeedback: null, compilerFeedback: null,
computeFeedback: null, computeFeedback: null,
proofFeedback: null,
setupExportFeedback: null, setupExportFeedback: null,
setupExportStatus: null, setupExportStatus: null,
provingScheme: 'groth16', provingScheme: 'groth16',
@ -86,6 +87,12 @@ export const appReducer = (state = appInitialState, action: Actions): AppState =
setupExportFeedback: action.payload setupExportFeedback: action.payload
} }
case 'SET_PROOF_FEEDBACK':
return {
...state,
proofFeedback: action.payload
}
case 'SET_FILE_PATH_TO_ID': case 'SET_FILE_PATH_TO_ID':
return { return {
...state, ...state,

@ -2,7 +2,7 @@ import { compiler_list } from 'circom_wasm'
import { Dispatch } from 'react' import { Dispatch } from 'react'
import type { CircomPluginClient } from '../services/circomPluginClient' import type { CircomPluginClient } from '../services/circomPluginClient'
export type CompilerStatus = "compiling" | "computing" | "idle" | "errored" | "warning" | "exporting" export type CompilerStatus = "compiling" | "computing" | "idle" | "errored" | "warning" | "exporting" | "proving"
export type ProvingScheme = 'groth16' | 'plonk' export type ProvingScheme = 'groth16' | 'plonk'
@ -31,6 +31,7 @@ export interface ActionPayloadTypes {
SET_SIGNAL_INPUTS: string[], SET_SIGNAL_INPUTS: string[],
SET_COMPILER_FEEDBACK: string | CompilerReport[], SET_COMPILER_FEEDBACK: string | CompilerReport[],
SET_COMPUTE_FEEDBACK: string | CompilerReport[], SET_COMPUTE_FEEDBACK: string | CompilerReport[],
SET_PROOF_FEEDBACK: string | CompilerReport[],
SET_SETUP_EXPORT_FEEDBACK: string | CompilerReport[], SET_SETUP_EXPORT_FEEDBACK: string | CompilerReport[],
SET_FILE_PATH_TO_ID: Record<number, string>, SET_FILE_PATH_TO_ID: Record<number, string>,
SET_PROVING_SCHEME: ProvingScheme, SET_PROVING_SCHEME: ProvingScheme,
@ -58,6 +59,7 @@ export interface AppState {
signalInputs: string[], signalInputs: string[],
compilerFeedback: string | CompilerReport[], compilerFeedback: string | CompilerReport[],
computeFeedback: string | CompilerReport[], computeFeedback: string | CompilerReport[],
proofFeedback: string | CompilerReport[],
setupExportFeedback: string | CompilerReport[], setupExportFeedback: string | CompilerReport[],
setupExportStatus: SetupExportStatus, setupExportStatus: SetupExportStatus,
provingScheme: ProvingScheme, provingScheme: ProvingScheme,

@ -10,6 +10,7 @@
"circuit.noFileSelected": "no file selected", "circuit.noFileSelected": "no file selected",
"circuit.generateR1cs": "Generate R1CS", "circuit.generateR1cs": "Generate R1CS",
"circuit.computeWitness": "Compute Witness", "circuit.computeWitness": "Compute Witness",
"circuit.generateProof": "Generate Proof",
"circuit.signalInput": "Signal Input", "circuit.signalInput": "Signal Input",
"circuit.compute": "Compute", "circuit.compute": "Compute",
"circuit.setupExports": "Setup and Exports", "circuit.setupExports": "Setup and Exports",

Loading…
Cancel
Save