diff --git a/.gitignore b/.gitignore index ef8b36916c..edffa95db3 100644 --- a/.gitignore +++ b/.gitignore @@ -66,4 +66,5 @@ apps/remix-ide/src/assets/esbuild.wasm apps/remixdesktop/build* apps/remixdesktop/reports/ apps/remixdesktop/logs/ +apps/remixdesktop/bin* logs diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index 229c15ce33..2ff2d5a4d3 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -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) { diff --git a/apps/remixdesktop/bin/circom b/apps/remixdesktop/bin/circom new file mode 160000 index 0000000000..9f3da35a8a --- /dev/null +++ b/apps/remixdesktop/bin/circom @@ -0,0 +1 @@ +Subproject commit 9f3da35a8ac3107190f8c85c8cf3ea1a0f8780a4 diff --git a/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_trusted_setup.ts b/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_trusted_setup.ts index 9692a62954..30f2e33dcf 100644 --- a/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_trusted_setup.ts +++ b/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_trusted_setup.ts @@ -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.') diff --git a/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts b/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts index 146bdab52b..1072ea7873 100644 --- a/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts @@ -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]], diff --git a/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_trusted_setup.ts b/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_trusted_setup.ts index 192cd2d12d..e6e919ad49 100644 --- a/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_trusted_setup.ts +++ b/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_trusted_setup.ts @@ -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) { diff --git a/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts b/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts index 544cd10b6d..3d6d7feadc 100644 --- a/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts @@ -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), diff --git a/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_trusted_setup.ts b/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_trusted_setup.ts index c4a9513c92..e972816fe4 100644 --- a/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_trusted_setup.ts +++ b/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_trusted_setup.ts @@ -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.') diff --git a/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts b/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts index d982568928..860c9dca61 100644 --- a/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts @@ -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) } diff --git a/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_trusted_setup.ts b/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_trusted_setup.ts index 8f146a1611..062bc5ef6c 100644 --- a/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_trusted_setup.ts +++ b/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_trusted_setup.ts @@ -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) { diff --git a/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts b/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts index b05c84720b..2f95cb5b82 100644 --- a/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts @@ -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) } diff --git a/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_trusted_setup.ts b/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_trusted_setup.ts index a155ef2192..4603b20dec 100644 --- a/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_trusted_setup.ts +++ b/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_trusted_setup.ts @@ -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.') diff --git a/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts b/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts index 35c708efa7..f395efe5f9 100644 --- a/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts @@ -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]], diff --git a/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_trusted_setup.ts b/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_trusted_setup.ts index c6d73a91fb..315ace426f 100644 --- a/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_trusted_setup.ts +++ b/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_trusted_setup.ts @@ -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.') diff --git a/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts b/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts index fd7f51d4a0..77b996a402 100644 --- a/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts +++ b/libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts @@ -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),