Zero-knowledge proof circuits for genomic privacy on Midnight blockchain
In response to the 23andMe breach where millions of genetic profiles were permanently exposed and sold on the dark web, HelixChain's smart contracts ensure that genomic verification happens without ever exposing raw genetic data. Our Midnight blockchain contracts use zero-knowledge proofs to verify genetic traits while keeping the actual genomic sequences private forever.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Contract Layer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Compact Language β ZK Circuits β ProofSDK β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Verification Circuits β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β BRCA1 Circuit β BRCA2 Circuit β CYP2D6 Circuit β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Storage Layer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Genome Commitments β Proof Registry β Access Control β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Event System β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β VerificationComplete β ProofSubmitted β AccessGranted β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Node.js 20 LTS
- Midnight Compact Compiler (
compactc) - Lace Wallet with testnet DUST tokens
# Navigate to contracts directory
cd contracts
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env with your configuration
# Compile contracts
npm run build
# Deploy to testnet
npm run deploy:testnet# Network Configuration
MIDNIGHT_NETWORK=testnet
MIDNIGHT_RPC_URL=https://testnet.midnight.network/rpc
MIDNIGHT_EXPLORER=https://explorer.testnet.midnight.network
# Deployment
DEPLOYER_PRIVATE_KEY=your-private-key-here
DEPLOYER_ADDRESS=your-midnight-address
# Contract Settings
MAX_PROOF_SIZE=2048
VERIFICATION_TIMEOUT=30000
CIRCUIT_DEPTH=20
# Development
MOCK_MODE=false
VERBOSE_LOGGING=truecontracts/
βββ src/
β βββ genomic_verifier.compact # Main contract
β βββ circuits/ # ZK circuits
β β βββ brca1.circom # BRCA1 trait verification
β β βββ brca2.circom # BRCA2 trait verification
β β βββ cyp2d6.circom # Drug metabolism verification
β β βββ common/ # Shared circuit components
β β βββ hash.circom
β β βββ merkle.circom
β β βββ range.circom
β β
β βββ sdk/ # TypeScript SDK
β β βββ ProofSDK.ts # Main SDK interface
β β βββ EventListener.ts # Blockchain event monitoring
β β βββ types.ts # Type definitions
β β βββ utils.ts # Helper functions
β β
β βββ interfaces/ # Contract interfaces
β βββ IGenomicVerifier.sol
β βββ IProofRegistry.sol
β
βββ scripts/
β βββ deploy.ts # Deployment script
β βββ verify.ts # Verification helper
β βββ compile.ts # Compilation script
β βββ interact.ts # Contract interaction
β
βββ tests/
β βββ unit/ # Unit tests
β β βββ circuits.test.ts
β β βββ contract.test.ts
β βββ integration/ # Integration tests
β β βββ end-to-end.test.ts
β βββ fixtures/ # Test data
β βββ sample-genomes.json
β
βββ build/ # Compiled artifacts
β βββ genomic_verifier.json # Contract ABI & bytecode
β βββ circuits/ # Compiled circuits
β βββ verification_keys/ # ZK verification keys
β
βββ deployment.json # Deployment addresses
The main contract that manages genomic trait verification using zero-knowledge proofs.
// Submit genome commitment (Patient)
function commitGenome(
bytes32 commitment,
bytes32 encryptedIPFSHash
) external returns (uint256 genomeId)
// Request verification (Doctor)
function requestVerification(
address patient,
TraitType trait,
string calldata reason
) external returns (uint256 requestId)
// Submit proof (Patient)
function submitProof(
uint256 requestId,
bytes calldata proof,
bytes32[] calldata publicInputs
) external returns (bool verified)
// Verify proof on-chain
function verifyProof(
TraitType trait,
bytes calldata proof,
bytes32[] calldata publicInputs
) public view returns (bool)
// Grant access (Patient)
function grantAccess(
address verifier,
uint256 genomeId,
uint256 duration
) external
// Revoke access (Patient)
function revokeAccess(
address verifier,
uint256 genomeId
) externalevent GenomeCommitted(
address indexed patient,
uint256 indexed genomeId,
bytes32 commitment
);
event VerificationRequested(
address indexed doctor,
address indexed patient,
uint256 requestId,
TraitType trait
);
event ProofSubmitted(
uint256 indexed requestId,
address indexed patient,
bool verified
);
event AccessGranted(
address indexed patient,
address indexed verifier,
uint256 genomeId,
uint256 duration
);Verifies presence of BRCA1 gene mutations associated with breast cancer risk.
template BRCA1Verifier() {
signal input genome[GENOME_LENGTH];
signal input mutation_positions[MAX_MUTATIONS];
signal input threshold;
signal output is_positive;
// Circuit logic for BRCA1 verification
// Checks for known pathogenic variants
// Returns 1 if mutation detected, 0 otherwise
}Verifies presence of BRCA2 gene mutations.
template BRCA2Verifier() {
signal input genome[GENOME_LENGTH];
signal input mutation_positions[MAX_MUTATIONS];
signal input threshold;
signal output is_positive;
// Circuit logic for BRCA2 verification
}Verifies CYP2D6 gene variants that affect drug metabolism.
template CYP2D6Verifier() {
signal input genome[GENOME_LENGTH];
signal input variant_alleles[MAX_VARIANTS];
signal output metabolizer_type; // 0: Poor, 1: Normal, 2: Rapid
// Circuit logic for drug metabolism phenotype
}# Compile all contracts
npm run build
# Compile specific contract
npm run build:genomic-verifier
# Compile circuits
npm run build:circuits
# Watch mode for development
npm run build:watch# Run all tests
npm test
# Run unit tests
npm run test:unit
# Run integration tests
npm run test:integration
# Test coverage
npm run test:coverage
# Test specific circuit
npm run test:circuit:brca1# Deploy to testnet
npm run deploy:testnet
# Deploy to mainnet (requires confirmation)
npm run deploy:mainnet
# Verify deployment
npm run verify:deployment
# Upgrade contract (if upgradeable)
npm run upgrade:contractimport { ProofSDK } from './sdk/ProofSDK';
// Initialize SDK
const sdk = new ProofSDK(
contractAddress,
rpcUrl,
privateKey
);
// Generate BRCA1 proof
const proof = await sdk.generateBRCA1Proof(
genomeData,
mutationThreshold
);
// Submit proof to blockchain
const txHash = await sdk.submitProof(
requestId,
proof
);
// Listen for events
sdk.on('ProofVerified', (event) => {
console.log('Proof verified:', event);
});import { EventListener } from './sdk/EventListener';
const listener = new EventListener(contractAddress, rpcUrl);
// Subscribe to verification events
listener.subscribe('VerificationComplete', (event) => {
const { requestId, patient, verified } = event;
console.log(`Request ${requestId}: ${verified ? 'Verified' : 'Failed'}`);
});
// Start monitoring
await listener.start();| Circuit | Constraint Count | Proof Generation Time | Verification Time | Proof Size |
|---|---|---|---|---|
| BRCA1 | 450,000 | 12s | 50ms | 1.8 KB |
| BRCA2 | 460,000 | 13s | 52ms | 1.8 KB |
| CYP2D6 | 320,000 | 8s | 35ms | 1.5 KB |
- Field Size: 254-bit prime field
- Hash Function: Poseidon
- Merkle Tree Depth: 20 levels
- Commitment Scheme: Pedersen
- Proof System: Groth16
- Audit smart contracts
- Verify circuit constraints
- Test with real genomic data
- Set up monitoring infrastructure
- Configure access control
- Deploy multi-sig wallet
- Set up emergency pause mechanism
- Compile and verify contracts
npm run compile:production
npm run verify:bytecode- Deploy to mainnet
npm run deploy:mainnet -- --network mainnet- Verify on explorer
npm run verify:explorer -- --address CONTRACT_ADDRESS- Initialize access control
npm run init:access-control- Set up monitoring
npm run setup:monitoring# Update circuit code
vim src/circuits/brca1.circom
# Recompile circuit
npm run compile:circuit:brca1
# Generate new verification key
npm run generate:vkey:brca1
# Deploy new verifier
npm run deploy:verifier:brca1
# Update contract to use new verifier
npm run upgrade:verifier -- --circuit brca1# Deploy new implementation
npm run deploy:implementation
# Propose upgrade (multi-sig)
npm run propose:upgrade -- --new-impl NEW_ADDRESS
# Execute upgrade (after approval)
npm run execute:upgrade -- --proposal-id IDCircuit compilation fails
# Check Circom version
circom --version
# Clear build cache
rm -rf build/circuits
npm run build:circuitsProof generation timeout
# Increase timeout in config
export PROOF_GENERATION_TIMEOUT=60000
# Use optimized witness generation
npm run optimize:witnessContract deployment fails
# Check account balance
npm run check:balance
# Verify network connection
npm run test:rpc
# Use manual gas settings
npm run deploy:testnet -- --gas-price 20 --gas-limit 8000000| Operation | Gas Used | Cost (DUST) |
|---|---|---|
| Commit Genome | 85,000 | 0.0085 |
| Submit Proof | 280,000 | 0.028 |
| Verify Proof | 185,000 | 0.0185 |
| Grant Access | 45,000 | 0.0045 |
- Batch proof verifications
- Use events instead of storage where possible
- Optimize circuit constraints
- Implement proof aggregation
- Never expose private inputs to circuits
- Use secure randomness for commitments
- Implement rate limiting for proof submissions
- Regular security audits
- Monitor for unusual activity
- Implement circuit-breaking mechanisms
- Audit Report 1 - CertiK
- Audit Report 2 - Trail of Bits
See CONTRIBUTING.md for development guidelines.
- Fork the repository
- Create feature branch
- Write tests first (TDD)
- Implement changes
- Run full test suite
- Submit pull request
MIT License - see LICENSE for details.
Built on Midnight blockchain to ensure genetic data never gets exposed again
Zero-knowledge proofs for permanent genomic privacy