From 811d90ae3660ea8cbbf940df32536b8e910a4921 Mon Sep 17 00:00:00 2001 From: lianahus Date: Mon, 29 Apr 2024 13:50:10 +0200 Subject: [PATCH] linting fixes for remix-ws-templates --- .../basic-contract-deploy.ts | 6 ++-- .../contract-deployer/index.ts | 6 ++-- .../create2-solidity-factory/index.ts | 2 +- .../src/script-templates/etherscan/index.ts | 6 ++-- .../etherscan/receiptGuidScript.ts | 2 +- .../etherscan/verifyScript.ts | 2 +- .../src/script-templates/sindri/index.ts | 4 +-- .../script-templates/sindri/run_compile.ts | 2 +- .../src/script-templates/sindri/run_prove.ts | 2 +- .../src/script-templates/sindri/utils.ts | 4 +-- .../gnosisSafeMultisig/scripts/ethers-lib.ts | 6 ++-- .../gnosisSafeMultisig/scripts/web3-lib.ts | 4 +-- .../scripts/groth16/groth16_trusted_setup.ts | 6 ++-- .../scripts/groth16/groth16_zkproof.ts | 21 ++++++------- .../scripts/plonk/plonk_zkproof.ts | 12 +++---- .../src/templates/ozerc1155/index.ts | 2 +- .../templates/ozerc1155/scripts/ethers-lib.ts | 6 ++-- .../templates/ozerc1155/scripts/web3-lib.ts | 4 +-- .../src/templates/ozerc20/index.ts | 2 +- .../templates/ozerc20/scripts/ethers-lib.ts | 6 ++-- .../src/templates/ozerc20/scripts/web3-lib.ts | 4 +-- .../templates/ozerc721/scripts/ethers-lib.ts | 6 ++-- .../templates/ozerc721/scripts/web3-lib.ts | 4 +-- .../playground/scripts/ethers-lib.ts | 6 ++-- .../templates/playground/scripts/web3-lib.ts | 4 +-- .../remixDefault/scripts/ethers-lib.ts | 6 ++-- .../remixDefault/scripts/web3-lib.ts | 4 +-- .../scripts/groth16/groth16_trusted_setup.ts | 6 ++-- .../rln/scripts/groth16/groth16_zkproof.ts | 28 ++++++++--------- .../rln/scripts/plonk/plonk_zkproof.ts | 28 ++++++++--------- .../scripts/groth16/groth16_trusted_setup.ts | 6 ++-- .../scripts/groth16/groth16_zkproof.ts | 28 ++++++++--------- .../scripts/plonk/plonk_trusted_setup.ts | 6 ++-- .../semaphore/scripts/plonk/plonk_zkproof.ts | 30 +++++++++--------- .../templates/semaphore/scripts/run_setup.ts | 10 +++--- .../semaphore/scripts/run_verification.ts | 31 +++++++++---------- .../zeroxErc20/scripts/ethers-lib.ts | 6 ++-- .../templates/zeroxErc20/scripts/web3-lib.ts | 4 +-- 38 files changed, 159 insertions(+), 163 deletions(-) diff --git a/libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts b/libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts index 2753f9bcd0..8e4adf95a6 100644 --- a/libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts +++ b/libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts @@ -7,7 +7,7 @@ import { ethers } from 'ethers' * @param {Number} accountIndex account index from the exposed account * @return {Contract} deployed contract */ -export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { +export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { console.log(`deploying ${contractName}`) // Note that the script needs the ABI which is generated from the compilation artifact. @@ -16,12 +16,12 @@ export const deploy = async (contractName: string, args: Array, accountInde const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) // 'web3Provider' is a remix global variable object - + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) - const contract = await factory.deploy(...args) + const contract = await factory.deploy(...args) // The contract is NOT deployed yet; we must wait until it is mined await contract.deployed() diff --git a/libs/remix-ws-templates/src/script-templates/contract-deployer/index.ts b/libs/remix-ws-templates/src/script-templates/contract-deployer/index.ts index 93682c8002..5ef8cb395b 100644 --- a/libs/remix-ws-templates/src/script-templates/contract-deployer/index.ts +++ b/libs/remix-ws-templates/src/script-templates/contract-deployer/index.ts @@ -1,12 +1,12 @@ export const contractDeployerScripts = async (plugin) => { - await plugin.call('fileManager', 'writeFile', + await plugin.call('fileManager', 'writeFile', 'scripts/contract-deployer/create2-factory-deploy.ts' , // @ts-ignore (await import('!!raw-loader!./create2-factory-deploy.ts')).default) await plugin.call('fileManager', 'open', 'scripts/contract-deployer/create2-factory-deploy.ts') - - await plugin.call('fileManager', 'writeFile', + + await plugin.call('fileManager', 'writeFile', 'scripts/contract-deployer/basic-contract-deploy.ts' , // @ts-ignore (await import('!!raw-loader!./basic-contract-deploy.ts')).default) diff --git a/libs/remix-ws-templates/src/script-templates/create2-solidity-factory/index.ts b/libs/remix-ws-templates/src/script-templates/create2-solidity-factory/index.ts index 4d7bedb2d8..80283660a2 100644 --- a/libs/remix-ws-templates/src/script-templates/create2-solidity-factory/index.ts +++ b/libs/remix-ws-templates/src/script-templates/create2-solidity-factory/index.ts @@ -1,5 +1,5 @@ export const contractCreate2Factory = async (plugin) => { - await plugin.call('fileManager', 'writeFile', + await plugin.call('fileManager', 'writeFile', 'contracts/libs/create2-factory.sol' , // @ts-ignore (await import('!!raw-loader!./create2-factory.sol')).default) diff --git a/libs/remix-ws-templates/src/script-templates/etherscan/index.ts b/libs/remix-ws-templates/src/script-templates/etherscan/index.ts index 3abbe27dd6..747e4fd8b8 100644 --- a/libs/remix-ws-templates/src/script-templates/etherscan/index.ts +++ b/libs/remix-ws-templates/src/script-templates/etherscan/index.ts @@ -1,12 +1,12 @@ export const etherscanScripts = async (plugin) => { - await plugin.call('fileManager', 'writeFile', + await plugin.call('fileManager', 'writeFile', 'scripts/etherscan/verifyScript.ts' , // @ts-ignore (await import('!!raw-loader!./verifyScript.ts')).default) - + await plugin.call('fileManager', 'open', 'scripts/etherscan/verifyScript.ts') - await plugin.call('fileManager', 'writeFile', + await plugin.call('fileManager', 'writeFile', 'scripts/etherscan/receiptGuidScript.ts' , // @ts-ignore (await import('!!raw-loader!./receiptGuidScript.ts')).default) diff --git a/libs/remix-ws-templates/src/script-templates/etherscan/receiptGuidScript.ts b/libs/remix-ws-templates/src/script-templates/etherscan/receiptGuidScript.ts index cc96dc14e6..b5bdeb3139 100644 --- a/libs/remix-ws-templates/src/script-templates/etherscan/receiptGuidScript.ts +++ b/libs/remix-ws-templates/src/script-templates/etherscan/receiptGuidScript.ts @@ -5,5 +5,5 @@ * @returns {{ status, message, succeed }} receiptStatus */ export const receiptStatus = async (apikey: string, guid: string, isProxyContract?: boolean) => { - return await remix.call('etherscan' as any, 'receiptStatus', guid, apikey, isProxyContract) + return await remix.call('etherscan' as any, 'receiptStatus', guid, apikey, isProxyContract) } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/script-templates/etherscan/verifyScript.ts b/libs/remix-ws-templates/src/script-templates/etherscan/verifyScript.ts index 2126bca90b..ba9c552a70 100644 --- a/libs/remix-ws-templates/src/script-templates/etherscan/verifyScript.ts +++ b/libs/remix-ws-templates/src/script-templates/etherscan/verifyScript.ts @@ -13,5 +13,5 @@ export const verify = async (apikey: string, contractAddress: string, contractAr const compilationResultParam = await remix.call('compilerArtefacts' as any, 'getCompilerAbstract', contractFile) console.log('verifying.. ' + contractName) // update apiKey and chainRef to verify contract on multiple networks - return await remix.call('etherscan' as any, 'verify', apikey, contractAddress, contractArguments, contractName, compilationResultParam, chainRef, isProxyContract, expectedImplAddress) + return await remix.call('etherscan' as any, 'verify', apikey, contractAddress, contractArguments, contractName, compilationResultParam, chainRef, isProxyContract, expectedImplAddress) } 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 fdc58bfad1..0abcebdb2e 100644 --- a/libs/remix-ws-templates/src/script-templates/sindri/index.ts +++ b/libs/remix-ws-templates/src/script-templates/sindri/index.ts @@ -71,12 +71,12 @@ export const sindriScripts = async (plugin: any) => { if (a.isTemplateEntrypoint !== b.isTemplateEntrypoint) return +b.isTemplateEntrypoint - +a.isTemplateEntrypoint return a.path.localeCompare(b.path) }) - .map(({path}) => path)[0] || './circuit.circom' + .map(({ path }) => path)[0] || './circuit.circom' sindriManifest.circuitPath = circomCircuitPath } // Derive the circuit name from the workspace name. - const {name: workspaceName} = await plugin.call('filePanel', 'getCurrentWorkspace') + const { name: workspaceName } = await plugin.call('filePanel', 'getCurrentWorkspace') sindriManifest.name = workspaceName .replace(/\s*-+\s*\d*$/, '') 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 index 40a2bb42ad..5d9acda605 100644 --- a/libs/remix-ws-templates/src/script-templates/sindri/run_compile.ts +++ b/libs/remix-ws-templates/src/script-templates/sindri/run_compile.ts @@ -1,4 +1,4 @@ -import {compile} from './utils' +import { compile } from './utils' const main = async () => { const circuit = await compile() 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 index 98e2ea43d7..cd81dbde15 100644 --- a/libs/remix-ws-templates/src/script-templates/sindri/run_prove.ts +++ b/libs/remix-ws-templates/src/script-templates/sindri/run_prove.ts @@ -1,4 +1,4 @@ -import {prove} from './utils' +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} = {} 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 8905d037da..006cd9fa6c 100644 --- a/libs/remix-ws-templates/src/script-templates/sindri/utils.ts +++ b/libs/remix-ws-templates/src/script-templates/sindri/utils.ts @@ -1,5 +1,5 @@ import sindriClient from 'sindri' -import type {CircuitInfoResponse, ProofInfoResponse} from 'sindri' +import type { CircuitInfoResponse, ProofInfoResponse } from 'sindri' sindriClient.logLevel = 'info' @@ -9,7 +9,7 @@ const authorize = async () => { if (!apiKey) { throw new Error('Missing API key.') } - sindriClient.authorize({apiKey}) + sindriClient.authorize({ apiKey }) } catch { const message = 'No Sindri API key found. Please click the gear in the lower left corner to open the settings page, and add your API key under "Sindri Credentials".' await remix.call('notification', 'toast', message) diff --git a/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/ethers-lib.ts index 2753f9bcd0..8e4adf95a6 100644 --- a/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/ethers-lib.ts @@ -7,7 +7,7 @@ import { ethers } from 'ethers' * @param {Number} accountIndex account index from the exposed account * @return {Contract} deployed contract */ -export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { +export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { console.log(`deploying ${contractName}`) // Note that the script needs the ABI which is generated from the compilation artifact. @@ -16,12 +16,12 @@ export const deploy = async (contractName: string, args: Array, accountInde const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) // 'web3Provider' is a remix global variable object - + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) - const contract = await factory.deploy(...args) + const contract = await factory.deploy(...args) // The contract is NOT deployed yet; we must wait until it is mined await contract.deployed() diff --git a/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/web3-lib.ts b/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/web3-lib.ts index c57e501039..cbd4f48489 100644 --- a/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/web3-lib.ts +++ b/libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/web3-lib.ts @@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array, from?: stri const accounts = await web3.eth.getAccounts() - const contract: Contract = new web3.eth.Contract(metadata.abi) + const contract: Contract = new web3.eth.Contract(metadata.abi) const contractSend: ContractSendMethod = contract.deploy({ data: metadata.data.bytecode.object, @@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array, from?: stri from: from || accounts[0], gas: gas || 1500000 }) - return newContractInstance.options + return newContractInstance.options } \ No newline at end of file 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 278146b08a..9692a62954 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 @@ -40,12 +40,12 @@ 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)) - + 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)))) - + console.log('setup done.') - + } catch (e) { console.error(e.message) } 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 daea2ed230..146bdab52b 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 @@ -20,21 +20,21 @@ const logger = { // @ts-ignore const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/calculate_hash.wasm', { encoding: null }); // @ts-ignore - const wasm = new Uint8Array(wasmBuffer); - + const wasm = new Uint8Array(wasmBuffer); + const zkey_final = { type: "mem", data: new Uint8Array(JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/zkey_final.txt'))) } - const wtns = { type: "mem" }; + const wtns = { type: "mem" }; const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/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 = { @@ -44,25 +44,24 @@ const logger = { 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', './zk/build/groth16/zk_verifier.sol', solidityContract) await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({ _pA: [proof.pi_a[0], proof.pi_a[1]], 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 31b2b8a1f9..544cd10b6d 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 @@ -28,7 +28,7 @@ const logger = { 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 = { @@ -41,11 +41,11 @@ const logger = { console.log('calculate') await snarkjs.wtns.calculate(signals, wasm, wtns, 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 verified = await snarkjs.plonk.verify(vKey, publicSignals, proof); console.log('zk proof validity', verified); @@ -53,7 +53,7 @@ const logger = { plonk: await remix.call('fileManager', 'readFile', 'templates/plonk_verifier.sol.ejs') } 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({ _proof: [ @@ -84,9 +84,9 @@ const logger = { ], _pubSignals: publicSignals }, null, 2)) - + console.log('proof done.') - + } catch (e) { console.error(e.message) } diff --git a/libs/remix-ws-templates/src/templates/ozerc1155/index.ts b/libs/remix-ws-templates/src/templates/ozerc1155/index.ts index f200464c07..40811b978f 100644 --- a/libs/remix-ws-templates/src/templates/ozerc1155/index.ts +++ b/libs/remix-ws-templates/src/templates/ozerc1155/index.ts @@ -29,6 +29,6 @@ export default async (opts) => { // @ts-ignore else filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_test.sol')).default } - + return filesObj } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts index 2753f9bcd0..8e4adf95a6 100644 --- a/libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts @@ -7,7 +7,7 @@ import { ethers } from 'ethers' * @param {Number} accountIndex account index from the exposed account * @return {Contract} deployed contract */ -export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { +export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { console.log(`deploying ${contractName}`) // Note that the script needs the ABI which is generated from the compilation artifact. @@ -16,12 +16,12 @@ export const deploy = async (contractName: string, args: Array, accountInde const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) // 'web3Provider' is a remix global variable object - + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) - const contract = await factory.deploy(...args) + const contract = await factory.deploy(...args) // The contract is NOT deployed yet; we must wait until it is mined await contract.deployed() diff --git a/libs/remix-ws-templates/src/templates/ozerc1155/scripts/web3-lib.ts b/libs/remix-ws-templates/src/templates/ozerc1155/scripts/web3-lib.ts index 921774572a..32369998ad 100644 --- a/libs/remix-ws-templates/src/templates/ozerc1155/scripts/web3-lib.ts +++ b/libs/remix-ws-templates/src/templates/ozerc1155/scripts/web3-lib.ts @@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array, from?: stri const accounts = await web3.eth.getAccounts() - const contract: Contract = new web3.eth.Contract(metadata.abi) + const contract: Contract = new web3.eth.Contract(metadata.abi) const contractSend: ContractSendMethod = contract.deploy({ data: metadata.data.bytecode.object, @@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array, from?: stri from: from || accounts[0], gas: gas || 3600000 }) - return newContractInstance.options + return newContractInstance.options } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc20/index.ts b/libs/remix-ws-templates/src/templates/ozerc20/index.ts index 2a8b0c8f3c..09b55ae00b 100644 --- a/libs/remix-ws-templates/src/templates/ozerc20/index.ts +++ b/libs/remix-ws-templates/src/templates/ozerc20/index.ts @@ -23,7 +23,7 @@ export default async (opts) => { // If no options is selected, opts.upgradeable will be undefined // We do not show test file for upgradeable contract - + if (!opts || opts.upgradeable === undefined || !opts.upgradeable) { // @ts-ignore if (erc20.defaults.mintable) filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_mintable_test.sol')).default diff --git a/libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts index 2753f9bcd0..8e4adf95a6 100644 --- a/libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts @@ -7,7 +7,7 @@ import { ethers } from 'ethers' * @param {Number} accountIndex account index from the exposed account * @return {Contract} deployed contract */ -export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { +export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { console.log(`deploying ${contractName}`) // Note that the script needs the ABI which is generated from the compilation artifact. @@ -16,12 +16,12 @@ export const deploy = async (contractName: string, args: Array, accountInde const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) // 'web3Provider' is a remix global variable object - + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) - const contract = await factory.deploy(...args) + const contract = await factory.deploy(...args) // The contract is NOT deployed yet; we must wait until it is mined await contract.deployed() diff --git a/libs/remix-ws-templates/src/templates/ozerc20/scripts/web3-lib.ts b/libs/remix-ws-templates/src/templates/ozerc20/scripts/web3-lib.ts index c57e501039..cbd4f48489 100644 --- a/libs/remix-ws-templates/src/templates/ozerc20/scripts/web3-lib.ts +++ b/libs/remix-ws-templates/src/templates/ozerc20/scripts/web3-lib.ts @@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array, from?: stri const accounts = await web3.eth.getAccounts() - const contract: Contract = new web3.eth.Contract(metadata.abi) + const contract: Contract = new web3.eth.Contract(metadata.abi) const contractSend: ContractSendMethod = contract.deploy({ data: metadata.data.bytecode.object, @@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array, from?: stri from: from || accounts[0], gas: gas || 1500000 }) - return newContractInstance.options + return newContractInstance.options } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers-lib.ts index 2753f9bcd0..8e4adf95a6 100644 --- a/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers-lib.ts @@ -7,7 +7,7 @@ import { ethers } from 'ethers' * @param {Number} accountIndex account index from the exposed account * @return {Contract} deployed contract */ -export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { +export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { console.log(`deploying ${contractName}`) // Note that the script needs the ABI which is generated from the compilation artifact. @@ -16,12 +16,12 @@ export const deploy = async (contractName: string, args: Array, accountInde const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) // 'web3Provider' is a remix global variable object - + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) - const contract = await factory.deploy(...args) + const contract = await factory.deploy(...args) // The contract is NOT deployed yet; we must wait until it is mined await contract.deployed() diff --git a/libs/remix-ws-templates/src/templates/ozerc721/scripts/web3-lib.ts b/libs/remix-ws-templates/src/templates/ozerc721/scripts/web3-lib.ts index c57e501039..cbd4f48489 100644 --- a/libs/remix-ws-templates/src/templates/ozerc721/scripts/web3-lib.ts +++ b/libs/remix-ws-templates/src/templates/ozerc721/scripts/web3-lib.ts @@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array, from?: stri const accounts = await web3.eth.getAccounts() - const contract: Contract = new web3.eth.Contract(metadata.abi) + const contract: Contract = new web3.eth.Contract(metadata.abi) const contractSend: ContractSendMethod = contract.deploy({ data: metadata.data.bytecode.object, @@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array, from?: stri from: from || accounts[0], gas: gas || 1500000 }) - return newContractInstance.options + return newContractInstance.options } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/playground/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/playground/scripts/ethers-lib.ts index 2753f9bcd0..8e4adf95a6 100644 --- a/libs/remix-ws-templates/src/templates/playground/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/playground/scripts/ethers-lib.ts @@ -7,7 +7,7 @@ import { ethers } from 'ethers' * @param {Number} accountIndex account index from the exposed account * @return {Contract} deployed contract */ -export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { +export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { console.log(`deploying ${contractName}`) // Note that the script needs the ABI which is generated from the compilation artifact. @@ -16,12 +16,12 @@ export const deploy = async (contractName: string, args: Array, accountInde const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) // 'web3Provider' is a remix global variable object - + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) - const contract = await factory.deploy(...args) + const contract = await factory.deploy(...args) // The contract is NOT deployed yet; we must wait until it is mined await contract.deployed() diff --git a/libs/remix-ws-templates/src/templates/playground/scripts/web3-lib.ts b/libs/remix-ws-templates/src/templates/playground/scripts/web3-lib.ts index c57e501039..cbd4f48489 100644 --- a/libs/remix-ws-templates/src/templates/playground/scripts/web3-lib.ts +++ b/libs/remix-ws-templates/src/templates/playground/scripts/web3-lib.ts @@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array, from?: stri const accounts = await web3.eth.getAccounts() - const contract: Contract = new web3.eth.Contract(metadata.abi) + const contract: Contract = new web3.eth.Contract(metadata.abi) const contractSend: ContractSendMethod = contract.deploy({ data: metadata.data.bytecode.object, @@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array, from?: stri from: from || accounts[0], gas: gas || 1500000 }) - return newContractInstance.options + return newContractInstance.options } \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/remixDefault/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/remixDefault/scripts/ethers-lib.ts index 2753f9bcd0..8e4adf95a6 100644 --- a/libs/remix-ws-templates/src/templates/remixDefault/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/remixDefault/scripts/ethers-lib.ts @@ -7,7 +7,7 @@ import { ethers } from 'ethers' * @param {Number} accountIndex account index from the exposed account * @return {Contract} deployed contract */ -export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { +export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { console.log(`deploying ${contractName}`) // Note that the script needs the ABI which is generated from the compilation artifact. @@ -16,12 +16,12 @@ export const deploy = async (contractName: string, args: Array, accountInde const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) // 'web3Provider' is a remix global variable object - + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) - const contract = await factory.deploy(...args) + const contract = await factory.deploy(...args) // The contract is NOT deployed yet; we must wait until it is mined await contract.deployed() diff --git a/libs/remix-ws-templates/src/templates/remixDefault/scripts/web3-lib.ts b/libs/remix-ws-templates/src/templates/remixDefault/scripts/web3-lib.ts index c57e501039..cbd4f48489 100644 --- a/libs/remix-ws-templates/src/templates/remixDefault/scripts/web3-lib.ts +++ b/libs/remix-ws-templates/src/templates/remixDefault/scripts/web3-lib.ts @@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array, from?: stri const accounts = await web3.eth.getAccounts() - const contract: Contract = new web3.eth.Contract(metadata.abi) + const contract: Contract = new web3.eth.Contract(metadata.abi) const contractSend: ContractSendMethod = contract.deploy({ data: metadata.data.bytecode.object, @@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array, from?: stri from: from || accounts[0], gas: gas || 1500000 }) - return newContractInstance.options + return newContractInstance.options } \ No newline at end of file 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 19b9736314..c4a9513c92 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 @@ -40,12 +40,12 @@ 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)) - + console.log('save zkey_final') await remix.call('fileManager', 'writeFile', './zk/keys/groth16/zkey_final.txt', (zkey_final as any).data, { encoding: null }) - + console.log('setup done.') - + } catch (e) { console.error(e.message) } 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 f8cef8c28e..d982568928 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 @@ -45,13 +45,13 @@ function hashNullifier(message: any): bigint { async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { console.log('calculate') await snarkjs.wtns.calculate(signals, wasm, wtns); - + console.log('check') - await snarkjs.wtns.check(r1cs, wtns, logger); + 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); @@ -81,33 +81,33 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { // @ts-ignore const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/rln.wasm', { encoding: null }); // @ts-ignore - const wasm = new Uint8Array(wasmBuffer); - + const wasm = new Uint8Array(wasmBuffer); + const zkey_final = { type: "mem", data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/groth16/zkey_final.txt', { encoding: null })) } - const wtns = { type: "mem" }; + const wtns = { type: "mem" }; const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/verification_key.json')) - + // build list of identity commitments const secrets = [] const identityCommitments = [] const rateCommitments = [] const userMessageLimit = 0x2 - for (let k = 0; k < 2; k++) { + for (let k = 0; k < 2; k++) { const identitySecret = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32))) secrets.push(identitySecret) - + const identityCommitment = poseidon([identitySecret]) const rateCommitment = poseidon([identityCommitment, userMessageLimit]) identityCommitments.push(identityCommitment) rateCommitments.push(rateCommitment) } - + let tree - + try { tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, rateCommitments) // Binary tree. } catch (e) { @@ -130,7 +130,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { externalNullifier: 0xa // hash(epoch, appId) } const proof1 = await prove(signals1, wasm, wtns, r1cs, zkey_final, vKey) - + const signals2 = { identitySecret: secrets[0], userMessageLimit, @@ -146,12 +146,12 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { console.log(secret.toString(10)) console.log(Fq.normalize(secrets[0])) - + 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', './zk/build/groth16/zk_verifier.sol', solidityContract) } catch (e) { console.error(e.message) 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 09b0a885f8..b05c84720b 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 @@ -45,13 +45,13 @@ function hashNullifier(message: any): bigint { async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { console.log('calculate') await snarkjs.wtns.calculate(signals, wasm, wtns); - + console.log('check') - await snarkjs.wtns.check(r1cs, wtns, logger); + await snarkjs.wtns.check(r1cs, wtns, logger); console.log('prove') const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns); - + const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, logger); console.log('zk proof validity', verified); @@ -84,7 +84,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_zw).toHexString(), 32), ] }, null, 2)) - + console.log('proof done.') return { proof, @@ -104,8 +104,8 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { // @ts-ignore const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/rln.wasm', { encoding: null }); // @ts-ignore - const wasm = new Uint8Array(wasmBuffer); - + const wasm = new Uint8Array(wasmBuffer); + const zkey_final = { type: "mem", // @ts-ignore @@ -114,24 +114,24 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { const wtns = { type: "mem" }; const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/plonk/verification_key.json')) - + // build list of identity commitments const secrets = [] const identityCommitments = [] const rateCommitments = [] const userMessageLimit = 0x2 - for (let k = 0; k < 2; k++) { + for (let k = 0; k < 2; k++) { const identitySecret = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32))) secrets.push(identitySecret) - + const identityCommitment = poseidon([identitySecret]) const rateCommitment = poseidon([identityCommitment, userMessageLimit]) identityCommitments.push(identityCommitment) rateCommitments.push(rateCommitment) } - + let tree - + try { tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, rateCommitments) // Binary tree. } catch (e) { @@ -154,7 +154,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { externalNullifier: 0xa // hash(epoch, appId) } const proof1 = await prove(signals1, wasm, wtns, r1cs, zkey_final, vKey) - + const signals2 = { identitySecret: secrets[0], userMessageLimit, @@ -170,12 +170,12 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { console.log(secret.toString(10)) console.log(Fq.normalize(secrets[0])) - + const templates = { plonk: await remix.call('fileManager', 'readFile', 'templates/plonk_verifier.sol.ejs') } const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) - + await remix.call('fileManager', 'writeFile', './zk/build/plonk/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 d3b205f858..a155ef2192 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 @@ -40,13 +40,13 @@ 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)) - + 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 }) - + console.log('setup done.') - + } catch (e) { console.error(e.message) } 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 d477342506..35c708efa7 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 @@ -33,33 +33,33 @@ function hash(message: any): bigint { // @ts-ignore const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/semaphore.wasm', true); // @ts-ignore - const wasm = new Uint8Array(wasmBuffer); - + const wasm = new Uint8Array(wasmBuffer); + const zkey_final = { type: "mem", // @ts-ignore data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/groth16/zkey_final.txt', { encoding: null })) } - const wtns = { type: "mem" }; + const wtns = { type: "mem" }; const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/verification_key.json')) - + // build list of identity commitments const secrets = [] const identityCommitments = [] for (let k = 0; k < 2; k++) { const identityTrapdoor = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32))) const identityNullifier = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32))) - secrets.push({identityTrapdoor, identityNullifier}) - + secrets.push({ identityTrapdoor, identityNullifier }) + const secret = poseidon([identityNullifier, identityTrapdoor]) const identityCommitment = poseidon([secret]) identityCommitments.push(identityCommitment) } //console.log('incremental tree', identityCommitments.map((x) => x.toString())) - + let tree - + try { tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, identityCommitments) // Binary tree. } catch (e) { @@ -69,11 +69,11 @@ function hash(message: any): bigint { const index = tree.indexOf(identityCommitments[0]) console.log(index.toString()) - + const proof1 = tree.createProof(0) console.log('prepare signals for id ', identityCommitments[0].toString(), tree.indexOf(identityCommitments[0]), proof1.siblings.map((x)=> x.toString())) - + const signals = { identityTrapdoor: secrets[0].identityTrapdoor, identityNullifier: secrets[0].identityNullifier, @@ -82,16 +82,16 @@ function hash(message: any): bigint { externalNullifier: hash(42), signalHash: hash(ethers.utils.formatBytes32String("Hello World")) } - + 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); proof1.root.toString() === publicSignals[0] ? console.log('merkle proof valid') : console.log('merkle proof invalid') @@ -100,7 +100,7 @@ function hash(message: any): bigint { 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', './zk/build/groth16/zk_verifier.sol', solidityContract) await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({ _pA: [proof.pi_a[0], proof.pi_a[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 8ebdab1e71..c6d73a91fb 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 @@ -24,13 +24,13 @@ 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)) - + 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 }) - + console.log('setup done.') - + } catch (e) { console.error(e.message) } 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 6472567bb1..fd7f51d4a0 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 @@ -33,33 +33,33 @@ function hash(message: any): bigint { // @ts-ignore const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/semaphore.wasm', true); // @ts-ignore - const wasm = new Uint8Array(wasmBuffer); - + const wasm = new Uint8Array(wasmBuffer); + const zkey_final = { type: "mem", // @ts-ignore data: new Uint8Array(await remix.call('fileManager', 'readFile', './zk/keys/plonk/zkey_final.txt', { encoding: null })) } - const wtns = { type: "mem" }; + const wtns = { type: "mem" }; const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/plonk/verification_key.json')) - + // build list of identity commitments const secrets = [] const identityCommitments = [] for (let k = 0; k < 2; k++) { const identityTrapdoor = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32))) const identityNullifier = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32))) - secrets.push({identityTrapdoor, identityNullifier}) - + secrets.push({ identityTrapdoor, identityNullifier }) + const secret = poseidon([identityNullifier, identityTrapdoor]) const identityCommitment = poseidon([secret]) identityCommitments.push(identityCommitment) } //console.log('incremental tree', identityCommitments.map((x) => x.toString())) - + let tree - + try { tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, identityCommitments) // Binary tree. } catch (e) { @@ -69,11 +69,11 @@ function hash(message: any): bigint { const index = tree.indexOf(identityCommitments[0]) console.log(index.toString()) - + const proof1 = tree.createProof(0) console.log('prepare signals for id ', identityCommitments[0].toString(), tree.indexOf(identityCommitments[0]), proof1.siblings.map((x)=> x.toString())) - + const signals = { identityTrapdoor: secrets[0].identityTrapdoor, identityNullifier: secrets[0].identityNullifier, @@ -82,16 +82,16 @@ function hash(message: any): bigint { externalNullifier: hash(42), signalHash: hash(ethers.utils.formatBytes32String("Hello World")) } - + 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.plonk.prove(zkey_final, wtns); - + const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, logger); console.log('zk proof validity', verified); proof1.root.toString() === publicSignals[0] ? console.log('merkle proof valid') : console.log('merkle proof invalid') @@ -100,7 +100,7 @@ function hash(message: any): bigint { plonk: await remix.call('fileManager', 'readFile', 'templates/plonk_verifier.sol.ejs') } 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({ _proof: [ @@ -131,7 +131,7 @@ function hash(message: any): bigint { ], _pubSignals: publicSignals }, null, 2)) - + console.log('proof done.') } catch (e) { console.error(e.message) diff --git a/libs/remix-ws-templates/src/templates/semaphore/scripts/run_setup.ts b/libs/remix-ws-templates/src/templates/semaphore/scripts/run_setup.ts index 1d8505b71d..26764841d7 100644 --- a/libs/remix-ws-templates/src/templates/semaphore/scripts/run_setup.ts +++ b/libs/remix-ws-templates/src/templates/semaphore/scripts/run_setup.ts @@ -53,19 +53,19 @@ function hash(message: any): bigint { console.log('exportVerificationKey') const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final) await remix.call('fileManager', 'writeFile', './zk/build/verification_key.json', JSON.stringify(vKey)) - + 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', './zk/build/zk_verifier.sol', solidityContract) - + console.log('buffer', (zkey_final as any).data.length) await remix.call('fileManager', 'writeFile', './zk/build/zk_setup.txt', JSON.stringify(Array.from(((zkey_final as any).data)))) - + console.log('setup done.') - + } catch (e) { console.error(e.message) } diff --git a/libs/remix-ws-templates/src/templates/semaphore/scripts/run_verification.ts b/libs/remix-ws-templates/src/templates/semaphore/scripts/run_verification.ts index e97e4074e9..24da889470 100644 --- a/libs/remix-ws-templates/src/templates/semaphore/scripts/run_verification.ts +++ b/libs/remix-ws-templates/src/templates/semaphore/scripts/run_verification.ts @@ -31,32 +31,32 @@ function hash(message: any): bigint { // @ts-ignore const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/semaphore.wasm', true); // @ts-ignore - const wasm = new Uint8Array(wasmBuffer); - + const wasm = new Uint8Array(wasmBuffer); + const zkey_final = { type: "mem", data: new Uint8Array(JSON.parse(await remix.call('fileManager', 'readFile', './zk/build/zk_setup.txt'))) } - const wtns = { type: "mem" }; + const wtns = { type: "mem" }; const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/build/verification_key.json')) - + // build list of identity commitments const secrets = [] const identityCommitments = [] - for (let k = 0; k < 2; k++) { + for (let k = 0; k < 2; k++) { const identityTrapdoor = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32))) const identityNullifier = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32))) - secrets.push({identityTrapdoor, identityNullifier}) - + secrets.push({ identityTrapdoor, identityNullifier }) + const secret = poseidon([identityNullifier, identityTrapdoor]) const identityCommitment = poseidon([secret]) identityCommitments.push(identityCommitment) } //console.log('incremental tree', identityCommitments.map((x) => x.toString())) - + let tree - + try { tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, identityCommitments) // Binary tree. } catch (e) { @@ -66,11 +66,11 @@ function hash(message: any): bigint { const index = tree.indexOf(identityCommitments[0]) console.log(index.toString()) - + const proof1 = tree.createProof(0) console.log('prepare signals for id ', identityCommitments[0].toString(), tree.indexOf(identityCommitments[0]), proof1.siblings.map((x)=> x.toString())) - + const signals = { identityTrapdoor: secrets[0].identityTrapdoor, identityNullifier: secrets[0].identityNullifier, @@ -79,23 +79,20 @@ function hash(message: any): bigint { externalNullifier: hash(42), signalHash: hash(ethers.utils.formatBytes32String("Hello World")) } - + 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); proof1.root.toString() === publicSignals[0] ? console.log('merkle proof valid') : console.log('merkle proof invalid') - - } catch (e) { console.error(e.message) } diff --git a/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/ethers-lib.ts b/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/ethers-lib.ts index 2753f9bcd0..8e4adf95a6 100644 --- a/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/ethers-lib.ts +++ b/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/ethers-lib.ts @@ -7,7 +7,7 @@ import { ethers } from 'ethers' * @param {Number} accountIndex account index from the exposed account * @return {Contract} deployed contract */ -export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { +export const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { console.log(`deploying ${contractName}`) // Note that the script needs the ABI which is generated from the compilation artifact. @@ -16,12 +16,12 @@ export const deploy = async (contractName: string, args: Array, accountInde const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) // 'web3Provider' is a remix global variable object - + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) - const contract = await factory.deploy(...args) + const contract = await factory.deploy(...args) // The contract is NOT deployed yet; we must wait until it is mined await contract.deployed() diff --git a/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/web3-lib.ts b/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/web3-lib.ts index c57e501039..cbd4f48489 100644 --- a/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/web3-lib.ts +++ b/libs/remix-ws-templates/src/templates/zeroxErc20/scripts/web3-lib.ts @@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array, from?: stri const accounts = await web3.eth.getAccounts() - const contract: Contract = new web3.eth.Contract(metadata.abi) + const contract: Contract = new web3.eth.Contract(metadata.abi) const contractSend: ContractSendMethod = contract.deploy({ data: metadata.data.bytecode.object, @@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array, from?: stri from: from || accounts[0], gas: gas || 1500000 }) - return newContractInstance.options + return newContractInstance.options } \ No newline at end of file