ccip_template
yann300 1 year ago
parent 41a4ebba14
commit bbe69aaf29
  1. 212
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/index.ts
  2. 24
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/0_compile_1.ts
  3. 24
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/0_compile_2.ts
  4. 24
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/0_compile_3.ts
  5. 24
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/0_compile_4.ts
  6. 88
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/1_deploy_semaphore.ts
  7. 102
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/2.1_addmembers.ts
  8. 38
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/2_create_groups.ts
  9. 76
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/3_store_groups.ts
  10. 40
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/helpers/convertsignal.ts
  11. 86
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/helpers/createProofForIdendity.ts
  12. 28
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/helpers/deploy.ts
  13. 20
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/helpers/packProof.ts
  14. 20
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/helpers/unpackProof.ts
  15. 14
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/manual operations/4.1_generate_proof_approve.ts
  16. 143
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/manual operations/4.5_generate_proof_with_trusted_setup.ts
  17. 18
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/manual operations/4_generate_proof_submit.ts
  18. 38
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/manual operations/5_verify_proof_on_chain.ts
  19. 24
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/manual operations/6_get_verified_proofs.ts
  20. 24
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/manual operations/7_generate_cids.ts
  21. 50
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/manual operations/7_hackergroup_events.ts
  22. 328
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/tests/hackerClient.test.ts
  23. 386
      libs/remix-ws-templates/src/templates/chainlink-ccip-semaphore/scripts/tests/hackergroup.test.ts

@ -1,110 +1,110 @@
export default async () => { export default async () => {
return { return {
// @ts-ignore // @ts-ignore
'.prettierrc': (await import('raw-loader!./.prettierrc')).default, '.prettierrc': (await import('raw-loader!./.prettierrc')).default,
// @ts-ignore // @ts-ignore
'README.md': (await import('raw-loader!./README.md')).default, 'README.md': (await import('raw-loader!./README.md')).default,
// @ts-ignore // @ts-ignore
'contracts/CCIP-BnM.sol': (await import('raw-loader!./contracts/CCIP-BnM.sol')).default, 'contracts/CCIP-BnM.sol': (await import('raw-loader!./contracts/CCIP-BnM.sol')).default,
// @ts-ignore // @ts-ignore
'contracts/IHackerGroup.sol': (await import('raw-loader!./contracts/IHackerGroup.sol')).default, 'contracts/IHackerGroup.sol': (await import('raw-loader!./contracts/IHackerGroup.sol')).default,
// @ts-ignore // @ts-ignore
'contracts/Link.sol': (await import('raw-loader!./contracts/Link.sol')).default, 'contracts/Link.sol': (await import('raw-loader!./contracts/Link.sol')).default,
// @ts-ignore // @ts-ignore
'contracts/Router.sol': (await import('raw-loader!./contracts/Router.sol')).default, 'contracts/Router.sol': (await import('raw-loader!./contracts/Router.sol')).default,
// @ts-ignore // @ts-ignore
'contracts/demo ccip contracts/Receiver.sol': (await import('raw-loader!./contracts/demo ccip contracts/Receiver.sol')).default, 'contracts/demo ccip contracts/Receiver.sol': (await import('raw-loader!./contracts/demo ccip contracts/Receiver.sol')).default,
// @ts-ignore // @ts-ignore
'contracts/demo ccip contracts/Sender.sol': (await import('raw-loader!./contracts/demo ccip contracts/Sender.sol')).default, 'contracts/demo ccip contracts/Sender.sol': (await import('raw-loader!./contracts/demo ccip contracts/Sender.sol')).default,
// @ts-ignore // @ts-ignore
'contracts/demo ccip contracts/transferToken.sol': (await import('raw-loader!./contracts/demo ccip contracts/transferToken.sol')).default, 'contracts/demo ccip contracts/transferToken.sol': (await import('raw-loader!./contracts/demo ccip contracts/transferToken.sol')).default,
// @ts-ignore // @ts-ignore
'contracts/hackerClient.sol': (await import('raw-loader!./contracts/hackerClient.sol')).default, 'contracts/hackerClient.sol': (await import('raw-loader!./contracts/hackerClient.sol')).default,
// @ts-ignore // @ts-ignore
'contracts/hackergroup.sol': (await import('raw-loader!./contracts/hackergroup.sol')).default, 'contracts/hackergroup.sol': (await import('raw-loader!./contracts/hackergroup.sol')).default,
// @ts-ignore // @ts-ignore
'data/group_id.json': (await import('./data/group_id.json.raw!=!raw-loader!./data/group_id.json')).default, 'data/group_id.json': (await import('./data/group_id.json.raw!=!raw-loader!./data/group_id.json')).default,
// @ts-ignore // @ts-ignore
'data/proof_approve.json': (await import('./data/proof_approve.json.raw!=!raw-loader!./data/proof_approve.json')).default, 'data/proof_approve.json': (await import('./data/proof_approve.json.raw!=!raw-loader!./data/proof_approve.json')).default,
// @ts-ignore // @ts-ignore
'data/proof_submit.json': (await import('./data/proof_submit.json.raw!=!raw-loader!./data/proof_submit.json')).default, 'data/proof_submit.json': (await import('./data/proof_submit.json.raw!=!raw-loader!./data/proof_submit.json')).default,
// @ts-ignore // @ts-ignore
'data/semaphore_deployment.json': (await import('./data/semaphore_deployment.json.raw!=!raw-loader!./data/semaphore_deployment.json')).default, 'data/semaphore_deployment.json': (await import('./data/semaphore_deployment.json.raw!=!raw-loader!./data/semaphore_deployment.json')).default,
// @ts-ignore // @ts-ignore
'index.ts': (await import('raw-loader!./index.ts')).default, 'index.ts': (await import('raw-loader!./index.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/0_compile_1.ts': (await import('raw-loader!./scripts/0_compile_1.ts')).default, 'scripts/0_compile_1.ts': (await import('raw-loader!./scripts/0_compile_1.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/0_compile_2.ts': (await import('raw-loader!./scripts/0_compile_2.ts')).default, 'scripts/0_compile_2.ts': (await import('raw-loader!./scripts/0_compile_2.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/0_compile_3.ts': (await import('raw-loader!./scripts/0_compile_3.ts')).default, 'scripts/0_compile_3.ts': (await import('raw-loader!./scripts/0_compile_3.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/0_compile_4.ts': (await import('raw-loader!./scripts/0_compile_4.ts')).default, 'scripts/0_compile_4.ts': (await import('raw-loader!./scripts/0_compile_4.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/1_deploy_semaphore.ts': (await import('raw-loader!./scripts/1_deploy_semaphore.ts')).default, 'scripts/1_deploy_semaphore.ts': (await import('raw-loader!./scripts/1_deploy_semaphore.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/2.1_addmembers.ts': (await import('raw-loader!./scripts/2.1_addmembers.ts')).default, 'scripts/2.1_addmembers.ts': (await import('raw-loader!./scripts/2.1_addmembers.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/2_create_groups.ts': (await import('raw-loader!./scripts/2_create_groups.ts')).default, 'scripts/2_create_groups.ts': (await import('raw-loader!./scripts/2_create_groups.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/3_store_groups.ts': (await import('raw-loader!./scripts/3_store_groups.ts')).default, 'scripts/3_store_groups.ts': (await import('raw-loader!./scripts/3_store_groups.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/helpers/convertsignal.ts': (await import('raw-loader!./scripts/helpers/convertsignal.ts')).default, 'scripts/helpers/convertsignal.ts': (await import('raw-loader!./scripts/helpers/convertsignal.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/helpers/createProofForIdendity.ts': (await import('raw-loader!./scripts/helpers/createProofForIdendity.ts')).default, 'scripts/helpers/createProofForIdendity.ts': (await import('raw-loader!./scripts/helpers/createProofForIdendity.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/helpers/deploy.ts': (await import('raw-loader!./scripts/helpers/deploy.ts')).default, 'scripts/helpers/deploy.ts': (await import('raw-loader!./scripts/helpers/deploy.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/helpers/packProof.ts': (await import('raw-loader!./scripts/helpers/packProof.ts')).default, 'scripts/helpers/packProof.ts': (await import('raw-loader!./scripts/helpers/packProof.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/helpers/unpackProof.ts': (await import('raw-loader!./scripts/helpers/unpackProof.ts')).default, 'scripts/helpers/unpackProof.ts': (await import('raw-loader!./scripts/helpers/unpackProof.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/manual operations/4.1_generate_proof_approve.ts': (await import('raw-loader!./scripts/manual operations/4.1_generate_proof_approve.ts')).default, 'scripts/manual operations/4.1_generate_proof_approve.ts': (await import('raw-loader!./scripts/manual operations/4.1_generate_proof_approve.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/manual operations/4.5_generate_proof_with_trusted_setup.ts': (await import('raw-loader!./scripts/manual operations/4.5_generate_proof_with_trusted_setup.ts')).default, 'scripts/manual operations/4.5_generate_proof_with_trusted_setup.ts': (await import('raw-loader!./scripts/manual operations/4.5_generate_proof_with_trusted_setup.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/manual operations/4_generate_proof_submit.ts': (await import('raw-loader!./scripts/manual operations/4_generate_proof_submit.ts')).default, 'scripts/manual operations/4_generate_proof_submit.ts': (await import('raw-loader!./scripts/manual operations/4_generate_proof_submit.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/manual operations/5_verify_proof_on_chain.ts': (await import('raw-loader!./scripts/manual operations/5_verify_proof_on_chain.ts')).default, 'scripts/manual operations/5_verify_proof_on_chain.ts': (await import('raw-loader!./scripts/manual operations/5_verify_proof_on_chain.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/manual operations/6_get_verified_proofs.ts': (await import('raw-loader!./scripts/manual operations/6_get_verified_proofs.ts')).default, 'scripts/manual operations/6_get_verified_proofs.ts': (await import('raw-loader!./scripts/manual operations/6_get_verified_proofs.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/manual operations/7_generate_cids.ts': (await import('raw-loader!./scripts/manual operations/7_generate_cids.ts')).default, 'scripts/manual operations/7_generate_cids.ts': (await import('raw-loader!./scripts/manual operations/7_generate_cids.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/manual operations/7_hackergroup_events.ts': (await import('raw-loader!./scripts/manual operations/7_hackergroup_events.ts')).default, 'scripts/manual operations/7_hackergroup_events.ts': (await import('raw-loader!./scripts/manual operations/7_hackergroup_events.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/tests/hackerClient.test.ts': (await import('raw-loader!./scripts/tests/hackerClient.test.ts')).default, 'scripts/tests/hackerClient.test.ts': (await import('raw-loader!./scripts/tests/hackerClient.test.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/tests/hackergroup.test.ts': (await import('raw-loader!./scripts/tests/hackergroup.test.ts')).default, 'scripts/tests/hackergroup.test.ts': (await import('raw-loader!./scripts/tests/hackergroup.test.ts')).default,
// @ts-ignore // @ts-ignore
'scripts/types/types.ts': (await import('raw-loader!./scripts/types/types.ts')).default, 'scripts/types/types.ts': (await import('raw-loader!./scripts/types/types.ts')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/README.md': (await import('raw-loader!./semaphore/contracts/README.md')).default, 'semaphore/contracts/README.md': (await import('raw-loader!./semaphore/contracts/README.md')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/Semaphore.sol': (await import('raw-loader!./semaphore/contracts/Semaphore.sol')).default, 'semaphore/contracts/Semaphore.sol': (await import('raw-loader!./semaphore/contracts/Semaphore.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/artifacts/Semaphore.json': (await import('./semaphore/contracts/artifacts/Semaphore.json.raw!=!raw-loader!./semaphore/contracts/artifacts/Semaphore.json')).default, 'semaphore/contracts/artifacts/Semaphore.json': (await import('./semaphore/contracts/artifacts/Semaphore.json.raw!=!raw-loader!./semaphore/contracts/artifacts/Semaphore.json')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/artifacts/Semaphore_metadata.json': (await import('./semaphore/contracts/artifacts/Semaphore_metadata.json.raw!=!raw-loader!./semaphore/contracts/artifacts/Semaphore_metadata.json')).default, 'semaphore/contracts/artifacts/Semaphore_metadata.json': (await import('./semaphore/contracts/artifacts/Semaphore_metadata.json.raw!=!raw-loader!./semaphore/contracts/artifacts/Semaphore_metadata.json')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/base/Pairing.sol': (await import('raw-loader!./semaphore/contracts/base/Pairing.sol')).default, 'semaphore/contracts/base/Pairing.sol': (await import('raw-loader!./semaphore/contracts/base/Pairing.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/base/SemaphoreGroups.sol': (await import('raw-loader!./semaphore/contracts/base/SemaphoreGroups.sol')).default, 'semaphore/contracts/base/SemaphoreGroups.sol': (await import('raw-loader!./semaphore/contracts/base/SemaphoreGroups.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/base/SemaphoreVerifier.sol': (await import('raw-loader!./semaphore/contracts/base/SemaphoreVerifier.sol')).default, 'semaphore/contracts/base/SemaphoreVerifier.sol': (await import('raw-loader!./semaphore/contracts/base/SemaphoreVerifier.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/extensions/SemaphoreVoting.sol': (await import('raw-loader!./semaphore/contracts/extensions/SemaphoreVoting.sol')).default, 'semaphore/contracts/extensions/SemaphoreVoting.sol': (await import('raw-loader!./semaphore/contracts/extensions/SemaphoreVoting.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/extensions/SemaphoreWhistleblowing.sol': (await import('raw-loader!./semaphore/contracts/extensions/SemaphoreWhistleblowing.sol')).default, 'semaphore/contracts/extensions/SemaphoreWhistleblowing.sol': (await import('raw-loader!./semaphore/contracts/extensions/SemaphoreWhistleblowing.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/interfaces/ISemaphore.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphore.sol')).default, 'semaphore/contracts/interfaces/ISemaphore.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphore.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/interfaces/ISemaphoreGroups.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphoreGroups.sol')).default, 'semaphore/contracts/interfaces/ISemaphoreGroups.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphoreGroups.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/interfaces/ISemaphoreVerifier.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphoreVerifier.sol')).default, 'semaphore/contracts/interfaces/ISemaphoreVerifier.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphoreVerifier.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/interfaces/ISemaphoreVoting.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphoreVoting.sol')).default, 'semaphore/contracts/interfaces/ISemaphoreVoting.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphoreVoting.sol')).default,
// @ts-ignore // @ts-ignore
'semaphore/contracts/interfaces/ISemaphoreWhistleblowing.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphoreWhistleblowing.sol')).default 'semaphore/contracts/interfaces/ISemaphoreWhistleblowing.sol': (await import('raw-loader!./semaphore/contracts/interfaces/ISemaphoreWhistleblowing.sol')).default
} }
} }

@ -1,15 +1,15 @@
;(async () => { ;(async () => {
try { try {
remix.off('solidity', 'compilationFinished') remix.off('solidity', 'compilationFinished')
const params = { const params = {
optimize: true, optimize: true,
runs: 200, runs: 200,
language: 'Solidity', language: 'Solidity',
version: '0.8.4+commit.c7e474f2', version: '0.8.4+commit.c7e474f2',
}
await remix.call('solidity', 'setCompilerConfig', params as any)
await remix.call('solidity', 'compile' as any, 'semaphore/contracts/Semaphore.sol')
}catch(e){
console.log(e.message)
} }
await remix.call('solidity', 'setCompilerConfig', params as any)
await remix.call('solidity', 'compile' as any, 'semaphore/contracts/Semaphore.sol')
}catch(e){
console.log(e.message)
}
})() })()

@ -1,15 +1,15 @@
;(async () => { ;(async () => {
try { try {
remix.off('solidity', 'compilationFinished') remix.off('solidity', 'compilationFinished')
const params = { const params = {
optimize: true, optimize: true,
runs: 200, runs: 200,
language: 'Solidity', language: 'Solidity',
version: '0.8.4+commit.c7e474f2', version: '0.8.4+commit.c7e474f2',
}
await remix.call('solidity', 'setCompilerConfig', params as any)
await remix.call('solidity', 'compile' as any, 'semaphore/contracts/base/SemaphoreVerifier.sol')
}catch(e){
console.log(e.message)
} }
await remix.call('solidity', 'setCompilerConfig', params as any)
await remix.call('solidity', 'compile' as any, 'semaphore/contracts/base/SemaphoreVerifier.sol')
}catch(e){
console.log(e.message)
}
})() })()

@ -1,15 +1,15 @@
;(async () => { ;(async () => {
try { try {
remix.off('solidity', 'compilationFinished') remix.off('solidity', 'compilationFinished')
const params = { const params = {
optimize: true, optimize: true,
runs: 200, runs: 200,
language: 'Solidity', language: 'Solidity',
version: '0.8.4+commit.c7e474f2', version: '0.8.4+commit.c7e474f2',
}
await remix.call('solidity', 'setCompilerConfig', params as any)
await remix.call('solidity', 'compile' as any, 'contracts/hackerClient.sol')
}catch(e){
console.log(e.message)
} }
await remix.call('solidity', 'setCompilerConfig', params as any)
await remix.call('solidity', 'compile' as any, 'contracts/hackerClient.sol')
}catch(e){
console.log(e.message)
}
})() })()

@ -1,15 +1,15 @@
;(async () => { ;(async () => {
try { try {
remix.off('solidity', 'compilationFinished') remix.off('solidity', 'compilationFinished')
const params = { const params = {
optimize: true, optimize: true,
runs: 200, runs: 200,
language: 'Solidity', language: 'Solidity',
version: '0.8.4+commit.c7e474f2', version: '0.8.4+commit.c7e474f2',
}
await remix.call('solidity', 'setCompilerConfig', params as any)
await remix.call('solidity', 'compile' as any, 'contracts/hackergroup.sol')
}catch(e){
console.log(e.message)
} }
await remix.call('solidity', 'setCompilerConfig', params as any)
await remix.call('solidity', 'compile' as any, 'contracts/hackergroup.sol')
}catch(e){
console.log(e.message)
}
})() })()

@ -1,47 +1,47 @@
import { deploy } from './helpers/deploy' import { deploy } from './helpers/deploy'
;(async () => { ;(async () => {
try { try {
const pairing = await deploy('Pairing', []) const pairing = await deploy('Pairing', [])
console.log(pairing.address) console.log(pairing.address)
const verifier = await deploy('SemaphoreVerifier', [], { const verifier = await deploy('SemaphoreVerifier', [], {
Pairing: pairing.address, Pairing: pairing.address,
}) })
const verifierAddress = verifier.address const verifierAddress = verifier.address
const poseidonT3 = await deploy('PoseidonT3', []) const poseidonT3 = await deploy('PoseidonT3', [])
console.log('PoseidonT3 at', poseidonT3.address) console.log('PoseidonT3 at', poseidonT3.address)
const incrementalBinaryTree = await deploy('IncrementalBinaryTree', [], { const incrementalBinaryTree = await deploy('IncrementalBinaryTree', [], {
'poseidon-solidity/PoseidonT3.sol:PoseidonT3': poseidonT3.address, 'poseidon-solidity/PoseidonT3.sol:PoseidonT3': poseidonT3.address,
}) })
console.log('IncrementalBinaryTree at', incrementalBinaryTree.address) console.log('IncrementalBinaryTree at', incrementalBinaryTree.address)
if (!verifierAddress) throw new Error("verifier address shouldn't be null, the semaphore needs it...") if (!verifierAddress) throw new Error("verifier address shouldn't be null, the semaphore needs it...")
const semaphore = await deploy('Semaphore', [verifierAddress], { const semaphore = await deploy('Semaphore', [verifierAddress], {
IncrementalBinaryTree: incrementalBinaryTree.address, IncrementalBinaryTree: incrementalBinaryTree.address,
}) })
console.log('Semaphore addres: ', semaphore.address) console.log('Semaphore addres: ', semaphore.address)
await remix.call( await remix.call(
'fileManager', 'fileManager',
'setFile', 'setFile',
'./data/semaphore_deployment.json', './data/semaphore_deployment.json',
JSON.stringify( JSON.stringify(
{ {
semaphoreAddress: semaphore.address, semaphoreAddress: semaphore.address,
verifierAddress, verifierAddress,
}, },
null, null,
'\t', '\t',
), ),
) )
await remix.call('solidity', 'compile' as any, 'contracts/hackergroup.sol') await remix.call('solidity', 'compile' as any, 'contracts/hackergroup.sol')
await remix.call('solidity', 'compile' as any, 'contracts/hackerClient.sol') await remix.call('solidity', 'compile' as any, 'contracts/hackerClient.sol')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }
})() })()

@ -6,72 +6,72 @@ const identities = []
const commmitments = [] const commmitments = []
const addMembers = async (sempahore_contract_address: any, admin: any, group_id: any, members: string[]) => { const addMembers = async (sempahore_contract_address: any, admin: any, group_id: any, members: string[]) => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer) const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer)
console.log('adding members to group', sempahore_contract_address, group_id, members) console.log('adding members to group', sempahore_contract_address, group_id, members)
await contract['addMembers(uint256,uint256[])'](group_id.toString(), members) await contract['addMembers(uint256,uint256[])'](group_id.toString(), members)
console.log('members added') console.log('members added')
} }
const verifyMemberCount = async (sempahore_contract_address: any, admin: any, group_id: number, memberCount: number) => { const verifyMemberCount = async (sempahore_contract_address: any, admin: any, group_id: number, memberCount: number) => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer) const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer)
console.log('counting members in group') console.log('counting members in group')
const count = await contract.getNumberOfMerkleTreeLeaves(group_id) const count = await contract.getNumberOfMerkleTreeLeaves(group_id)
if (memberCount !== count.toNumber()) { if (memberCount !== count.toNumber()) {
console.error('Members not added') console.error('Members not added')
} else { } else {
console.log('Members added correctly') console.log('Members added correctly')
} }
} }
;(async () => { ;(async () => {
try { try {
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
console.log(semaphore_deployment_data.semaphoreAddress) console.log(semaphore_deployment_data.semaphoreAddress)
const admin = await signer.getAddress() const admin = await signer.getAddress()
const sempahore_contract_address = semaphore_deployment_data.semaphoreAddress const sempahore_contract_address = semaphore_deployment_data.semaphoreAddress
// get group id from file // get group id from file
const group_id = JSON.parse(await remix.call('fileManager', 'readFile', 'data/group_id.json')).group_id.hex.toString() const group_id = JSON.parse(await remix.call('fileManager', 'readFile', 'data/group_id.json')).group_id.hex.toString()
//console.log(group_id.hex.toString()) //console.log(group_id.hex.toString())
//return //return
// create some random identities // create some random identities
for (let i = 0; i <= 1; i++) { for (let i = 0; i <= 1; i++) {
const identity = new Identity() const identity = new Identity()
const { trapdoor, nullifier, commitment } = identity const { trapdoor, nullifier, commitment } = identity
identities.push({ identities.push({
trapdoor: trapdoor.toString(), trapdoor: trapdoor.toString(),
nullifier: nullifier.toString(), nullifier: nullifier.toString(),
commitment: commitment.toString(), commitment: commitment.toString(),
data: identity.toString(), data: identity.toString(),
group_id, group_id,
}) })
commmitments.push(commitment.toString()) commmitments.push(commitment.toString())
} }
// store them so we can use them in our dApp, it contains secrets, not for production use // store them so we can use them in our dApp, it contains secrets, not for production use
await remix.call('fileManager', 'setFile', './build/identities.json', JSON.stringify(identities, null, '\t')) await remix.call('fileManager', 'setFile', './build/identities.json', JSON.stringify(identities, null, '\t'))
// add them all to the group // add them all to the group
const r = await addMembers(sempahore_contract_address, admin, group_id, commmitments) const r = await addMembers(sempahore_contract_address, admin, group_id, commmitments)
setTimeout( setTimeout(
async () => async () =>
// verify we added them // verify we added them
await verifyMemberCount(sempahore_contract_address, admin, group_id, commmitments.length), await verifyMemberCount(sempahore_contract_address, admin, group_id, commmitments.length),
20000, 20000,
) )
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }
})() })()

@ -5,32 +5,32 @@ const identities = []
const commmitments = [] const commmitments = []
const createGroup = async (sempahore_contract_address: any, admin: any, group_id: number) => { const createGroup = async (sempahore_contract_address: any, admin: any, group_id: number) => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer) const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer)
console.log('creating semaphore group') console.log('creating semaphore group')
await contract['createGroup(uint256,uint256,address)'](group_id, '20', admin) await contract['createGroup(uint256,uint256,address)'](group_id, '20', admin)
console.log('group created ', group_id) console.log('group created ', group_id)
} }
;(async () => { ;(async () => {
try { try {
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
console.log(semaphore_deployment_data.semaphoreAddress) console.log(semaphore_deployment_data.semaphoreAddress)
const admin = await signer.getAddress() const admin = await signer.getAddress()
const sempahore_contract_address = semaphore_deployment_data.semaphoreAddress const sempahore_contract_address = semaphore_deployment_data.semaphoreAddress
// create a new group in Semaphore // create a new group in Semaphore
const group_id = ethers.BigNumber.from(ethers.utils.randomBytes(32)) const group_id = ethers.BigNumber.from(ethers.utils.randomBytes(32))
await createGroup(sempahore_contract_address, admin, group_id) await createGroup(sempahore_contract_address, admin, group_id)
await remix.call('fileManager', 'setFile', './data/group_id.json', JSON.stringify({group_id}, null, '\t')) await remix.call('fileManager', 'setFile', './data/group_id.json', JSON.stringify({group_id}, null, '\t'))
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }
})() })()

@ -1,58 +1,58 @@
import { ethers, BigNumber } from 'ethers' import { ethers, BigNumber } from 'ethers'
import { ISemaphoreDeploymentData, IGroup, IGroupMember } from './types/types' import { ISemaphoreDeploymentData, IGroup, IGroupMember } from './types/types'
;(async () => { ;(async () => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
console.log(await signer.getAddress()) console.log(await signer.getAddress())
const signerAddress = await signer.getAddress() const signerAddress = await signer.getAddress()
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const contract = await ethers.getContractAt('Semaphore', semaphore_deployment_data.semaphoreAddress, signer) const contract = await ethers.getContractAt('Semaphore', semaphore_deployment_data.semaphoreAddress, signer)
//console.log(contract.filters) //console.log(contract.filters)
let eventFilter = contract.filters.GroupCreated() let eventFilter = contract.filters.GroupCreated()
let groupsCreated = await contract.queryFilter(eventFilter) const groupsCreated = await contract.queryFilter(eventFilter)
const groupIds: any = [] const groupIds: any = []
for (let groupCreated of groupsCreated) { for (const groupCreated of groupsCreated) {
console.log(groupCreated) console.log(groupCreated)
const group = await contract.groups(groupCreated.args[0]) const group = await contract.groups(groupCreated.args[0])
if (group[0] == signerAddress) { if (group[0] == signerAddress) {
console.log('found group belonging to ' + signerAddress + 'group id ' + groupCreated.args[0]) console.log('found group belonging to ' + signerAddress + 'group id ' + groupCreated.args[0])
groupIds.push(groupCreated.args[0]) groupIds.push(groupCreated.args[0])
}
} }
}
eventFilter = contract.filters.MemberAdded() eventFilter = contract.filters.MemberAdded()
let membersAdded = await contract.queryFilter(eventFilter) const membersAdded = await contract.queryFilter(eventFilter)
const groups: IGroup[] = [] const groups: IGroup[] = []
for (let groupId of groupIds) { for (const groupId of groupIds) {
console.log('checking group members of group ' + groupId) console.log('checking group members of group ' + groupId)
const group: IGroup = { const group: IGroup = {
group_id: groupId.toString(), group_id: groupId.toString(),
members: [], members: [],
} }
for (let member of membersAdded) {
if (member.args[0].toHexString() == BigNumber.from(groupId).toHexString()) {
console.log('found member ')
console.log(member.args[2].toString())
group.members.push(member.args[2].toString())
}
}
groups.push(group) for (const member of membersAdded) {
if (member.args[0].toHexString() == BigNumber.from(groupId).toHexString()) {
console.log('found member ')
console.log(member.args[2].toString())
group.members.push(member.args[2].toString())
}
} }
console.log('groups:') groups.push(group)
console.log(groups) }
console.log('groups:')
console.log(groups)
await remix.call('fileManager', 'setFile', './build/groups.json', JSON.stringify(groups, null, '\t')) await remix.call('fileManager', 'setFile', './build/groups.json', JSON.stringify(groups, null, '\t'))
})() })()

@ -2,27 +2,27 @@ import * as multihash from 'multihashes'
import { BigNumber, utils } from 'ethers' import { BigNumber, utils } from 'ethers'
export const SignalToBigNumber = (message: string) => { export const SignalToBigNumber = (message: string) => {
// ************************************************************** // **************************************************************
// **************** Convert CID to Big Number *************** // **************** Convert CID to Big Number ***************
const tmpArray = multihash.fromB58String(message) const tmpArray = multihash.fromB58String(message)
const b58decoded = multihash.decode(tmpArray).digest const b58decoded = multihash.decode(tmpArray).digest
const tmpHexStr = utils.hexlify(b58decoded) const tmpHexStr = utils.hexlify(b58decoded)
const signal = BigNumber.from(tmpHexStr, 16).toString() const signal = BigNumber.from(tmpHexStr, 16).toString()
return signal return signal
} }
export const BigNumberToSignal = (signal: string) => { export const BigNumberToSignal = (signal: string) => {
// ************************************************************** // **************************************************************
// Convert the signal back to the original CID // Convert the signal back to the original CID
const tmpBNtoHex = utils.hexlify( const tmpBNtoHex = utils.hexlify(
BigNumber.from(signal) BigNumber.from(signal)
); );
const tmpHextoBytes = utils.arrayify(tmpBNtoHex); const tmpHextoBytes = utils.arrayify(tmpBNtoHex);
const tmpBytestoArr = multihash.encode(tmpHextoBytes, "sha2-256"); const tmpBytestoArr = multihash.encode(tmpHextoBytes, "sha2-256");
const mhBuf = multihash.encode(tmpBytestoArr, "sha2-256"); const mhBuf = multihash.encode(tmpBytestoArr, "sha2-256");
const decodedBuf = multihash.decode(mhBuf); const decodedBuf = multihash.decode(mhBuf);
const encodedStr = multihash.toB58String(decodedBuf.digest); const encodedStr = multihash.toB58String(decodedBuf.digest);
console.log("Recovered CID Value: ", encodedStr); console.log("Recovered CID Value: ", encodedStr);
return encodedStr return encodedStr
// ************************************************************** // **************************************************************
} }

@ -6,66 +6,66 @@ import { SignalToBigNumber } from '../helpers/convertsignal'
import { IIdentity, SemaphoreProof } from '../types/types' import { IIdentity, SemaphoreProof } from '../types/types'
export const createProofForIdendity = async (_cid: string, _signal: string, writeProof: boolean = true, _prooffile?: string, _commitment?: any): Promise<SemaphoreProof> => { export const createProofForIdendity = async (_cid: string, _signal: string, writeProof: boolean = true, _prooffile?: string, _commitment?: any): Promise<SemaphoreProof> => {
if (!_signal || !_cid) throw new Error('message and topic not set') if (!_signal || !_cid) throw new Error('message and topic not set')
const topic = _cid const topic = _cid
const preSignal = _signal const preSignal = _signal
console.log('topic', topic) console.log('topic', topic)
console.log('message', preSignal) console.log('message', preSignal)
// get the idendity // get the idendity
const identities: IIdentity[] = JSON.parse(await remix.call('fileManager', 'readFile', './build/identities.json')) const identities: IIdentity[] = JSON.parse(await remix.call('fileManager', 'readFile', './build/identities.json'))
console.log('using identity... ') console.log('using identity... ')
const id = identities.find((i) => i.commitment == _commitment) const id = identities.find((i) => i.commitment == _commitment)
let identity: Identity let identity: Identity
if (id) { if (id) {
identity = new Identity(id.data) identity = new Identity(id.data)
} else { } else {
identity = new Identity(identities[0].data) identity = new Identity(identities[0].data)
} }
console.log(identity.commitment.toString()) console.log(identity.commitment.toString())
// construct the group // construct the group
const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json')) const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json'))
const group_with_member = groups.find((g) => { const group_with_member = groups.find((g) => {
return g.members.includes(identity.commitment.toString()) return g.members.includes(identity.commitment.toString())
}) })
console.log('found group ... ') console.log('found group ... ')
console.log(group_with_member) console.log(group_with_member)
/* reconstruct the group to use in the Sempaphore proof /* reconstruct the group to use in the Sempaphore proof
/ this will also create the merkle tree internally in the grouo / this will also create the merkle tree internally in the grouo
/ but you will need to have all the members to do this / but you will need to have all the members to do this
*/ */
const group = new Group(group_with_member.group_id, 20, group_with_member.members) const group = new Group(group_with_member.group_id, 20, group_with_member.members)
const signal = preSignal const signal = preSignal
const externalNullifier = SignalToBigNumber(topic) const externalNullifier = SignalToBigNumber(topic)
console.log('Creating proof with semaphore') console.log('Creating proof with semaphore')
/* this was & zkey was taken from https://www.trusted-setup-pse.org/ for a tree depth of 20 only!! /* this was & zkey was taken from https://www.trusted-setup-pse.org/ for a tree depth of 20 only!!
/ generate your own zkeys and wasm files or store them on IPFS / generate your own zkeys and wasm files or store them on IPFS
/ the snarkjs implementation that drives this function needs a URL withour CORS limitations, that is why we use IPFS / the snarkjs implementation that drives this function needs a URL withour CORS limitations, that is why we use IPFS
*/ */
const fullProof: SemaphoreProof = await generateProof(identity, group, externalNullifier, signal, { const fullProof: SemaphoreProof = await generateProof(identity, group, externalNullifier, signal, {
zkeyFilePath: 'https://ipfs-cluster.ethdevops.io/ipfs/QmYQU3F6MpxhwAjGLMrcf7Xt2u5PyuS1wrV1Upy1M8xGhL', zkeyFilePath: 'https://ipfs-cluster.ethdevops.io/ipfs/QmYQU3F6MpxhwAjGLMrcf7Xt2u5PyuS1wrV1Upy1M8xGhL',
wasmFilePath: 'https://ipfs-cluster.ethdevops.io/ipfs/QmQ8oN5nydG5MwQtxZBVUW5b3E2n41kcbXYUi9wPLFEfqq', wasmFilePath: 'https://ipfs-cluster.ethdevops.io/ipfs/QmQ8oN5nydG5MwQtxZBVUW5b3E2n41kcbXYUi9wPLFEfqq',
}) })
console.log('Proof created') console.log('Proof created')
console.log(JSON.stringify(fullProof, null, '\t')) console.log(JSON.stringify(fullProof, null, '\t'))
// write it to the filesystem // write it to the filesystem
if (writeProof) { if (writeProof) {
await remix.call('fileManager', 'setFile', _prooffile || './build/proof.json', JSON.stringify({fullProof, group_id: group_with_member.group_id}, null, '\t')) await remix.call('fileManager', 'setFile', _prooffile || './build/proof.json', JSON.stringify({fullProof, group_id: group_with_member.group_id}, null, '\t'))
} }
console.log('verifying proof off chain...') console.log('verifying proof off chain...')
const result = await verifyProof(fullProof, 20) const result = await verifyProof(fullProof, 20)
console.log(result) console.log(result)
return fullProof return fullProof
} }

@ -7,24 +7,24 @@ import { ethers } from 'ethers'
* @return {Contract} deployed contract * @return {Contract} deployed contract
*/ */
export const deploy = async ( export const deploy = async (
contractName: string, contractName: string,
args: Array<any>, args: Array<any>,
libraries?: { [key: string]: any }, libraries?: { [key: string]: any },
): Promise<ethers.Contract> => { ): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`) console.log(`deploying ${contractName}`)
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
// internal Remix method that resolves the artifacts and links the libraries // internal Remix method that resolves the artifacts and links the libraries
let factory = await ethers.getContractFactory(contractName as any, null, { const factory = await ethers.getContractFactory(contractName as any, null, {
signer, signer,
libraries, libraries,
} as any) } as any)
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()
return contract return contract
} }

@ -6,14 +6,14 @@ import { SnarkJSProof, Proof } from "@semaphore-protocol/proof"
* @returns The proof compatible with Semaphore. * @returns The proof compatible with Semaphore.
*/ */
export default function packProof(originalProof: SnarkJSProof): Proof { export default function packProof(originalProof: SnarkJSProof): Proof {
return [ return [
originalProof.pi_a[0], originalProof.pi_a[0],
originalProof.pi_a[1], originalProof.pi_a[1],
originalProof.pi_b[0][1], originalProof.pi_b[0][1],
originalProof.pi_b[0][0], originalProof.pi_b[0][0],
originalProof.pi_b[1][1], originalProof.pi_b[1][1],
originalProof.pi_b[1][0], originalProof.pi_b[1][0],
originalProof.pi_c[0], originalProof.pi_c[0],
originalProof.pi_c[1] originalProof.pi_c[1]
] ]
} }

@ -6,14 +6,14 @@ import { SnarkJSProof, Proof } from "@semaphore-protocol/proof"
* @returns The proof compatible with SnarkJS. * @returns The proof compatible with SnarkJS.
*/ */
export default function unpackProof(proof: Proof): SnarkJSProof { export default function unpackProof(proof: Proof): SnarkJSProof {
return { return {
pi_a: [proof[0], proof[1]], pi_a: [proof[0], proof[1]],
pi_b: [ pi_b: [
[proof[3], proof[2]], [proof[3], proof[2]],
[proof[5], proof[4]] [proof[5], proof[4]]
], ],
pi_c: [proof[6], proof[7]], pi_c: [proof[6], proof[7]],
protocol: "groth16", protocol: "groth16",
curve: "bn128" curve: "bn128"
} }
} }

@ -3,12 +3,12 @@ import { SemaphoreProof } from './types/types'
import { ethers } from 'ethers' import { ethers } from 'ethers'
import { BigNumberToSignal } from './helpers/convertsignal' import { BigNumberToSignal } from './helpers/convertsignal'
;(async () => { ;(async () => {
try { try {
const cid = await remix.call('fileManager', 'readFile', './build/cid_submit.txt') const cid = await remix.call('fileManager', 'readFile', './build/cid_submit.txt')
console.log('cid', cid) console.log('cid', cid)
const proof: SemaphoreProof = await createProofForIdendity(cid, '1', true, '/data/proof_approve.json', '9756501288174340008630509738020211027723632351628960927627754250562315251706') const proof: SemaphoreProof = await createProofForIdendity(cid, '1', true, '/data/proof_approve.json', '9756501288174340008630509738020211027723632351628960927627754250562315251706')
} catch (e) { } catch (e) {
console.log(e.message) console.log(e.message)
} }
})() })()

@ -1,6 +1,7 @@
import { ethers, BigNumber } from 'ethers' import { ethers, BigNumber } from 'ethers'
import { IncrementalMerkleTree } from '@zk-kit/incremental-merkle-tree' import { IncrementalMerkleTree } from '@zk-kit/incremental-merkle-tree'
import { poseidon } from 'circomlibjs' // v0.0.8 import { poseidon } from 'circomlibjs' // v0.0.8
// eslint-disable-next-line @typescript-eslint/no-var-requires
const snarkjs = require('snarkjs') const snarkjs = require('snarkjs')
import { Identity } from '@semaphore-protocol/identity' import { Identity } from '@semaphore-protocol/identity'
import { generateProof, verifyProof } from '@semaphore-protocol/proof' import { generateProof, verifyProof } from '@semaphore-protocol/proof'
@ -9,9 +10,9 @@ import packProof from './packProof'
import { Group } from '@semaphore-protocol/group' import { Group } from '@semaphore-protocol/group'
const logger = { const logger = {
info: (...args) => console.log(...args), info: (...args) => console.log(...args),
debug: (...args) => console.log(...args), debug: (...args) => console.log(...args),
error: (...args) => console.error(...args), error: (...args) => console.error(...args),
} }
/** /**
@ -20,97 +21,97 @@ const logger = {
* @returns The message digest. * @returns The message digest.
*/ */
function hash(message: any): bigint { function hash(message: any): bigint {
message = BigNumber.from(message).toTwos(256).toHexString() message = BigNumber.from(message).toTwos(256).toHexString()
message = ethers.utils.zeroPad(message, 32) message = ethers.utils.zeroPad(message, 32)
return BigInt(ethers.utils.keccak256(message)) >> BigInt(8) return BigInt(ethers.utils.keccak256(message)) >> BigInt(8)
} }
;(async () => { ;(async () => {
try { try {
const topic = 'some topic' const topic = 'some topic'
const message = 'I vote yes' const message = 'I vote yes'
// get the first group from the file // get the first group from the file
const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json')) const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json'))
const group = new Group(groups[0].group_id, 20, groups[0].members) const group = new Group(groups[0].group_id, 20, groups[0].members)
// create idendity from the first member of the group // create idendity from the first member of the group
const identities = JSON.parse(await remix.call('fileManager', 'readFile', './build/identities.json')) const identities = JSON.parse(await remix.call('fileManager', 'readFile', './build/identities.json'))
console.log('using identity... ') console.log('using identity... ')
console.log(identities[0].commitment) console.log(identities[0].commitment)
const identity = new Identity(identities[0].data) const identity = new Identity(identities[0].data)
const signal = utils.formatBytes32String(message) const signal = utils.formatBytes32String(message)
const externalNullifier = utils.formatBytes32String(topic) const externalNullifier = utils.formatBytes32String(topic)
// USE ZK TRUSTED SETUP // USE ZK TRUSTED SETUP
const r1cs = 'https://ipfs-cluster.ethdevops.io/ipfs/QmbMk4ksBYLQzJ6TiZfzaALF8W11xvB8Wz6a2GrG9oDrXW' const r1cs = 'https://ipfs-cluster.ethdevops.io/ipfs/QmbMk4ksBYLQzJ6TiZfzaALF8W11xvB8Wz6a2GrG9oDrXW'
const wasm = 'https://ipfs-cluster.ethdevops.io/ipfs/QmUbpEvHHKaHEqYLjhn93S8rEsUGeqiTYgRjGPk7g8tBbz' const wasm = 'https://ipfs-cluster.ethdevops.io/ipfs/QmUbpEvHHKaHEqYLjhn93S8rEsUGeqiTYgRjGPk7g8tBbz'
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 identityCommitments = groups[0].members const identityCommitments = groups[0].members
console.log('new incremental merkle tree', identityCommitments) console.log('new incremental merkle tree', identityCommitments)
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) {
console.error(e.message) console.error(e.message)
return return
} }
let proof1 = tree.createProof(0) const proof1 = tree.createProof(0)
console.log('check index in tree') console.log('check index in tree')
let index = tree.indexOf(identities[0].commitment) const index = tree.indexOf(identities[0].commitment)
console.log(index.toString()) console.log(index.toString())
console.log('prepare signals') console.log('prepare signals')
const signals = { const signals = {
identityTrapdoor: identity.trapdoor, identityTrapdoor: identity.trapdoor,
identityNullifier: identity.nullifier, identityNullifier: identity.nullifier,
treePathIndices: proof1.pathIndices, treePathIndices: proof1.pathIndices,
treeSiblings: proof1.siblings, treeSiblings: proof1.siblings,
externalNullifier: hash(externalNullifier), externalNullifier: hash(externalNullifier),
signalHash: hash(signal), signalHash: hash(signal),
} }
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 semaphoreProof = { const semaphoreProof = {
merkleTreeRoot: publicSignals[0], merkleTreeRoot: publicSignals[0],
nullifierHash: publicSignals[1], nullifierHash: publicSignals[1],
signal: BigNumber.from(signal).toString(), signal: BigNumber.from(signal).toString(),
externalNullifier: BigNumber.from(externalNullifier).toString(), externalNullifier: BigNumber.from(externalNullifier).toString(),
proof: packProof(proof), proof: packProof(proof),
} }
console.log(JSON.stringify(semaphoreProof, null, '\t')) console.log(JSON.stringify(semaphoreProof, null, '\t'))
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)
verified ? console.log('merkle proof valid') : console.log('merkle proof invalid') verified ? console.log('merkle proof valid') : console.log('merkle proof invalid')
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }
})() })()

@ -3,13 +3,13 @@ import { SemaphoreProof } from './types/types'
import { ethers } from 'ethers' import { ethers } from 'ethers'
import { BigNumberToSignal } from './helpers/convertsignal' import { BigNumberToSignal } from './helpers/convertsignal'
;(async () => { ;(async () => {
try { try {
const n = ethers.BigNumber.from(ethers.utils.randomBytes(32)) const n = ethers.BigNumber.from(ethers.utils.randomBytes(32))
const cid = BigNumberToSignal(n) const cid = BigNumberToSignal(n)
console.log('cid', cid) console.log('cid', cid)
const proof: SemaphoreProof = await createProofForIdendity(cid, '0', true, '/data/proof_submit.json') const proof: SemaphoreProof = await createProofForIdendity(cid, '0', true, '/data/proof_submit.json')
await remix.call('fileManager', 'setFile', './build/cid_submit.txt', cid) await remix.call('fileManager', 'setFile', './build/cid_submit.txt', cid)
} catch (e) { } catch (e) {
console.log(e.message) console.log(e.message)
} }
})() })()

@ -4,30 +4,30 @@ import { Identity } from '@semaphore-protocol/identity'
import { ethers } from 'ethers' import { ethers } from 'ethers'
import { ISemaphoreDeploymentData } from './types' import { ISemaphoreDeploymentData } from './types'
;(async () => { ;(async () => {
try { try {
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const sempahore_contract_address = semaphore_deployment_data.semaphoreAddress const sempahore_contract_address = semaphore_deployment_data.semaphoreAddress
const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer) const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer)
// load a proof // load a proof
const proofData = JSON.parse(await remix.call('fileManager', 'readFile', 'build/proof.json')) const proofData = JSON.parse(await remix.call('fileManager', 'readFile', 'build/proof.json'))
const proof = proofData.fullProof const proof = proofData.fullProof
const group_id = proofData.group_id const group_id = proofData.group_id
console.log('verifying proof on chain...') console.log('verifying proof on chain...')
console.log(proof) console.log(proof)
console.log('using proof ...', group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof) console.log('using proof ...', group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof)
const result = await contract.verifyProof(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof) const result = await contract.verifyProof(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof)
console.log('verification....') console.log('verification....')
console.log(result) console.log(result)
} catch (e) { } catch (e) {
console.error(e.message) console.error(e.message)
} }
})() })()

@ -1,22 +1,22 @@
import { ethers, BigNumber } from 'ethers' import { ethers, BigNumber } from 'ethers'
import { ISemaphoreDeploymentData, IGroup, IGroupMember } from './types' import { ISemaphoreDeploymentData, IGroup, IGroupMember } from './types'
;(async () => { ;(async () => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
console.log(await signer.getAddress()) console.log(await signer.getAddress())
const signerAddress = await signer.getAddress() const signerAddress = await signer.getAddress()
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const contract = await ethers.getContractAt('Semaphore', semaphore_deployment_data.semaphoreAddress, signer) const contract = await ethers.getContractAt('Semaphore', semaphore_deployment_data.semaphoreAddress, signer)
//console.log(contract.filters) //console.log(contract.filters)
let eventFilter = contract.filters.ProofVerified() const eventFilter = contract.filters.ProofVerified()
let proofs_verified = await contract.queryFilter(eventFilter) const proofs_verified = await contract.queryFilter(eventFilter)
console.log(JSON.stringify(proofs_verified, null, '\t')) console.log(JSON.stringify(proofs_verified, null, '\t'))
// write it to the filesystem // write it to the filesystem
await remix.call('fileManager', 'setFile', './build/proofs_verified.json', JSON.stringify(proofs_verified, null, '\t')) await remix.call('fileManager', 'setFile', './build/proofs_verified.json', JSON.stringify(proofs_verified, null, '\t'))
})() })()

@ -1,19 +1,19 @@
import { ethers, BigNumber, utils } from 'ethers' import { ethers, BigNumber, utils } from 'ethers'
import { BigNumberToSignal } from './helpers/convertsignal' import { BigNumberToSignal } from './helpers/convertsignal'
;(async () => { ;(async () => {
const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json')) const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json'))
const cids = [] const cids = []
for (let proof of verified_proofs) { for (const proof of verified_proofs) {
const cid = BigNumberToSignal(proof.args[3].hex) const cid = BigNumberToSignal(proof.args[3].hex)
const signal = proof.args[4].hex const signal = proof.args[4].hex
cids.push({ cids.push({
date: Date.now(), date: Date.now(),
cid: cid, cid: cid,
signal signal
}) })
} }
await remix.call('fileManager', 'setFile', './build/cids.json', JSON.stringify(cids, null, '\t')) await remix.call('fileManager', 'setFile', './build/cids.json', JSON.stringify(cids, null, '\t'))
})() })()

@ -1,46 +1,46 @@
import { ethers, BigNumber } from 'ethers' import { ethers, BigNumber } from 'ethers'
// [1,2,3,4,5,6,7,8] // [1,2,3,4,5,6,7,8]
;(async () => { ;(async () => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const signerAddress = await signer.getAddress() const signerAddress = await signer.getAddress()
const contract = await ethers.getContractAt('HackerGroup', '0x9a2E12340354d2532b4247da3704D2A5d73Bd189', signer) const contract = await ethers.getContractAt('HackerGroup', '0x9a2E12340354d2532b4247da3704D2A5d73Bd189', signer)
//console.log(contract.filters) //console.log(contract.filters)
let eventFilter = contract.filters.bugCreated() let eventFilter = contract.filters.bugCreated()
let bugs = await contract.queryFilter(eventFilter) let bugs = await contract.queryFilter(eventFilter)
console.log('bugs created') console.log('bugs created')
console.log(JSON.stringify(bugs, null, '\t')) console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.bugApproved() eventFilter = contract.filters.bugApproved()
bugs = await contract.queryFilter(eventFilter) bugs = await contract.queryFilter(eventFilter)
console.log('bugs approved') console.log('bugs approved')
console.log(JSON.stringify(bugs, null, '\t')) console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.bugRejected() eventFilter = contract.filters.bugRejected()
bugs = await contract.queryFilter(eventFilter) bugs = await contract.queryFilter(eventFilter)
console.log('bugs rejected') console.log('bugs rejected')
console.log(JSON.stringify(bugs, null, '\t')) console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.messageReceived(null) eventFilter = contract.filters.messageReceived(null)
bugs = await contract.queryFilter(eventFilter) bugs = await contract.queryFilter(eventFilter)
console.log('message received') console.log('message received')
console.log(JSON.stringify(bugs, null, '\t')) console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.TokensTransferred(null) eventFilter = contract.filters.TokensTransferred(null)
bugs = await contract.queryFilter(eventFilter) bugs = await contract.queryFilter(eventFilter)
console.log('tokens transferred') console.log('tokens transferred')
console.log(JSON.stringify(bugs, null, '\t')) console.log(JSON.stringify(bugs, null, '\t'))
/* /*
const client = await ethers.getContractAt('HackerClient', '0x4a9C121080f6D9250Fc0143f41B595fD172E31bf', signer) const client = await ethers.getContractAt('HackerClient', '0x4a9C121080f6D9250Fc0143f41B595fD172E31bf', signer)
eventFilter = client.filters.messageSent() eventFilter = client.filters.messageSent()

@ -15,173 +15,173 @@ let hackerclient
let semaphoreAddress let semaphoreAddress
let CCIPBNM let CCIPBNM
let proof: SemaphoreProof let proof: SemaphoreProof
let _paymentChainSelector = '16015286601757825753' const _paymentChainSelector = '16015286601757825753'
let _receiver let _receiver
let cid let cid
const router = ethers.Wallet.createRandom() // some random address uses instead of the CCIP router const router = ethers.Wallet.createRandom() // some random address uses instead of the CCIP router
describe('Hackerclient', function () { describe('Hackerclient', function () {
it('Deploys token', async function () { it('Deploys token', async function () {
await remix.call('udapp', 'clearAllInstances' as any) await remix.call('udapp', 'clearAllInstances' as any)
CCIPBNM = await deploy('CCIPBNM', []) CCIPBNM = await deploy('CCIPBNM', [])
console.log('deploy CCIPBNM done ', CCIPBNM.address) console.log('deploy CCIPBNM done ', CCIPBNM.address)
expect(CCIPBNM.address).to.not.null expect(CCIPBNM.address).to.not.null
}) })
it('Set Receiver', async function () { it('Set Receiver', async function () {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
_receiver = await signer.getAddress() _receiver = await signer.getAddress()
console.log('receiver', _receiver) console.log('receiver', _receiver)
}) })
it('Deploys hackergroup', async function () { it('Deploys hackergroup', async function () {
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
semaphoreAddress = semaphore_deployment_data.semaphoreAddress semaphoreAddress = semaphore_deployment_data.semaphoreAddress
hackergroup = await deploy('HackerGroup', [semaphore_deployment_data.semaphoreAddress, router.address, CCIPBNM.address]) hackergroup = await deploy('HackerGroup', [semaphore_deployment_data.semaphoreAddress, router.address, CCIPBNM.address])
console.log('deploy done ', hackergroup.address) console.log('deploy done ', hackergroup.address)
expect(hackergroup.address).to.not.null expect(hackergroup.address).to.not.null
}) })
it('Mints token to hackergroup', async function () { it('Mints token to hackergroup', async function () {
await CCIPBNM.mint(hackergroup.address, 100) await CCIPBNM.mint(hackergroup.address, 100)
expect(await CCIPBNM.balanceOf(hackergroup.address)).to.equal(100) expect(await CCIPBNM.balanceOf(hackergroup.address)).to.equal(100)
}) })
it('Deploys hackerclient', async function () { it('Deploys hackerclient', async function () {
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
semaphoreAddress = semaphore_deployment_data.semaphoreAddress semaphoreAddress = semaphore_deployment_data.semaphoreAddress
// here we will simulate going between chains // here we will simulate going between chains
const destChain = 2 const destChain = 2
const sourceChain = 1 const sourceChain = 1
hackerclient = await deploy('HackerClient', [destChain, sourceChain, hackergroup.address]) hackerclient = await deploy('HackerClient', [destChain, sourceChain, hackergroup.address])
console.log('deploy done ', hackerclient.address) console.log('deploy done ', hackerclient.address)
expect(hackerclient.address).to.not.null expect(hackerclient.address).to.not.null
}) })
it('Submit a new valid proof for onchain validating with hackergroup', async function () { it('Submit a new valid proof for onchain validating with hackergroup', async function () {
// get the first group from the file // get the first group from the file
const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json')) const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json'))
const group_id = groups[0].group_id const group_id = groups[0].group_id
const n = ethers.BigNumber.from(ethers.utils.randomBytes(32)) const n = ethers.BigNumber.from(ethers.utils.randomBytes(32))
cid = BigNumberToSignal(n) cid = BigNumberToSignal(n)
// signal is 0, meaning we create a new bug // signal is 0, meaning we create a new bug
proof = await await createProofForIdendity(cid, '0', true, null, groups[0].members[0]) proof = await await createProofForIdendity(cid, '0', true, null, groups[0].members[0])
console.log('using proof ...') console.log('using proof ...')
const result = await hackerclient.submit(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof, _paymentChainSelector, _receiver) const result = await hackerclient.submit(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof, _paymentChainSelector, _receiver)
console.log('verification by hackerclient...') console.log('verification by hackerclient...')
console.log(result) console.log(result)
expect(result.hash).to.not.null expect(result.hash).to.not.null
}) })
it('Fetches the bug associated with the cid', async function () { it('Fetches the bug associated with the cid', async function () {
console.log('fetching ....', proof.externalNullifier) console.log('fetching ....', proof.externalNullifier)
const result = await hackergroup.bugs(proof.externalNullifier) const result = await hackergroup.bugs(proof.externalNullifier)
console.log(result) console.log(result)
expect(result[0]).to.equal(proof.externalNullifier) expect(result[0]).to.equal(proof.externalNullifier)
}) })
it('Reads the events from the contract', async function () { it('Reads the events from the contract', async function () {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const contract = await ethers.getContractAt('HackerGroup', hackergroup.address, signer) const contract = await ethers.getContractAt('HackerGroup', hackergroup.address, signer)
let eventFilter = contract.filters.bugCreated() const eventFilter = contract.filters.bugCreated()
let bugs = await contract.queryFilter(eventFilter) const bugs = await contract.queryFilter(eventFilter)
expect(bugs.length).to.equal(1) expect(bugs.length).to.equal(1)
console.log('bugs created') console.log('bugs created')
console.log(JSON.stringify(bugs, null, '\t')) console.log(JSON.stringify(bugs, null, '\t'))
}) })
it('Submit a new valid approval proof by the second member of the group', async function () { it('Submit a new valid approval proof by the second member of the group', async function () {
// get the first group from the file // get the first group from the file
const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json')) const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json'))
const group_id = groups[0].group_id const group_id = groups[0].group_id
// signal is 1, meaning we approve the bug // signal is 1, meaning we approve the bug
proof = await createProofForIdendity(cid, '1', true, null, groups[0].members[1]) proof = await createProofForIdendity(cid, '1', true, null, groups[0].members[1])
// get the first group from the file // get the first group from the file
console.log('using proof ...') console.log('using proof ...')
const result = await hackerclient.submit(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof, _paymentChainSelector, _receiver) const result = await hackerclient.submit(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof, _paymentChainSelector, _receiver)
console.log('verification by hackerclient...') console.log('verification by hackerclient...')
console.log(result) console.log(result)
expect(result.hash).to.not.null expect(result.hash).to.not.null
}) })
it('Fetches the bug associated with the cid', async function () { it('Fetches the bug associated with the cid', async function () {
const result = await hackergroup.approvals(proof.externalNullifier) const result = await hackergroup.approvals(proof.externalNullifier)
console.log(result) console.log(result)
expect(result).to.equal(1) expect(result).to.equal(1)
}) })
it('Reads the events from the contract', async function () { it('Reads the events from the contract', async function () {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const contract = await ethers.getContractAt('HackerGroup', hackergroup.address, signer) const contract = await ethers.getContractAt('HackerGroup', hackergroup.address, signer)
let eventFilter = contract.filters.TokensTransferred(null) const eventFilter = contract.filters.TokensTransferred(null)
const tokens = await contract.queryFilter(eventFilter) const tokens = await contract.queryFilter(eventFilter)
expect(tokens.length).to.equal(1) expect(tokens.length).to.equal(1)
console.log('tokens transferred') console.log('tokens transferred')
console.log(JSON.stringify(tokens, null, '\t')) console.log(JSON.stringify(tokens, null, '\t'))
}) })
it('Check balance of hackergroup', async function () { it('Check balance of hackergroup', async function () {
expect(await CCIPBNM.balanceOf(hackergroup.address)).to.equal(99) expect(await CCIPBNM.balanceOf(hackergroup.address)).to.equal(99)
}) })
it('gets the cids from the verified proofs', async () => { it('gets the cids from the verified proofs', async () => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const contract = await ethers.getContractAt('Semaphore', semaphore_deployment_data.semaphoreAddress, signer) const contract = await ethers.getContractAt('Semaphore', semaphore_deployment_data.semaphoreAddress, signer)
//console.log(contract.filters) //console.log(contract.filters)
let eventFilter = contract.filters.ProofVerified() const eventFilter = contract.filters.ProofVerified()
let proofs_verified = await contract.queryFilter(eventFilter) const proofs_verified = await contract.queryFilter(eventFilter)
// write it to the filesystem // write it to the filesystem
await remix.call('fileManager', 'setFile', './build/proofs_verified.json', JSON.stringify(proofs_verified, null, '\t')) await remix.call('fileManager', 'setFile', './build/proofs_verified.json', JSON.stringify(proofs_verified, null, '\t'))
// build cids from it // build cids from it
const cids = [] const cids = []
const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json')) const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json'))
for (let proof of verified_proofs) { for (const proof of verified_proofs) {
const cid = BigNumberToSignal(proof.args[3].hex) const cid = BigNumberToSignal(proof.args[3].hex)
const signal = proof.args[4].hex const signal = proof.args[4].hex
cids.push({ cids.push({
date: Date.now(), date: Date.now(),
cid: cid, cid: cid,
signal signal
}) })
console.log(cids) console.log(cids)
console.log('finding ', cid) console.log('finding ', cid)
const index = cids.findIndex((x) => x.cid === cid) const index = cids.findIndex((x) => x.cid === cid)
expect(index).to.greaterThan(-1) expect(index).to.greaterThan(-1)
} }
}) })
it('writes bugs to file', async () => { it('writes bugs to file', async () => {
let bugs = [] const bugs = []
const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json')) const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json'))
for (let proof of verified_proofs) { for (const proof of verified_proofs) {
const cid = BigNumberToSignal(proof.args[3].hex) const cid = BigNumberToSignal(proof.args[3].hex)
const externalNullifier = proof.args[3].hex const externalNullifier = proof.args[3].hex
console.log(externalNullifier) console.log(externalNullifier)
// query the contract // query the contract
console.log('fetching ....', externalNullifier) console.log('fetching ....', externalNullifier)
const result = await hackergroup.bugs(externalNullifier) const result = await hackergroup.bugs(externalNullifier)
console.log(result) console.log(result)
bugs.push({ bugs.push({
cid, cid,
approved: result[4].toNumber(), approved: result[4].toNumber(),
rejected: result[5].toNumber() rejected: result[5].toNumber()
}) })
} }
await remix.call('fileManager', 'setFile', './build/bugs.json', JSON.stringify(bugs, null, '\t')) await remix.call('fileManager', 'setFile', './build/bugs.json', JSON.stringify(bugs, null, '\t'))
}) })
}) })

@ -15,204 +15,204 @@ import { BigNumberToSignal } from '../helpers/convertsignal'
let hackergroup let hackergroup
let semaphoreAddress let semaphoreAddress
let proof: SemaphoreProof let proof: SemaphoreProof
let _paymentChainSelector = '16015286601757825753' const _paymentChainSelector = '16015286601757825753'
let _receiver let _receiver
let cid let cid
let CCIPBNM let CCIPBNM
const router = ethers.Wallet.createRandom() // some random address uses instead of the CCIP router const router = ethers.Wallet.createRandom() // some random address uses instead of the CCIP router
describe('Hackergroup', function () { describe('Hackergroup', function () {
it('Deploys token', async function () { it('Deploys token', async function () {
await remix.call('udapp', 'clearAllInstances' as any) await remix.call('udapp', 'clearAllInstances' as any)
CCIPBNM = await deploy('CCIPBNM', []) CCIPBNM = await deploy('CCIPBNM', [])
console.log('deploy CCIPBNM done ', CCIPBNM.address) console.log('deploy CCIPBNM done ', CCIPBNM.address)
expect(CCIPBNM.address).to.not.null expect(CCIPBNM.address).to.not.null
}) })
it('Set Receiver', async function () { it('Set Receiver', async function () {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
_receiver = await signer.getAddress() _receiver = await signer.getAddress()
console.log('receiver', _receiver) console.log('receiver', _receiver)
}) })
it('Deploys hackergroup', async function () { it('Deploys hackergroup', async function () {
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
semaphoreAddress = semaphore_deployment_data.semaphoreAddress semaphoreAddress = semaphore_deployment_data.semaphoreAddress
hackergroup = await deploy('HackerGroup', [semaphore_deployment_data.semaphoreAddress, router.address, CCIPBNM.address]) hackergroup = await deploy('HackerGroup', [semaphore_deployment_data.semaphoreAddress, router.address, CCIPBNM.address])
console.log('deploy done ', hackergroup.address) console.log('deploy done ', hackergroup.address)
expect(hackergroup.address).to.not.null expect(hackergroup.address).to.not.null
}) })
it('Mints token to hackergroup', async function () { it('Mints token to hackergroup', async function () {
await CCIPBNM.mint(hackergroup.address, 100) await CCIPBNM.mint(hackergroup.address, 100)
expect(await CCIPBNM.balanceOf(hackergroup.address)).to.equal(100) expect(await CCIPBNM.balanceOf(hackergroup.address)).to.equal(100)
}) })
it('Gets the Semaphore adddress', async function () { it('Gets the Semaphore adddress', async function () {
const address = await hackergroup.semaphore() const address = await hackergroup.semaphore()
console.log(address) console.log(address)
expect(address).to.equal(semaphoreAddress) expect(address).to.equal(semaphoreAddress)
}) })
it('Creates a valid proof for onchain validating with semaphore', async function () { it('Creates a valid proof for onchain validating with semaphore', async function () {
const n = ethers.BigNumber.from(ethers.utils.randomBytes(32)) const n = ethers.BigNumber.from(ethers.utils.randomBytes(32))
cid = BigNumberToSignal(n) cid = BigNumberToSignal(n)
proof = await createProofForIdendity(cid, '0', false) proof = await createProofForIdendity(cid, '0', false)
}) })
it('Validates proof on chain', async function () { it('Validates proof on chain', async function () {
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const sempahore_contract_address = semaphore_deployment_data.semaphoreAddress const sempahore_contract_address = semaphore_deployment_data.semaphoreAddress
const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer) const contract = await ethers.getContractAt('Semaphore', sempahore_contract_address, signer)
console.log('verifying proof on chain...') console.log('verifying proof on chain...')
console.log(proof) console.log(proof)
// get the first group from the file // get the first group from the file
const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json')) const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json'))
const group_id = groups[0].group_id const group_id = groups[0].group_id
console.log('using proof ...') console.log('using proof ...')
const result = await contract.verifyProof(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof) const result = await contract.verifyProof(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof)
console.log('verification...') console.log('verification...')
console.log(result) console.log(result)
expect(result.hash).to.not.null expect(result.hash).to.not.null
}) })
it('Submit a new valid proof for onchain validating with hackergroup', async function () { it('Submit a new valid proof for onchain validating with hackergroup', async function () {
// get the first group from the file // get the first group from the file
const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json')) const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json'))
const group_id = groups[0].group_id const group_id = groups[0].group_id
const n = ethers.BigNumber.from(ethers.utils.randomBytes(32)) const n = ethers.BigNumber.from(ethers.utils.randomBytes(32))
cid = BigNumberToSignal(n) cid = BigNumberToSignal(n)
// signal is 0, meaning we create a new bug // signal is 0, meaning we create a new bug
proof = await createProofForIdendity(cid, '0', true, null, groups[0].members[0]) proof = await createProofForIdendity(cid, '0', true, null, groups[0].members[0])
console.log('using proof ...') console.log('using proof ...')
const result = await hackergroup.submit(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof, _paymentChainSelector, _receiver) const result = await hackergroup.submit(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof, _paymentChainSelector, _receiver)
console.log('verification by hackergroup...') console.log('verification by hackergroup...')
console.log(result) console.log(result)
expect(result.hash).to.not.null expect(result.hash).to.not.null
}) })
it('Fetches the bug associated with the cid', async function () { it('Fetches the bug associated with the cid', async function () {
console.log('fetching ....', proof.externalNullifier) console.log('fetching ....', proof.externalNullifier)
const result = await hackergroup.bugs(proof.externalNullifier) const result = await hackergroup.bugs(proof.externalNullifier)
console.log(result) console.log(result)
expect(result[0]).to.equal(proof.externalNullifier) expect(result[0]).to.equal(proof.externalNullifier)
}) })
it('Submit a new valid approval proof by the second member of the group', async function () { it('Submit a new valid approval proof by the second member of the group', async function () {
// get the first group from the file // get the first group from the file
const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json')) const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json'))
const group_id = groups[0].group_id const group_id = groups[0].group_id
// signal is 1, meaning we approve the bug // signal is 1, meaning we approve the bug
proof = await createProofForIdendity(cid, '1', true, null, groups[0].members[1]) proof = await createProofForIdendity(cid, '1', true, null, groups[0].members[1])
// get the first group from the file // get the first group from the file
console.log('using proof ...') console.log('using proof ...')
const result = await hackergroup.submit(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof, _paymentChainSelector, _receiver) const result = await hackergroup.submit(group_id, proof.merkleTreeRoot, proof.signal, proof.nullifierHash, proof.externalNullifier, proof.proof, _paymentChainSelector, _receiver)
console.log('verification by hackergroup...') console.log('verification by hackergroup...')
console.log(result) console.log(result)
expect(result.hash).to.not.null expect(result.hash).to.not.null
}) })
it('Fetches the bug associated with the cid', async function () { it('Fetches the bug associated with the cid', async function () {
const result = await hackergroup.approvals(proof.externalNullifier) const result = await hackergroup.approvals(proof.externalNullifier)
console.log(result) console.log(result)
expect(result).to.equal(1) expect(result).to.equal(1)
}) })
it('Reads the events from the contract', async function () { it('Reads the events from the contract', async function () {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const contract = await ethers.getContractAt('HackerGroup', hackergroup.address, signer) const contract = await ethers.getContractAt('HackerGroup', hackergroup.address, signer)
let eventFilter = contract.filters.bugCreated() let eventFilter = contract.filters.bugCreated()
let bugs = await contract.queryFilter(eventFilter) let bugs = await contract.queryFilter(eventFilter)
expect(bugs.length).to.equal(1) expect(bugs.length).to.equal(1)
console.log('bugs created') console.log('bugs created')
console.log(JSON.stringify(bugs, null, '\t')) console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.bugApproved() eventFilter = contract.filters.bugApproved()
bugs = await contract.queryFilter(eventFilter) bugs = await contract.queryFilter(eventFilter)
expect(bugs.length).to.equal(1) expect(bugs.length).to.equal(1)
console.log('bugs approved') console.log('bugs approved')
console.log(JSON.stringify(bugs, null, '\t')) console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.TokensTransferred(null) eventFilter = contract.filters.TokensTransferred(null)
const tokens = await contract.queryFilter(eventFilter) const tokens = await contract.queryFilter(eventFilter)
expect(tokens.length).to.equal(1) expect(tokens.length).to.equal(1)
console.log('tokens transferred') console.log('tokens transferred')
console.log(JSON.stringify(tokens, null, '\t')) console.log(JSON.stringify(tokens, null, '\t'))
}) })
it('Check balance of hackergroup', async function () { it('Check balance of hackergroup', async function () {
expect(await CCIPBNM.balanceOf(hackergroup.address)).to.equal(99) expect(await CCIPBNM.balanceOf(hackergroup.address)).to.equal(99)
}) })
it('gets the cids from the verified proofs', async () => { it('gets the cids from the verified proofs', async () => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner() const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json') const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment) const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const contract = await ethers.getContractAt('Semaphore', semaphore_deployment_data.semaphoreAddress, signer) const contract = await ethers.getContractAt('Semaphore', semaphore_deployment_data.semaphoreAddress, signer)
//console.log(contract.filters) //console.log(contract.filters)
let eventFilter = contract.filters.ProofVerified() const eventFilter = contract.filters.ProofVerified()
let proofs_verified = await contract.queryFilter(eventFilter) const proofs_verified = await contract.queryFilter(eventFilter)
// write it to the filesystem // write it to the filesystem
await remix.call('fileManager', 'setFile', './build/proofs_verified.json', JSON.stringify(proofs_verified, null, '\t')) await remix.call('fileManager', 'setFile', './build/proofs_verified.json', JSON.stringify(proofs_verified, null, '\t'))
// build cids from it // build cids from it
const cids = [] const cids = []
const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json')) const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json'))
for (let proof of verified_proofs) { for (const proof of verified_proofs) {
const cid = BigNumberToSignal(proof.args[3].hex) const cid = BigNumberToSignal(proof.args[3].hex)
const signal = proof.args[4].hex const signal = proof.args[4].hex
cids.push({ cids.push({
date: Date.now(), date: Date.now(),
cid: cid, cid: cid,
signal signal
}) })
console.log(cids) console.log(cids)
console.log('finding ', cid) console.log('finding ', cid)
const index = cids.findIndex((x) => x.cid === cid) const index = cids.findIndex((x) => x.cid === cid)
expect(index).to.greaterThan(-1) expect(index).to.greaterThan(-1)
} }
}) })
it('writes bugs to file', async () => { it('writes bugs to file', async () => {
let bugs = [] const bugs = []
const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json')) const verified_proofs = JSON.parse(await remix.call('fileManager', 'readFile', './build/proofs_verified.json'))
for (let proof of verified_proofs) { for (const proof of verified_proofs) {
const cid = BigNumberToSignal(proof.args[3].hex) const cid = BigNumberToSignal(proof.args[3].hex)
const externalNullifier = proof.args[3].hex const externalNullifier = proof.args[3].hex
console.log(externalNullifier) console.log(externalNullifier)
// query the contract // query the contract
console.log('fetching ....', externalNullifier) console.log('fetching ....', externalNullifier)
const result = await hackergroup.bugs(externalNullifier) const result = await hackergroup.bugs(externalNullifier)
console.log(result) console.log(result)
bugs.push({ bugs.push({
cid, cid,
approved: result[4].toNumber(), approved: result[4].toNumber(),
rejected: result[5].toNumber() rejected: result[5].toNumber()
}) })
} }
await remix.call('fileManager', 'setFile', './build/bugs.json', JSON.stringify(bugs, null, '\t')) await remix.call('fileManager', 'setFile', './build/bugs.json', JSON.stringify(bugs, null, '\t'))
}) })
}) })

Loading…
Cancel
Save