From 783c828d1b6023d7cb561296874607277913f6f3 Mon Sep 17 00:00:00 2001 From: Evan Sangaline Date: Sun, 11 Feb 2024 13:23:46 -0600 Subject: [PATCH] Add basic proof/compile scripts. --- .../src/script-templates/sindri/index.ts | 10 +++++ .../script-templates/sindri/run_compile.ts | 7 ++++ .../src/script-templates/sindri/run_prove.ts | 15 ++++++++ .../src/script-templates/sindri/utils.ts | 37 ++++++++++++++----- 4 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 libs/remix-ws-templates/src/script-templates/sindri/run_compile.ts create mode 100644 libs/remix-ws-templates/src/script-templates/sindri/run_prove.ts diff --git a/libs/remix-ws-templates/src/script-templates/sindri/index.ts b/libs/remix-ws-templates/src/script-templates/sindri/index.ts index f4c2073f29..e26f495589 100644 --- a/libs/remix-ws-templates/src/script-templates/sindri/index.ts +++ b/libs/remix-ws-templates/src/script-templates/sindri/index.ts @@ -4,6 +4,16 @@ export const sindriScripts = async (plugin) => { // @ts-ignore (await import('!!raw-loader!./utils.ts')).default) + await plugin.call('fileManager', 'writeFile', + 'scripts/sindri/run_compile.ts' , + // @ts-ignore + (await import('!!raw-loader!./run_compile.ts')).default) + + await plugin.call('fileManager', 'writeFile', + 'scripts/sindri/run_prove.ts' , + // @ts-ignore + (await import('!!raw-loader!./run_prove.ts')).default) + const existingFiles = await plugin.call('fileManager', 'readdir', '') // Only write out the `.sindriignore` file if it doesn't already exist. diff --git a/libs/remix-ws-templates/src/script-templates/sindri/run_compile.ts b/libs/remix-ws-templates/src/script-templates/sindri/run_compile.ts new file mode 100644 index 0000000000..40a2bb42ad --- /dev/null +++ b/libs/remix-ws-templates/src/script-templates/sindri/run_compile.ts @@ -0,0 +1,7 @@ +import {compile} from './utils' + +const main = async () => { + const circuit = await compile() +} + +main() diff --git a/libs/remix-ws-templates/src/script-templates/sindri/run_prove.ts b/libs/remix-ws-templates/src/script-templates/sindri/run_prove.ts new file mode 100644 index 0000000000..98e2ea43d7 --- /dev/null +++ b/libs/remix-ws-templates/src/script-templates/sindri/run_prove.ts @@ -0,0 +1,15 @@ +import {prove} from './utils' + +// You must modify the input signals to include the data you're trying to generate a proof for. +const signals: {[name: string]: number | string} = {} + +const main = async () => { + if (Object.keys(signals).length === 0) { + console.error("You must modify the input signals to include the data you're trying to generate a proof for.") + return + } + const proofResponse = await prove(signals) + console.log('Proof:\n', JSON.stringify(proofResponse.proof, null, 2)) +} + +main() diff --git a/libs/remix-ws-templates/src/script-templates/sindri/utils.ts b/libs/remix-ws-templates/src/script-templates/sindri/utils.ts index 33383ca5e5..642582e651 100644 --- a/libs/remix-ws-templates/src/script-templates/sindri/utils.ts +++ b/libs/remix-ws-templates/src/script-templates/sindri/utils.ts @@ -68,11 +68,15 @@ export const compile = async (tags: string | string[] | null = ['latest']): Circ }) } - console.log(`creating circuit "${sindriManifest.name}"...`) + console.log(`Compiling circuit "${sindriManifest.name}"...`) const files = Object.values(filesByPath) - const circuitProject = await sindriClient.createCircuit(files, tags) - console.log(`circuit created ${circuitProject.circuit_id}`) - return circuitProject + const circuitResponse = await sindriClient.createCircuit(files, tags) + if (circuitResponse.status === 'Ready') { + console.log(`Circuit compiled successfully, circuit id: ${circuitResponse.circuit_id}`) + } else { + console.error('Circuit compilation failed:', circuitResponse.error || 'Unknown error') + } + return circuitResponse } /** @@ -81,13 +85,28 @@ export const compile = async (tags: string | string[] | null = ['latest']): Circ * @param {Object} signals - Input signals for the circuit. * @returns {ProofInfoResponse} The generated proof. */ -export const proveCircuit = async (signals: {[id: string]: string}): ProofInfoResponse => { +export const prove = async (signals: {[id: string]: number | string}): ProofInfoResponse => { authorize() const sindriManifest = await getSindriManifest() const circuitName = sindriManifest.name - console.log(`proving circuit "${circuitName}"...`) - const proof = await sindriClient.proveCircuit(circuitName, JSON.stringify(signals)) - console.log(`proof id: ${proof.proof_id}`) - return proof + console.log(`Proving circuit "${circuitName}"...`) + try { + const proofResponse = await sindriClient.proveCircuit(circuitName, JSON.stringify(signals)) + if (proofResponse.status === 'Ready') { + console.log(`Proof generated successfully, proof id: ${proofResponse.proof_id}`) + } else { + console.error('Proof generation failed:', proofResponse.error || 'Unknown error') + } + return proofResponse + } catch (error) { + if ('status' in error && error.status === 404) { + const message = `No compiled circuit "${circuitName}" found, have you successfully compiled the circuit?` + console.error(message) + throw new Error(message) + } else { + console.error('Unknown error occurred.') + throw error + } + } }