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

@ -1,15 +1,15 @@
;(async () => {
try {
remix.off('solidity', 'compilationFinished')
const params = {
optimize: true,
runs: 200,
language: 'Solidity',
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)
try {
remix.off('solidity', 'compilationFinished')
const params = {
optimize: true,
runs: 200,
language: 'Solidity',
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)
}
})()

@ -1,15 +1,15 @@
;(async () => {
try {
remix.off('solidity', 'compilationFinished')
const params = {
optimize: true,
runs: 200,
language: 'Solidity',
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)
try {
remix.off('solidity', 'compilationFinished')
const params = {
optimize: true,
runs: 200,
language: 'Solidity',
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)
}
})()

@ -1,15 +1,15 @@
;(async () => {
try {
remix.off('solidity', 'compilationFinished')
const params = {
optimize: true,
runs: 200,
language: 'Solidity',
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)
try {
remix.off('solidity', 'compilationFinished')
const params = {
optimize: true,
runs: 200,
language: 'Solidity',
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)
}
})()

@ -1,15 +1,15 @@
;(async () => {
try {
remix.off('solidity', 'compilationFinished')
const params = {
optimize: true,
runs: 200,
language: 'Solidity',
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)
try {
remix.off('solidity', 'compilationFinished')
const params = {
optimize: true,
runs: 200,
language: 'Solidity',
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)
}
})()

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

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

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

@ -1,58 +1,58 @@
import { ethers, BigNumber } from 'ethers'
import { ISemaphoreDeploymentData, IGroup, IGroupMember } from './types/types'
;(async () => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
console.log(await signer.getAddress())
const signerAddress = await signer.getAddress()
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
console.log(await signer.getAddress())
const signerAddress = await signer.getAddress()
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
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 groupsCreated = await contract.queryFilter(eventFilter)
let eventFilter = contract.filters.GroupCreated()
const groupsCreated = await contract.queryFilter(eventFilter)
const groupIds: any = []
const groupIds: any = []
for (let groupCreated of groupsCreated) {
console.log(groupCreated)
const group = await contract.groups(groupCreated.args[0])
for (const groupCreated of groupsCreated) {
console.log(groupCreated)
const group = await contract.groups(groupCreated.args[0])
if (group[0] == signerAddress) {
console.log('found group belonging to ' + signerAddress + 'group id ' + groupCreated.args[0])
groupIds.push(groupCreated.args[0])
}
if (group[0] == signerAddress) {
console.log('found group belonging to ' + signerAddress + 'group id ' + groupCreated.args[0])
groupIds.push(groupCreated.args[0])
}
}
eventFilter = contract.filters.MemberAdded()
let membersAdded = await contract.queryFilter(eventFilter)
eventFilter = contract.filters.MemberAdded()
const membersAdded = await contract.queryFilter(eventFilter)
const groups: IGroup[] = []
const groups: IGroup[] = []
for (let groupId of groupIds) {
console.log('checking group members of group ' + groupId)
for (const groupId of groupIds) {
console.log('checking group members of group ' + groupId)
const group: IGroup = {
group_id: groupId.toString(),
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())
}
}
const group: IGroup = {
group_id: groupId.toString(),
members: [],
}
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:')
console.log(groups)
groups.push(group)
}
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'
export const SignalToBigNumber = (message: string) => {
// **************************************************************
// **************** Convert CID to Big Number ***************
const tmpArray = multihash.fromB58String(message)
const b58decoded = multihash.decode(tmpArray).digest
const tmpHexStr = utils.hexlify(b58decoded)
const signal = BigNumber.from(tmpHexStr, 16).toString()
return signal
// **************************************************************
// **************** Convert CID to Big Number ***************
const tmpArray = multihash.fromB58String(message)
const b58decoded = multihash.decode(tmpArray).digest
const tmpHexStr = utils.hexlify(b58decoded)
const signal = BigNumber.from(tmpHexStr, 16).toString()
return signal
}
export const BigNumberToSignal = (signal: string) => {
// **************************************************************
// Convert the signal back to the original CID
const tmpBNtoHex = utils.hexlify(
BigNumber.from(signal)
);
const tmpHextoBytes = utils.arrayify(tmpBNtoHex);
const tmpBytestoArr = multihash.encode(tmpHextoBytes, "sha2-256");
const mhBuf = multihash.encode(tmpBytestoArr, "sha2-256");
const decodedBuf = multihash.decode(mhBuf);
const encodedStr = multihash.toB58String(decodedBuf.digest);
console.log("Recovered CID Value: ", encodedStr);
return encodedStr
// **************************************************************
// **************************************************************
// Convert the signal back to the original CID
const tmpBNtoHex = utils.hexlify(
BigNumber.from(signal)
);
const tmpHextoBytes = utils.arrayify(tmpBNtoHex);
const tmpBytestoArr = multihash.encode(tmpHextoBytes, "sha2-256");
const mhBuf = multihash.encode(tmpBytestoArr, "sha2-256");
const decodedBuf = multihash.decode(mhBuf);
const encodedStr = multihash.toB58String(decodedBuf.digest);
console.log("Recovered CID Value: ", encodedStr);
return encodedStr
// **************************************************************
}

@ -6,66 +6,66 @@ import { SignalToBigNumber } from '../helpers/convertsignal'
import { IIdentity, SemaphoreProof } from '../types/types'
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 preSignal = _signal
const topic = _cid
const preSignal = _signal
console.log('topic', topic)
console.log('message', preSignal)
console.log('topic', topic)
console.log('message', preSignal)
// get the idendity
const identities: IIdentity[] = JSON.parse(await remix.call('fileManager', 'readFile', './build/identities.json'))
console.log('using identity... ')
const id = identities.find((i) => i.commitment == _commitment)
let identity: Identity
if (id) {
identity = new Identity(id.data)
} else {
identity = new Identity(identities[0].data)
}
// get the idendity
const identities: IIdentity[] = JSON.parse(await remix.call('fileManager', 'readFile', './build/identities.json'))
console.log('using identity... ')
const id = identities.find((i) => i.commitment == _commitment)
let identity: Identity
if (id) {
identity = new Identity(id.data)
} else {
identity = new Identity(identities[0].data)
}
console.log(identity.commitment.toString())
console.log(identity.commitment.toString())
// construct the group
const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json'))
// construct the group
const groups = JSON.parse(await remix.call('fileManager', 'readFile', './build/groups.json'))
const group_with_member = groups.find((g) => {
return g.members.includes(identity.commitment.toString())
})
const group_with_member = groups.find((g) => {
return g.members.includes(identity.commitment.toString())
})
console.log('found group ... ')
console.log(group_with_member)
console.log('found group ... ')
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
/ 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 externalNullifier = SignalToBigNumber(topic)
const signal = preSignal
const externalNullifier = SignalToBigNumber(topic)
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!!
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!!
/ 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
*/
const fullProof: SemaphoreProof = await generateProof(identity, group, externalNullifier, signal, {
zkeyFilePath: 'https://ipfs-cluster.ethdevops.io/ipfs/QmYQU3F6MpxhwAjGLMrcf7Xt2u5PyuS1wrV1Upy1M8xGhL',
wasmFilePath: 'https://ipfs-cluster.ethdevops.io/ipfs/QmQ8oN5nydG5MwQtxZBVUW5b3E2n41kcbXYUi9wPLFEfqq',
})
console.log('Proof created')
console.log(JSON.stringify(fullProof, null, '\t'))
const fullProof: SemaphoreProof = await generateProof(identity, group, externalNullifier, signal, {
zkeyFilePath: 'https://ipfs-cluster.ethdevops.io/ipfs/QmYQU3F6MpxhwAjGLMrcf7Xt2u5PyuS1wrV1Upy1M8xGhL',
wasmFilePath: 'https://ipfs-cluster.ethdevops.io/ipfs/QmQ8oN5nydG5MwQtxZBVUW5b3E2n41kcbXYUi9wPLFEfqq',
})
console.log('Proof created')
console.log(JSON.stringify(fullProof, null, '\t'))
// write it to the filesystem
if (writeProof) {
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...')
const result = await verifyProof(fullProof, 20)
// write it to the filesystem
if (writeProof) {
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...')
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
*/
export const deploy = async (
contractName: string,
args: Array<any>,
libraries?: { [key: string]: any },
contractName: string,
args: Array<any>,
libraries?: { [key: string]: any },
): 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
let factory = await ethers.getContractFactory(contractName as any, null, {
signer,
libraries,
} as any)
// internal Remix method that resolves the artifacts and links the libraries
const factory = await ethers.getContractFactory(contractName as any, null, {
signer,
libraries,
} 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
await contract.deployed()
// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
return contract
return contract
}

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

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

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

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

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

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

@ -1,22 +1,22 @@
import { ethers, BigNumber } from 'ethers'
import { ISemaphoreDeploymentData, IGroup, IGroupMember } from './types'
;(async () => {
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
console.log(await signer.getAddress())
const signerAddress = await signer.getAddress()
const signer = new ethers.providers.Web3Provider(web3Provider).getSigner()
console.log(await signer.getAddress())
const signerAddress = await signer.getAddress()
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
const semaphore_deployment_data: ISemaphoreDeploymentData = JSON.parse(semaphore_deployment)
const semaphore_deployment = await remix.call('fileManager', 'readFile', 'data/semaphore_deployment.json')
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()
let proofs_verified = await contract.queryFilter(eventFilter)
const eventFilter = contract.filters.ProofVerified()
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
await remix.call('fileManager', 'setFile', './build/proofs_verified.json', JSON.stringify(proofs_verified, null, '\t'))
// write it to the filesystem
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 { BigNumberToSignal } from './helpers/convertsignal'
;(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) {
const cid = BigNumberToSignal(proof.args[3].hex)
const signal = proof.args[4].hex
cids.push({
date: Date.now(),
cid: cid,
signal
})
}
for (const proof of verified_proofs) {
const cid = BigNumberToSignal(proof.args[3].hex)
const signal = proof.args[4].hex
cids.push({
date: Date.now(),
cid: cid,
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'
// [1,2,3,4,5,6,7,8]
;(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 bugs = await contract.queryFilter(eventFilter)
let eventFilter = contract.filters.bugCreated()
let bugs = await contract.queryFilter(eventFilter)
console.log('bugs created')
console.log(JSON.stringify(bugs, null, '\t'))
console.log('bugs created')
console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.bugApproved()
bugs = await contract.queryFilter(eventFilter)
eventFilter = contract.filters.bugApproved()
bugs = await contract.queryFilter(eventFilter)
console.log('bugs approved')
console.log(JSON.stringify(bugs, null, '\t'))
console.log('bugs approved')
console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.bugRejected()
bugs = await contract.queryFilter(eventFilter)
eventFilter = contract.filters.bugRejected()
bugs = await contract.queryFilter(eventFilter)
console.log('bugs rejected')
console.log(JSON.stringify(bugs, null, '\t'))
console.log('bugs rejected')
console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.messageReceived(null)
bugs = await contract.queryFilter(eventFilter)
eventFilter = contract.filters.messageReceived(null)
bugs = await contract.queryFilter(eventFilter)
console.log('message received')
console.log(JSON.stringify(bugs, null, '\t'))
console.log('message received')
console.log(JSON.stringify(bugs, null, '\t'))
eventFilter = contract.filters.TokensTransferred(null)
bugs = await contract.queryFilter(eventFilter)
eventFilter = contract.filters.TokensTransferred(null)
bugs = await contract.queryFilter(eventFilter)
console.log('tokens transferred')
console.log(JSON.stringify(bugs, null, '\t'))
console.log('tokens transferred')
console.log(JSON.stringify(bugs, null, '\t'))
/*
/*
const client = await ethers.getContractAt('HackerClient', '0x4a9C121080f6D9250Fc0143f41B595fD172E31bf', signer)
eventFilter = client.filters.messageSent()

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

Loading…
Cancel
Save