linting fixes for remix-ws-templates

pull/4771/head
lianahus 7 months ago
parent 4fe4b7f97e
commit 811d90ae36
  1. 6
      libs/remix-ws-templates/src/script-templates/contract-deployer/basic-contract-deploy.ts
  2. 6
      libs/remix-ws-templates/src/script-templates/contract-deployer/index.ts
  3. 2
      libs/remix-ws-templates/src/script-templates/create2-solidity-factory/index.ts
  4. 6
      libs/remix-ws-templates/src/script-templates/etherscan/index.ts
  5. 2
      libs/remix-ws-templates/src/script-templates/etherscan/receiptGuidScript.ts
  6. 2
      libs/remix-ws-templates/src/script-templates/etherscan/verifyScript.ts
  7. 4
      libs/remix-ws-templates/src/script-templates/sindri/index.ts
  8. 2
      libs/remix-ws-templates/src/script-templates/sindri/run_compile.ts
  9. 2
      libs/remix-ws-templates/src/script-templates/sindri/run_prove.ts
  10. 4
      libs/remix-ws-templates/src/script-templates/sindri/utils.ts
  11. 6
      libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/ethers-lib.ts
  12. 4
      libs/remix-ws-templates/src/templates/gnosisSafeMultisig/scripts/web3-lib.ts
  13. 6
      libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_trusted_setup.ts
  14. 21
      libs/remix-ws-templates/src/templates/hashchecker/scripts/groth16/groth16_zkproof.ts
  15. 12
      libs/remix-ws-templates/src/templates/hashchecker/scripts/plonk/plonk_zkproof.ts
  16. 2
      libs/remix-ws-templates/src/templates/ozerc1155/index.ts
  17. 6
      libs/remix-ws-templates/src/templates/ozerc1155/scripts/ethers-lib.ts
  18. 4
      libs/remix-ws-templates/src/templates/ozerc1155/scripts/web3-lib.ts
  19. 2
      libs/remix-ws-templates/src/templates/ozerc20/index.ts
  20. 6
      libs/remix-ws-templates/src/templates/ozerc20/scripts/ethers-lib.ts
  21. 4
      libs/remix-ws-templates/src/templates/ozerc20/scripts/web3-lib.ts
  22. 6
      libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers-lib.ts
  23. 4
      libs/remix-ws-templates/src/templates/ozerc721/scripts/web3-lib.ts
  24. 6
      libs/remix-ws-templates/src/templates/playground/scripts/ethers-lib.ts
  25. 4
      libs/remix-ws-templates/src/templates/playground/scripts/web3-lib.ts
  26. 6
      libs/remix-ws-templates/src/templates/remixDefault/scripts/ethers-lib.ts
  27. 4
      libs/remix-ws-templates/src/templates/remixDefault/scripts/web3-lib.ts
  28. 6
      libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_trusted_setup.ts
  29. 28
      libs/remix-ws-templates/src/templates/rln/scripts/groth16/groth16_zkproof.ts
  30. 28
      libs/remix-ws-templates/src/templates/rln/scripts/plonk/plonk_zkproof.ts
  31. 6
      libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_trusted_setup.ts
  32. 28
      libs/remix-ws-templates/src/templates/semaphore/scripts/groth16/groth16_zkproof.ts
  33. 6
      libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_trusted_setup.ts
  34. 30
      libs/remix-ws-templates/src/templates/semaphore/scripts/plonk/plonk_zkproof.ts
  35. 10
      libs/remix-ws-templates/src/templates/semaphore/scripts/run_setup.ts
  36. 31
      libs/remix-ws-templates/src/templates/semaphore/scripts/run_verification.ts
  37. 6
      libs/remix-ws-templates/src/templates/zeroxErc20/scripts/ethers-lib.ts
  38. 4
      libs/remix-ws-templates/src/templates/zeroxErc20/scripts/web3-lib.ts

@ -7,7 +7,7 @@ import { ethers } from 'ethers'
* @param {Number} accountIndex account index from the exposed account * @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract * @return {Contract} deployed contract
*/ */
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => { export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`) console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact. // 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<any>, accountInde
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object // 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) 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 // The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed() await contract.deployed()

@ -1,12 +1,12 @@
export const contractDeployerScripts = async (plugin) => { export const contractDeployerScripts = async (plugin) => {
await plugin.call('fileManager', 'writeFile', await plugin.call('fileManager', 'writeFile',
'scripts/contract-deployer/create2-factory-deploy.ts' , 'scripts/contract-deployer/create2-factory-deploy.ts' ,
// @ts-ignore // @ts-ignore
(await import('!!raw-loader!./create2-factory-deploy.ts')).default) (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', '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' , 'scripts/contract-deployer/basic-contract-deploy.ts' ,
// @ts-ignore // @ts-ignore
(await import('!!raw-loader!./basic-contract-deploy.ts')).default) (await import('!!raw-loader!./basic-contract-deploy.ts')).default)

@ -1,5 +1,5 @@
export const contractCreate2Factory = async (plugin) => { export const contractCreate2Factory = async (plugin) => {
await plugin.call('fileManager', 'writeFile', await plugin.call('fileManager', 'writeFile',
'contracts/libs/create2-factory.sol' , 'contracts/libs/create2-factory.sol' ,
// @ts-ignore // @ts-ignore
(await import('!!raw-loader!./create2-factory.sol')).default) (await import('!!raw-loader!./create2-factory.sol')).default)

@ -1,12 +1,12 @@
export const etherscanScripts = async (plugin) => { export const etherscanScripts = async (plugin) => {
await plugin.call('fileManager', 'writeFile', await plugin.call('fileManager', 'writeFile',
'scripts/etherscan/verifyScript.ts' , 'scripts/etherscan/verifyScript.ts' ,
// @ts-ignore // @ts-ignore
(await import('!!raw-loader!./verifyScript.ts')).default) (await import('!!raw-loader!./verifyScript.ts')).default)
await plugin.call('fileManager', 'open', 'scripts/etherscan/verifyScript.ts') await plugin.call('fileManager', 'open', 'scripts/etherscan/verifyScript.ts')
await plugin.call('fileManager', 'writeFile', await plugin.call('fileManager', 'writeFile',
'scripts/etherscan/receiptGuidScript.ts' , 'scripts/etherscan/receiptGuidScript.ts' ,
// @ts-ignore // @ts-ignore
(await import('!!raw-loader!./receiptGuidScript.ts')).default) (await import('!!raw-loader!./receiptGuidScript.ts')).default)

@ -5,5 +5,5 @@
* @returns {{ status, message, succeed }} receiptStatus * @returns {{ status, message, succeed }} receiptStatus
*/ */
export const receiptStatus = async (apikey: string, guid: string, isProxyContract?: boolean) => { 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)
} }

@ -13,5 +13,5 @@ export const verify = async (apikey: string, contractAddress: string, contractAr
const compilationResultParam = await remix.call('compilerArtefacts' as any, 'getCompilerAbstract', contractFile) const compilationResultParam = await remix.call('compilerArtefacts' as any, 'getCompilerAbstract', contractFile)
console.log('verifying.. ' + contractName) console.log('verifying.. ' + contractName)
// update apiKey and chainRef to verify contract on multiple networks // 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)
} }

@ -71,12 +71,12 @@ export const sindriScripts = async (plugin: any) => {
if (a.isTemplateEntrypoint !== b.isTemplateEntrypoint) return +b.isTemplateEntrypoint - +a.isTemplateEntrypoint if (a.isTemplateEntrypoint !== b.isTemplateEntrypoint) return +b.isTemplateEntrypoint - +a.isTemplateEntrypoint
return a.path.localeCompare(b.path) return a.path.localeCompare(b.path)
}) })
.map(({path}) => path)[0] || './circuit.circom' .map(({ path }) => path)[0] || './circuit.circom'
sindriManifest.circuitPath = circomCircuitPath sindriManifest.circuitPath = circomCircuitPath
} }
// Derive the circuit name from the workspace name. // 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 = sindriManifest.name =
workspaceName workspaceName
.replace(/\s*-+\s*\d*$/, '') .replace(/\s*-+\s*\d*$/, '')

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

@ -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. // 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 signals: {[name: string]: number | string} = {}

@ -1,5 +1,5 @@
import sindriClient from 'sindri' import sindriClient from 'sindri'
import type {CircuitInfoResponse, ProofInfoResponse} from 'sindri' import type { CircuitInfoResponse, ProofInfoResponse } from 'sindri'
sindriClient.logLevel = 'info' sindriClient.logLevel = 'info'
@ -9,7 +9,7 @@ const authorize = async () => {
if (!apiKey) { if (!apiKey) {
throw new Error('Missing API key.') throw new Error('Missing API key.')
} }
sindriClient.authorize({apiKey}) sindriClient.authorize({ apiKey })
} catch { } 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".' 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) await remix.call('notification', 'toast', message)

@ -7,7 +7,7 @@ import { ethers } from 'ethers'
* @param {Number} accountIndex account index from the exposed account * @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract * @return {Contract} deployed contract
*/ */
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => { export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`) console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact. // 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<any>, accountInde
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object // 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) 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 // The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed() await contract.deployed()

@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
const accounts = await web3.eth.getAccounts() 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({ const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object, data: metadata.data.bytecode.object,
@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
from: from || accounts[0], from: from || accounts[0],
gas: gas || 1500000 gas: gas || 1500000
}) })
return newContractInstance.options return newContractInstance.options
} }

@ -40,12 +40,12 @@ const logger = {
console.log('exportVerificationKey') console.log('exportVerificationKey')
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final) 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', './zk/keys/groth16/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('save zkey_final') 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', './zk/keys/groth16/zkey_final.txt', JSON.stringify(Array.from(((zkey_final as any).data))))
console.log('setup done.') console.log('setup done.')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }

@ -20,21 +20,21 @@ const logger = {
// @ts-ignore // @ts-ignore
const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/calculate_hash.wasm', { encoding: null }); const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/calculate_hash.wasm', { encoding: null });
// @ts-ignore // @ts-ignore
const wasm = new Uint8Array(wasmBuffer); const wasm = new Uint8Array(wasmBuffer);
const zkey_final = { const zkey_final = {
type: "mem", 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', './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 vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/verification_key.json'))
const value1 = '1234' const value1 = '1234'
const value2 = '2' const value2 = '2'
const value3 = '3' const value3 = '3'
const value4 = '4' const value4 = '4'
const wrongValue = '5' // put this in the poseidon hash calculation to simulate a non matching hash. const wrongValue = '5' // put this in the poseidon hash calculation to simulate a non matching hash.
const signals = { const signals = {
@ -44,25 +44,24 @@ const logger = {
value4, value4,
hash: poseidon([value1, value2, value3, value4]) hash: poseidon([value1, value2, value3, value4])
} }
console.log('calculate') console.log('calculate')
await snarkjs.wtns.calculate(signals, wasm, wtns); await snarkjs.wtns.calculate(signals, wasm, wtns);
console.log('check') console.log('check')
await snarkjs.wtns.check(r1cs, wtns, logger); await snarkjs.wtns.check(r1cs, wtns, logger);
console.log('prove') console.log('prove')
const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns); const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns);
const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger); const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified); console.log('zk proof validity', verified);
const templates = { const templates = {
groth16: await remix.call('fileManager', 'readFile', 'templates/groth16_verifier.sol.ejs') groth16: await remix.call('fileManager', 'readFile', 'templates/groth16_verifier.sol.ejs')
} }
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) 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/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({ await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({
_pA: [proof.pi_a[0], proof.pi_a[1]], _pA: [proof.pi_a[0], proof.pi_a[1]],

@ -28,7 +28,7 @@ const logger = {
const value2 = '2' const value2 = '2'
const value3 = '3' const value3 = '3'
const value4 = '4' const value4 = '4'
const wrongValue = '5' // put this in the poseidon hash calculation to simulate a non matching hash. const wrongValue = '5' // put this in the poseidon hash calculation to simulate a non matching hash.
const signals = { const signals = {
@ -41,11 +41,11 @@ const logger = {
console.log('calculate') console.log('calculate')
await snarkjs.wtns.calculate(signals, wasm, wtns, logger); await snarkjs.wtns.calculate(signals, wasm, wtns, logger);
const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns); 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', './zk/keys/plonk/verification_key.json'))
const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof); const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof);
console.log('zk proof validity', verified); console.log('zk proof validity', verified);
@ -53,7 +53,7 @@ const logger = {
plonk: await remix.call('fileManager', 'readFile', 'templates/plonk_verifier.sol.ejs') plonk: await remix.call('fileManager', 'readFile', 'templates/plonk_verifier.sol.ejs')
} }
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) 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/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({ await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({
_proof: [ _proof: [
@ -84,9 +84,9 @@ const logger = {
], ],
_pubSignals: publicSignals _pubSignals: publicSignals
}, null, 2)) }, null, 2))
console.log('proof done.') console.log('proof done.')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }

@ -29,6 +29,6 @@ export default async (opts) => {
// @ts-ignore // @ts-ignore
else filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_test.sol')).default else filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_test.sol')).default
} }
return filesObj return filesObj
} }

@ -7,7 +7,7 @@ import { ethers } from 'ethers'
* @param {Number} accountIndex account index from the exposed account * @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract * @return {Contract} deployed contract
*/ */
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => { export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`) console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact. // 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<any>, accountInde
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object // 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) 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 // The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed() await contract.deployed()

@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
const accounts = await web3.eth.getAccounts() 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({ const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object, data: metadata.data.bytecode.object,
@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
from: from || accounts[0], from: from || accounts[0],
gas: gas || 3600000 gas: gas || 3600000
}) })
return newContractInstance.options return newContractInstance.options
} }

@ -23,7 +23,7 @@ export default async (opts) => {
// If no options is selected, opts.upgradeable will be undefined // If no options is selected, opts.upgradeable will be undefined
// We do not show test file for upgradeable contract // We do not show test file for upgradeable contract
if (!opts || opts.upgradeable === undefined || !opts.upgradeable) { if (!opts || opts.upgradeable === undefined || !opts.upgradeable) {
// @ts-ignore // @ts-ignore
if (erc20.defaults.mintable) filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_mintable_test.sol')).default if (erc20.defaults.mintable) filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_mintable_test.sol')).default

@ -7,7 +7,7 @@ import { ethers } from 'ethers'
* @param {Number} accountIndex account index from the exposed account * @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract * @return {Contract} deployed contract
*/ */
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => { export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`) console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact. // 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<any>, accountInde
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object // 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) 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 // The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed() await contract.deployed()

@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
const accounts = await web3.eth.getAccounts() 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({ const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object, data: metadata.data.bytecode.object,
@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
from: from || accounts[0], from: from || accounts[0],
gas: gas || 1500000 gas: gas || 1500000
}) })
return newContractInstance.options return newContractInstance.options
} }

@ -7,7 +7,7 @@ import { ethers } from 'ethers'
* @param {Number} accountIndex account index from the exposed account * @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract * @return {Contract} deployed contract
*/ */
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => { export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`) console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact. // 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<any>, accountInde
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object // 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) 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 // The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed() await contract.deployed()

@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
const accounts = await web3.eth.getAccounts() 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({ const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object, data: metadata.data.bytecode.object,
@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
from: from || accounts[0], from: from || accounts[0],
gas: gas || 1500000 gas: gas || 1500000
}) })
return newContractInstance.options return newContractInstance.options
} }

@ -7,7 +7,7 @@ import { ethers } from 'ethers'
* @param {Number} accountIndex account index from the exposed account * @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract * @return {Contract} deployed contract
*/ */
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => { export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`) console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact. // 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<any>, accountInde
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object // 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) 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 // The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed() await contract.deployed()

@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
const accounts = await web3.eth.getAccounts() 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({ const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object, data: metadata.data.bytecode.object,
@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
from: from || accounts[0], from: from || accounts[0],
gas: gas || 1500000 gas: gas || 1500000
}) })
return newContractInstance.options return newContractInstance.options
} }

@ -7,7 +7,7 @@ import { ethers } from 'ethers'
* @param {Number} accountIndex account index from the exposed account * @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract * @return {Contract} deployed contract
*/ */
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => { export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`) console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact. // 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<any>, accountInde
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object // 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) 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 // The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed() await contract.deployed()

@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
const accounts = await web3.eth.getAccounts() 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({ const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object, data: metadata.data.bytecode.object,
@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
from: from || accounts[0], from: from || accounts[0],
gas: gas || 1500000 gas: gas || 1500000
}) })
return newContractInstance.options return newContractInstance.options
} }

@ -40,12 +40,12 @@ const logger = {
console.log('exportVerificationKey') console.log('exportVerificationKey')
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final) 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', './zk/keys/groth16/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('save zkey_final') 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', './zk/keys/groth16/zkey_final.txt', (zkey_final as any).data, { encoding: null })
console.log('setup done.') console.log('setup done.')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }

@ -45,13 +45,13 @@ function hashNullifier(message: any): bigint {
async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
console.log('calculate') console.log('calculate')
await snarkjs.wtns.calculate(signals, wasm, wtns); await snarkjs.wtns.calculate(signals, wasm, wtns);
console.log('check') console.log('check')
await snarkjs.wtns.check(r1cs, wtns, logger); await snarkjs.wtns.check(r1cs, wtns, logger);
console.log('prove') console.log('prove')
const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns); const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns);
const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger); const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified); console.log('zk proof validity', verified);
@ -81,33 +81,33 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
// @ts-ignore // @ts-ignore
const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/rln.wasm', { encoding: null }); const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/rln.wasm', { encoding: null });
// @ts-ignore // @ts-ignore
const wasm = new Uint8Array(wasmBuffer); const wasm = new Uint8Array(wasmBuffer);
const zkey_final = { const zkey_final = {
type: "mem", 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', './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')) const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/verification_key.json'))
// build list of identity commitments // build list of identity commitments
const secrets = [] const secrets = []
const identityCommitments = [] const identityCommitments = []
const rateCommitments = [] const rateCommitments = []
const userMessageLimit = 0x2 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))) const identitySecret = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32)))
secrets.push(identitySecret) secrets.push(identitySecret)
const identityCommitment = poseidon([identitySecret]) const identityCommitment = poseidon([identitySecret])
const rateCommitment = poseidon([identityCommitment, userMessageLimit]) const rateCommitment = poseidon([identityCommitment, userMessageLimit])
identityCommitments.push(identityCommitment) identityCommitments.push(identityCommitment)
rateCommitments.push(rateCommitment) rateCommitments.push(rateCommitment)
} }
let tree let tree
try { try {
tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, rateCommitments) // Binary tree. tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, rateCommitments) // Binary tree.
} catch (e) { } catch (e) {
@ -130,7 +130,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
externalNullifier: 0xa // hash(epoch, appId) externalNullifier: 0xa // hash(epoch, appId)
} }
const proof1 = await prove(signals1, wasm, wtns, r1cs, zkey_final, vKey) const proof1 = await prove(signals1, wasm, wtns, r1cs, zkey_final, vKey)
const signals2 = { const signals2 = {
identitySecret: secrets[0], identitySecret: secrets[0],
userMessageLimit, userMessageLimit,
@ -146,12 +146,12 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
console.log(secret.toString(10)) console.log(secret.toString(10))
console.log(Fq.normalize(secrets[0])) console.log(Fq.normalize(secrets[0]))
const templates = { const templates = {
groth16: await remix.call('fileManager', 'readFile', 'templates/groth16_verifier.sol.ejs') groth16: await remix.call('fileManager', 'readFile', 'templates/groth16_verifier.sol.ejs')
} }
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) 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/zk_verifier.sol', solidityContract)
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)

@ -45,13 +45,13 @@ function hashNullifier(message: any): bigint {
async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) { async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
console.log('calculate') console.log('calculate')
await snarkjs.wtns.calculate(signals, wasm, wtns); await snarkjs.wtns.calculate(signals, wasm, wtns);
console.log('check') console.log('check')
await snarkjs.wtns.check(r1cs, wtns, logger); await snarkjs.wtns.check(r1cs, wtns, logger);
console.log('prove') console.log('prove')
const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns); const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns);
const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, logger); const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified); 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), ethers.utils.hexZeroPad(ethers.BigNumber.from(proof.eval_zw).toHexString(), 32),
] ]
}, null, 2)) }, null, 2))
console.log('proof done.') console.log('proof done.')
return { return {
proof, proof,
@ -104,8 +104,8 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
// @ts-ignore // @ts-ignore
const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/rln.wasm', { encoding: null }); const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/rln.wasm', { encoding: null });
// @ts-ignore // @ts-ignore
const wasm = new Uint8Array(wasmBuffer); const wasm = new Uint8Array(wasmBuffer);
const zkey_final = { const zkey_final = {
type: "mem", type: "mem",
// @ts-ignore // @ts-ignore
@ -114,24 +114,24 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
const wtns = { type: "mem" }; 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', './zk/keys/plonk/verification_key.json'))
// build list of identity commitments // build list of identity commitments
const secrets = [] const secrets = []
const identityCommitments = [] const identityCommitments = []
const rateCommitments = [] const rateCommitments = []
const userMessageLimit = 0x2 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))) const identitySecret = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32)))
secrets.push(identitySecret) secrets.push(identitySecret)
const identityCommitment = poseidon([identitySecret]) const identityCommitment = poseidon([identitySecret])
const rateCommitment = poseidon([identityCommitment, userMessageLimit]) const rateCommitment = poseidon([identityCommitment, userMessageLimit])
identityCommitments.push(identityCommitment) identityCommitments.push(identityCommitment)
rateCommitments.push(rateCommitment) rateCommitments.push(rateCommitment)
} }
let tree let tree
try { try {
tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, rateCommitments) // Binary tree. tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, rateCommitments) // Binary tree.
} catch (e) { } catch (e) {
@ -154,7 +154,7 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
externalNullifier: 0xa // hash(epoch, appId) externalNullifier: 0xa // hash(epoch, appId)
} }
const proof1 = await prove(signals1, wasm, wtns, r1cs, zkey_final, vKey) const proof1 = await prove(signals1, wasm, wtns, r1cs, zkey_final, vKey)
const signals2 = { const signals2 = {
identitySecret: secrets[0], identitySecret: secrets[0],
userMessageLimit, userMessageLimit,
@ -170,12 +170,12 @@ async function prove (signals, wasm, wtns, r1cs, zkey_final, vKey) {
console.log(secret.toString(10)) console.log(secret.toString(10))
console.log(Fq.normalize(secrets[0])) console.log(Fq.normalize(secrets[0]))
const templates = { const templates = {
plonk: await remix.call('fileManager', 'readFile', 'templates/plonk_verifier.sol.ejs') plonk: await remix.call('fileManager', 'readFile', 'templates/plonk_verifier.sol.ejs')
} }
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) 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/zk_verifier.sol', solidityContract)
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)

@ -40,13 +40,13 @@ const logger = {
console.log('exportVerificationKey') console.log('exportVerificationKey')
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final) 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', './zk/keys/groth16/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('save zkey_final') console.log('save zkey_final')
// @ts-ignore // @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', './zk/keys/groth16/zkey_final.txt', (zkey_final as any).data, { encoding: null })
console.log('setup done.') console.log('setup done.')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }

@ -33,33 +33,33 @@ function hash(message: any): bigint {
// @ts-ignore // @ts-ignore
const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/semaphore.wasm', true); const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/semaphore.wasm', true);
// @ts-ignore // @ts-ignore
const wasm = new Uint8Array(wasmBuffer); const wasm = new Uint8Array(wasmBuffer);
const zkey_final = { const zkey_final = {
type: "mem", type: "mem",
// @ts-ignore // @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', './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')) const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/groth16/verification_key.json'))
// build list of identity commitments // build list of identity commitments
const secrets = [] const secrets = []
const identityCommitments = [] 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 identityTrapdoor = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32)))
const identityNullifier = 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 secret = poseidon([identityNullifier, identityTrapdoor])
const identityCommitment = poseidon([secret]) const identityCommitment = poseidon([secret])
identityCommitments.push(identityCommitment) identityCommitments.push(identityCommitment)
} }
//console.log('incremental tree', identityCommitments.map((x) => x.toString())) //console.log('incremental tree', identityCommitments.map((x) => x.toString()))
let tree let tree
try { try {
tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, identityCommitments) // Binary tree. tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, identityCommitments) // Binary tree.
} catch (e) { } catch (e) {
@ -69,11 +69,11 @@ function hash(message: any): bigint {
const index = tree.indexOf(identityCommitments[0]) const index = tree.indexOf(identityCommitments[0])
console.log(index.toString()) console.log(index.toString())
const proof1 = tree.createProof(0) const proof1 = tree.createProof(0)
console.log('prepare signals for id ', identityCommitments[0].toString(), tree.indexOf(identityCommitments[0]), proof1.siblings.map((x)=> x.toString())) console.log('prepare signals for id ', identityCommitments[0].toString(), tree.indexOf(identityCommitments[0]), proof1.siblings.map((x)=> x.toString()))
const signals = { const signals = {
identityTrapdoor: secrets[0].identityTrapdoor, identityTrapdoor: secrets[0].identityTrapdoor,
identityNullifier: secrets[0].identityNullifier, identityNullifier: secrets[0].identityNullifier,
@ -82,16 +82,16 @@ function hash(message: any): bigint {
externalNullifier: hash(42), externalNullifier: hash(42),
signalHash: hash(ethers.utils.formatBytes32String("Hello World")) signalHash: hash(ethers.utils.formatBytes32String("Hello World"))
} }
console.log('calculate') console.log('calculate')
await snarkjs.wtns.calculate(signals, wasm, wtns); await snarkjs.wtns.calculate(signals, wasm, wtns);
console.log('check') console.log('check')
await snarkjs.wtns.check(r1cs, wtns, logger); await snarkjs.wtns.check(r1cs, wtns, logger);
console.log('prove') console.log('prove')
const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns); const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns);
const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger); const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified); console.log('zk proof validity', verified);
proof1.root.toString() === publicSignals[0] ? console.log('merkle proof valid') : console.log('merkle proof invalid') 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') groth16: await remix.call('fileManager', 'readFile', 'templates/groth16_verifier.sol.ejs')
} }
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) 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/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({ await remix.call('fileManager', 'writeFile', 'zk/build/groth16/input.json', JSON.stringify({
_pA: [proof.pi_a[0], proof.pi_a[1]], _pA: [proof.pi_a[0], proof.pi_a[1]],

@ -24,13 +24,13 @@ const logger = {
console.log('exportVerificationKey') console.log('exportVerificationKey')
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final) 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', './zk/keys/plonk/verification_key.json', JSON.stringify(vKey, null, 2))
console.log('save zkey_final') console.log('save zkey_final')
// @ts-ignore // @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', './zk/keys/plonk/zkey_final.txt', (zkey_final as any).data, { encoding: null })
console.log('setup done.') console.log('setup done.')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }

@ -33,33 +33,33 @@ function hash(message: any): bigint {
// @ts-ignore // @ts-ignore
const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/semaphore.wasm', true); const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/semaphore.wasm', true);
// @ts-ignore // @ts-ignore
const wasm = new Uint8Array(wasmBuffer); const wasm = new Uint8Array(wasmBuffer);
const zkey_final = { const zkey_final = {
type: "mem", type: "mem",
// @ts-ignore // @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', './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')) const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/keys/plonk/verification_key.json'))
// build list of identity commitments // build list of identity commitments
const secrets = [] const secrets = []
const identityCommitments = [] 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 identityTrapdoor = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32)))
const identityNullifier = 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 secret = poseidon([identityNullifier, identityTrapdoor])
const identityCommitment = poseidon([secret]) const identityCommitment = poseidon([secret])
identityCommitments.push(identityCommitment) identityCommitments.push(identityCommitment)
} }
//console.log('incremental tree', identityCommitments.map((x) => x.toString())) //console.log('incremental tree', identityCommitments.map((x) => x.toString()))
let tree let tree
try { try {
tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, identityCommitments) // Binary tree. tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, identityCommitments) // Binary tree.
} catch (e) { } catch (e) {
@ -69,11 +69,11 @@ function hash(message: any): bigint {
const index = tree.indexOf(identityCommitments[0]) const index = tree.indexOf(identityCommitments[0])
console.log(index.toString()) console.log(index.toString())
const proof1 = tree.createProof(0) const proof1 = tree.createProof(0)
console.log('prepare signals for id ', identityCommitments[0].toString(), tree.indexOf(identityCommitments[0]), proof1.siblings.map((x)=> x.toString())) console.log('prepare signals for id ', identityCommitments[0].toString(), tree.indexOf(identityCommitments[0]), proof1.siblings.map((x)=> x.toString()))
const signals = { const signals = {
identityTrapdoor: secrets[0].identityTrapdoor, identityTrapdoor: secrets[0].identityTrapdoor,
identityNullifier: secrets[0].identityNullifier, identityNullifier: secrets[0].identityNullifier,
@ -82,16 +82,16 @@ function hash(message: any): bigint {
externalNullifier: hash(42), externalNullifier: hash(42),
signalHash: hash(ethers.utils.formatBytes32String("Hello World")) signalHash: hash(ethers.utils.formatBytes32String("Hello World"))
} }
console.log('calculate') console.log('calculate')
await snarkjs.wtns.calculate(signals, wasm, wtns); await snarkjs.wtns.calculate(signals, wasm, wtns);
console.log('check') console.log('check')
await snarkjs.wtns.check(r1cs, wtns, logger); await snarkjs.wtns.check(r1cs, wtns, logger);
console.log('prove') console.log('prove')
const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns); const { proof, publicSignals } = await snarkjs.plonk.prove(zkey_final, wtns);
const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, logger); const verified = await snarkjs.plonk.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified); console.log('zk proof validity', verified);
proof1.root.toString() === publicSignals[0] ? console.log('merkle proof valid') : console.log('merkle proof invalid') 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') plonk: await remix.call('fileManager', 'readFile', 'templates/plonk_verifier.sol.ejs')
} }
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) 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/zk_verifier.sol', solidityContract)
await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({ await remix.call('fileManager', 'writeFile', 'zk/build/plonk/input.json', JSON.stringify({
_proof: [ _proof: [
@ -131,7 +131,7 @@ function hash(message: any): bigint {
], ],
_pubSignals: publicSignals _pubSignals: publicSignals
}, null, 2)) }, null, 2))
console.log('proof done.') console.log('proof done.')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)

@ -53,19 +53,19 @@ function hash(message: any): bigint {
console.log('exportVerificationKey') console.log('exportVerificationKey')
const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final) const vKey = await snarkjs.zKey.exportVerificationKey(zkey_final)
await remix.call('fileManager', 'writeFile', './zk/build/verification_key.json', JSON.stringify(vKey)) await remix.call('fileManager', 'writeFile', './zk/build/verification_key.json', JSON.stringify(vKey))
const templates = { const templates = {
groth16: await remix.call('fileManager', 'readFile', 'templates/groth16_verifier.sol.ejs') groth16: await remix.call('fileManager', 'readFile', 'templates/groth16_verifier.sol.ejs')
} }
const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates) const solidityContract = await snarkjs.zKey.exportSolidityVerifier(zkey_final, templates)
await remix.call('fileManager', 'writeFile', './zk/build/zk_verifier.sol', solidityContract) await remix.call('fileManager', 'writeFile', './zk/build/zk_verifier.sol', solidityContract)
console.log('buffer', (zkey_final as any).data.length) 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)))) await remix.call('fileManager', 'writeFile', './zk/build/zk_setup.txt', JSON.stringify(Array.from(((zkey_final as any).data))))
console.log('setup done.') console.log('setup done.')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }

@ -31,32 +31,32 @@ function hash(message: any): bigint {
// @ts-ignore // @ts-ignore
const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/semaphore.wasm', true); const wasmBuffer = await remix.call('fileManager', 'readFile', 'circuits/.bin/semaphore.wasm', true);
// @ts-ignore // @ts-ignore
const wasm = new Uint8Array(wasmBuffer); const wasm = new Uint8Array(wasmBuffer);
const zkey_final = { const zkey_final = {
type: "mem", type: "mem",
data: new Uint8Array(JSON.parse(await remix.call('fileManager', 'readFile', './zk/build/zk_setup.txt'))) 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')) const vKey = JSON.parse(await remix.call('fileManager', 'readFile', './zk/build/verification_key.json'))
// build list of identity commitments // build list of identity commitments
const secrets = [] const secrets = []
const identityCommitments = [] 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 identityTrapdoor = BigInt(ethers.utils.hexlify(ethers.utils.randomBytes(32)))
const identityNullifier = 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 secret = poseidon([identityNullifier, identityTrapdoor])
const identityCommitment = poseidon([secret]) const identityCommitment = poseidon([secret])
identityCommitments.push(identityCommitment) identityCommitments.push(identityCommitment)
} }
//console.log('incremental tree', identityCommitments.map((x) => x.toString())) //console.log('incremental tree', identityCommitments.map((x) => x.toString()))
let tree let tree
try { try {
tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, identityCommitments) // Binary tree. tree = new IncrementalMerkleTree(poseidon, 20, BigInt(0), 2, identityCommitments) // Binary tree.
} catch (e) { } catch (e) {
@ -66,11 +66,11 @@ function hash(message: any): bigint {
const index = tree.indexOf(identityCommitments[0]) const index = tree.indexOf(identityCommitments[0])
console.log(index.toString()) console.log(index.toString())
const proof1 = tree.createProof(0) const proof1 = tree.createProof(0)
console.log('prepare signals for id ', identityCommitments[0].toString(), tree.indexOf(identityCommitments[0]), proof1.siblings.map((x)=> x.toString())) console.log('prepare signals for id ', identityCommitments[0].toString(), tree.indexOf(identityCommitments[0]), proof1.siblings.map((x)=> x.toString()))
const signals = { const signals = {
identityTrapdoor: secrets[0].identityTrapdoor, identityTrapdoor: secrets[0].identityTrapdoor,
identityNullifier: secrets[0].identityNullifier, identityNullifier: secrets[0].identityNullifier,
@ -79,23 +79,20 @@ function hash(message: any): bigint {
externalNullifier: hash(42), externalNullifier: hash(42),
signalHash: hash(ethers.utils.formatBytes32String("Hello World")) signalHash: hash(ethers.utils.formatBytes32String("Hello World"))
} }
console.log('calculate') console.log('calculate')
await snarkjs.wtns.calculate(signals, wasm, wtns); await snarkjs.wtns.calculate(signals, wasm, wtns);
console.log('check') console.log('check')
await snarkjs.wtns.check(r1cs, wtns, logger); await snarkjs.wtns.check(r1cs, wtns, logger);
console.log('prove') console.log('prove')
const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns); const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns);
const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger); const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger);
console.log('zk proof validity', verified); console.log('zk proof validity', verified);
proof1.root.toString() === publicSignals[0] ? console.log('merkle proof valid') : console.log('merkle proof invalid') proof1.root.toString() === publicSignals[0] ? console.log('merkle proof valid') : console.log('merkle proof invalid')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }

@ -7,7 +7,7 @@ import { ethers } from 'ethers'
* @param {Number} accountIndex account index from the exposed account * @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract * @return {Contract} deployed contract
*/ */
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => { export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`) console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact. // 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<any>, accountInde
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object // 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) 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 // The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed() await contract.deployed()

@ -21,7 +21,7 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
const accounts = await web3.eth.getAccounts() 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({ const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object, data: metadata.data.bytecode.object,
@ -32,5 +32,5 @@ export const deploy = async (contractName: string, args: Array<any>, from?: stri
from: from || accounts[0], from: from || accounts[0],
gas: gas || 1500000 gas: gas || 1500000
}) })
return newContractInstance.options return newContractInstance.options
} }
Loading…
Cancel
Save