Add basic proof/compile scripts.

pull/4512/head
Evan Sangaline 9 months ago committed by Aniket
parent c28985eeb7
commit cd69ee7cd1
  1. 10
      libs/remix-ws-templates/src/script-templates/sindri/index.ts
  2. 7
      libs/remix-ws-templates/src/script-templates/sindri/run_compile.ts
  3. 15
      libs/remix-ws-templates/src/script-templates/sindri/run_prove.ts
  4. 37
      libs/remix-ws-templates/src/script-templates/sindri/utils.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.

@ -0,0 +1,7 @@
import {compile} from './utils'
const main = async () => {
const circuit = await compile()
}
main()

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

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

Loading…
Cancel
Save