Track zk scripts execution

pull/5031/head
ioedeveloper 4 months ago committed by Aniket
parent 60beae0d19
commit ee6ecea68d
  1. 1
      .gitignore
  2. 6
      apps/remix-ide/src/app/files/fileManager.ts
  3. 1
      apps/remixdesktop/bin/circom
  4. 4
      libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_trusted_setup.ts
  5. 8
      libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts
  6. 4
      libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_trusted_setup.ts
  7. 8
      libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts
  8. 4
      libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_trusted_setup.ts
  9. 8
      libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts
  10. 4
      libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_trusted_setup.ts
  11. 8
      libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts
  12. 4
      libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_trusted_setup.ts
  13. 8
      libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts
  14. 4
      libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_trusted_setup.ts
  15. 8
      libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts

1
.gitignore vendored

@ -66,4 +66,5 @@ apps/remix-ide/src/assets/esbuild.wasm
apps/remixdesktop/build*
apps/remixdesktop/reports/
apps/remixdesktop/logs/
apps/remixdesktop/bin*
logs

@ -40,6 +40,7 @@ const errorMsg = {
const createError = (err) => {
return new Error(`${errorMsg[err.code]} ${err.message || ''}`)
}
const _paq = (window._paq = window._paq || [])
class FileManager extends Plugin {
mode: string
openedFiles: any
@ -215,6 +216,11 @@ class FileManager extends Plugin {
} else {
const ret = await this.setFileContent(path, data, options)
this.emit('fileAdded', path)
// Temporary solution to tracking scripts execution for zk in matomo
if (path === 'scripts/groth16/zk/keys/zkey_final.txt' && data) _paq.push(['trackEvent', 'circuit-compiler', 'script', 'groth16', 'zk trusted setup done'])
if (path === 'scripts/groth16/zk/build/zk_verifier.sol' && data) _paq.push(['trackEvent', 'circuit-compiler', 'script', 'groth16', 'zk proof done'])
if (path === 'scripts/plonk/zk/keys/zkey_final.txt' && data) _paq.push(['trackEvent', 'circuit-compiler', 'script', 'plonk', 'zk trusted setup done'])
if (path === 'scripts/plonk/zk/build/zk_verifier.sol' && data) _paq.push(['trackEvent', 'circuit-compiler', 'script', 'plonk', 'zk proof done'])
return ret
}
} catch (e) {

@ -0,0 +1 @@
Subproject commit 9f3da35a8ac3107190f8c85c8cf3ea1a0f8780a4

@ -39,10 +39,10 @@ const logger = {
console.log('exportVerificationKey')
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final)
await remix.call('fileManager', 'writeFile', './zk/keys/groth16/verification_key.json', JSON.stringify(vKey, null, 2))
await remix.call('fileManager', 'writeFile', 'scripts/groth16/zk/keys/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('save zkey_final')
await remix.call('fileManager', 'writeFile', './zk/keys/groth16/zkey_final.txt', JSON.stringify(Array.from(((zkey_final as any).data))))
await remix.call('fileManager', 'writeFile', 'scripts/groth16/zk/keys/zkey_final.txt', JSON.stringify(Array.from(((zkey_final as any).data))))
console.log('setup done.')

@ -24,11 +24,11 @@ const logger = {
const zkey_final = {
type: "mem",
data: new Uint8Array(JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/zkey_final.txt')))
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', './zk/keys/groth16/verification_key.json'))
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', 'scripts/groth16/zk/keys/verification_key.json'))
const value1 = '1234'
const value2 = '2'
@ -62,8 +62,8 @@ const logger = {
}
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates)
await remix.call('fileManager', 'writeFile', './zk/build/groth16/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({
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]],

@ -20,10 +20,10 @@ const snarkjs = require('snarkjs');
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final)
console.log('save zkey_final')
await remix.call('fileManager', 'writeFile', './zk/keys/plonk/zkey_final.txt', JSON.stringify(Array.from(((zkey_final as any).data))))
await remix.call('fileManager', 'writeFile', 'scripts/plonk/zk/keys/zkey_final.txt', JSON.stringify(Array.from(((zkey_final as any).data))))
console.log('save verification key')
await remix.call('fileManager', 'writeFile', './zk/keys/plonk/verification_key.json', JSON.stringify(vKey, null, 2))
await remix.call('fileManager', 'writeFile', 'scripts/plonk/zk/keys/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('setup done')
} catch (e) {

@ -20,7 +20,7 @@ const logger = {
const wasm = new Uint8Array(wasmBuffer);
const zkey_final = {
type: "mem",
data: new Uint8Array(JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/plonk/zkey_final.txt')))
data: new Uint8Array(JSON.parse(await remix.call('fileManager', 'readFile', 'scripts/plonk/zk/keys/zkey_final.txt')))
}
const wtns = { type: "mem" };
@ -44,7 +44,7 @@ const logger = {
const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns);
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/plonk/verification_key.json'))
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', 'scripts/plonk/zk/keys/verification_key.json'))
const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof);
@ -54,8 +54,8 @@ const logger = {
}
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates)
await remix.call('fileManager', 'writeFile', 'zk/build/plonk/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({
await remix.call('fileManager', 'writeFile', 'scripts/plonk/zk/build/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'scripts/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),

@ -39,10 +39,10 @@ const logger = {
console.log('exportVerificationKey')
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final)
await remix.call('fileManager', 'writeFile', './zk/keys/groth16/verification_key.json', JSON.stringify(vKey, null, 2))
await remix.call('fileManager', 'writeFile', 'scripts/groth16/zk/keys/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('save zkey_final')
await remix.call('fileManager', 'writeFile', './zk/keys/groth16/zkey_final.txt', (zkey_final as any).data, { encoding: null })
await remix.call('fileManager', 'writeFile', 'scripts/groth16/zk/keys/zkey_final.txt', (zkey_final as any).data, { encoding: null })
console.log('setup done.')

@ -55,7 +55,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified);
await remix.call('fileManager', 'writeFile', `zk/build/groth16/input-${Date.now()}.json`, JSON.stringify({
await remix.call('fileManager', 'writeFile', `scripts/groth16/zk/build/input-${Date.now()}.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]],
@ -85,11 +85,11 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
const zkey_final = {
type: "mem",
data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/groth16/zkey_final.txt', { encoding: null }))
data: new Uint8Array(await remix.call('fileManager', 'readFile', 'scripts/groth16/zk/keys/zkey_final.txt', { encoding: null }))
}
const wtns = { type: "mem" };
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/verification_key.json'))
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', 'scripts/groth16/zk/keys/verification_key.json'))
// build list of identity commitments
const secrets = []
@ -152,7 +152,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
}
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates)
await remix.call('fileManager', 'writeFile', './zk/build/groth16/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'scripts/groth16/zk/build/zk_verifier.sol', solidityContract)
} catch (e) {
console.error(e.message)
}

@ -21,10 +21,10 @@ const snarkjs = require('snarkjs');
console.log('save zkey_final')
// @ts-ignore
await remix.call('fileManager', 'writeFile', './zk/keys/plonk/zkey_final.txt', (zkey_final as any).data, { encoding: null })
await remix.call('fileManager', 'writeFile', 'scripts/plonk/zk/keys/zkey_final.txt', (zkey_final as any).data, { encoding: null })
console.log('save verification key')
await remix.call('fileManager', 'writeFile', './zk/keys/plonk/verification_key.json', JSON.stringify(vKey, null, 2))
await remix.call('fileManager', 'writeFile', 'scripts/plonk/zk/keys/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('setup done')
} catch (e) {

@ -55,7 +55,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified);
await remix.call('fileManager', 'writeFile', `zk/build/plonk/input-${Date.now()}.json`, JSON.stringify({
await remix.call('fileManager', 'writeFile', `scripts/plonk/zk/build/input-${Date.now()}.json`, JSON.stringify({
_pubSignals: publicSignals,
_proof: [
ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.A[0]).toHexString(), 32),
@ -109,11 +109,11 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
const zkey_final = {
type: "mem",
// @ts-ignore
data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/plonk/zkey_final.txt', { encoding: null }))
data: new Uint8Array(await remix.call('fileManager', 'readFile', 'scripts/plonk/zk/keys/zkey_final.txt', { encoding: null }))
}
const wtns = { type: "mem" };
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/plonk/verification_key.json'))
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', 'scripts/plonk/zk/keys/verification_key.json'))
// build list of identity commitments
const secrets = []
@ -176,7 +176,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
}
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates)
await remix.call('fileManager', 'writeFile', './zk/build/plonk/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'scripts/plonk/zk/build/zk_verifier.sol', solidityContract)
} catch (e) {
console.error(e.message)
}

@ -39,11 +39,11 @@ const logger = {
console.log('exportVerificationKey')
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final)
await remix.call('fileManager', 'writeFile', './zk/keys/groth16/verification_key.json', JSON.stringify(vKey, null, 2))
await remix.call('fileManager', 'writeFile', 'scripts/groth16/zk/keys/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('save zkey_final')
// @ts-ignore
await remix.call('fileManager', 'writeFile', './zk/keys/groth16/zkey_final.txt', (zkey_final as any).data, { encoding: null })
await remix.call('fileManager', 'writeFile', 'scripts/groth16/zk/keys/zkey_final.txt', (zkey_final as any).data, { encoding: null })
console.log('setup done.')

@ -38,11 +38,11 @@ function hash(message: any): bigint {
const zkey_final = {
type: "mem",
// @ts-ignore
data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/groth16/zkey_final.txt', { encoding: null }))
data: new Uint8Array(await remix.call('fileManager', 'readFile', 'scripts/groth16/zk/keys/zkey_final.txt', { encoding: null }))
}
const wtns = { type: "mem" };
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/verification_key.json'))
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', 'scripts/groth16/zk/keys/verification_key.json'))
// build list of identity commitments
const secrets = []
@ -101,8 +101,8 @@ function hash(message: any): bigint {
}
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates)
await remix.call('fileManager', 'writeFile', './zk/build/groth16/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({
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]],

@ -23,11 +23,11 @@ const logger = {
console.log('exportVerificationKey')
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final)
await remix.call('fileManager', 'writeFile', './zk/keys/plonk/verification_key.json', JSON.stringify(vKey, null, 2))
await remix.call('fileManager', 'writeFile', 'scripts/plonk/zk/keys/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('save zkey_final')
// @ts-ignore
await remix.call('fileManager', 'writeFile', './zk/keys/plonk/zkey_final.txt', (zkey_final as any).data, { encoding: null })
await remix.call('fileManager', 'writeFile', 'scripts/plonk/zk/keys/zkey_final.txt', (zkey_final as any).data, { encoding: null })
console.log('setup done.')

@ -38,11 +38,11 @@ function hash(message: any): bigint {
const zkey_final = {
type: "mem",
// @ts-ignore
data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/plonk/zkey_final.txt', { encoding: null }))
data: new Uint8Array(await remix.call('fileManager', 'readFile', 'scripts/plonk/zk/keys/zkey_final.txt', { encoding: null }))
}
const wtns = { type: "mem" };
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/plonk/verification_key.json'))
const vKey = JSON.parse(await remix.call('fileManager', 'readFile', 'scripts/plonk/zk/keys/verification_key.json'))
// build list of identity commitments
const secrets = []
@ -101,8 +101,8 @@ function hash(message: any): bigint {
}
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates)
await remix.call('fileManager', 'writeFile', './zk/build/plonk/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({
await remix.call('fileManager', 'writeFile', 'scripts/plonk/zk/build/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'scripts/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),

Loading…
Cancel
Save