|
| 1 | +# Semaphore V4 - llms.txt |
| 2 | + |
| 3 | +> Zero-knowledge protocol for anonymous group membership and signaling |
| 4 | + |
| 5 | +## Quick Reference |
| 6 | + |
| 7 | +### Core Concept |
| 8 | +Semaphore allows users to cast messages (votes, endorsements) as provable group members without revealing identity, with built-in double-signaling prevention. |
| 9 | + |
| 10 | +**Key Components:** |
| 11 | +- **Identity**: User's cryptographic identity (private key, public key, commitment) |
| 12 | +- **Group**: Merkle tree of identity commitments |
| 13 | +- **Proof**: Zero-knowledge proof of group membership + message |
| 14 | +- **Nullifier**: Unique identifier preventing double-signaling |
| 15 | +- **Scope**: Topic/context that limits one proof per user |
| 16 | + |
| 17 | +### Essential Packages |
| 18 | +```bash |
| 19 | +# Core functionality |
| 20 | +npm install @semaphore-protocol/core |
| 21 | + |
| 22 | +# Individual packages |
| 23 | +npm install @semaphore-protocol/identity |
| 24 | +npm install @semaphore-protocol/group |
| 25 | +npm install @semaphore-protocol/proof |
| 26 | +npm install @semaphore-protocol/contracts |
| 27 | +``` |
| 28 | + |
| 29 | +## Common Patterns |
| 30 | + |
| 31 | +### 1. Identity Management |
| 32 | +```javascript |
| 33 | +import { Identity } from "@semaphore-protocol/identity" |
| 34 | + |
| 35 | +// Random identity |
| 36 | +const identity = new Identity() |
| 37 | +const { privateKey, publicKey, commitment } = identity |
| 38 | + |
| 39 | +// Deterministic identity (from secret) |
| 40 | +const deterministicIdentity = new Identity("secret-value") |
| 41 | + |
| 42 | +// Sign/verify messages |
| 43 | +const message = "Hello World" |
| 44 | +const signature = identity.signMessage(message) |
| 45 | +const isValid = Identity.verifySignature(message, signature, identity.publicKey) |
| 46 | + |
| 47 | +// Export/import |
| 48 | +const exported = identity.export() // base64 private key |
| 49 | +const imported = Identity.import(exported) |
| 50 | +``` |
| 51 | + |
| 52 | +### 2. Group Operations |
| 53 | +```javascript |
| 54 | +import { Group } from "@semaphore-protocol/group" |
| 55 | + |
| 56 | +// Create group |
| 57 | +const group = new Group() |
| 58 | +const groupWithMembers = new Group([commitment1, commitment2]) |
| 59 | + |
| 60 | +// Manage members |
| 61 | +group.addMember(identity.commitment) |
| 62 | +group.addMembers([commitment1, commitment2]) |
| 63 | +group.removeMember(0) // sets to 0, doesn't change size |
| 64 | +group.updateMember(0, newCommitment) |
| 65 | + |
| 66 | +// Generate Merkle proof |
| 67 | +const merkleProof = group.generateMerkleProof(0) |
| 68 | +``` |
| 69 | + |
| 70 | +### 3. Proof Generation & Verification |
| 71 | +```javascript |
| 72 | +import { generateProof, verifyProof } from "@semaphore-protocol/proof" |
| 73 | + |
| 74 | +// Generate proof |
| 75 | +const scope = group.root // or any unique scope |
| 76 | +const message = 1 |
| 77 | +const proof = await generateProof(identity, group, message, scope) |
| 78 | + |
| 79 | +// Verify proof |
| 80 | +const isValid = await verifyProof(proof) |
| 81 | +``` |
| 82 | + |
| 83 | +### 4. On-Chain Integration |
| 84 | +```solidity |
| 85 | +// Contract setup |
| 86 | +import "@semaphore-protocol/contracts/interfaces/ISemaphore.sol"; |
| 87 | + |
| 88 | +contract YourContract { |
| 89 | + ISemaphore public semaphore; |
| 90 | + uint256 public groupId; |
| 91 | + |
| 92 | + constructor(ISemaphore _semaphore) { |
| 93 | + semaphore = _semaphore; |
| 94 | + groupId = semaphore.createGroup(); |
| 95 | + } |
| 96 | + |
| 97 | + // Validate proof on-chain |
| 98 | + function validateProof(ISemaphore.SemaphoreProof calldata proof) external { |
| 99 | + semaphore.validateProof(groupId, proof); |
| 100 | + } |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +## Configuration Reference |
| 105 | + |
| 106 | +### Circuit Parameters |
| 107 | +- **MAX_DEPTH**: 1-32 (Merkle tree depth) |
| 108 | +- **Default proof validity**: 1 hour for old Merkle roots |
| 109 | + |
| 110 | +### Key Security Settings |
| 111 | +- **Identity reuse warning**: Same identity across groups compromises all groups |
| 112 | +- **Nullifier uniqueness**: Prevents double-signaling within same scope |
| 113 | +- **Message tampering**: Circuit calculates dummy square to prevent tampering |
| 114 | + |
| 115 | +## Troubleshooting |
| 116 | + |
| 117 | +### Common Issues |
| 118 | + |
| 119 | +**"Proof verification failed"** |
| 120 | +- Check group contains identity commitment |
| 121 | +- Verify scope matches between generation and verification |
| 122 | +- Ensure Merkle proof is current (within validity window) |
| 123 | + |
| 124 | +**"Nullifier already exists"** |
| 125 | +- User already submitted proof with this scope |
| 126 | +- Use different scope or implement nullifier tracking |
| 127 | + |
| 128 | +**"Identity commitment not found"** |
| 129 | +- Add identity to group before generating proof |
| 130 | +- Verify correct group is being used |
| 131 | + |
| 132 | +## Architecture Overview |
| 133 | + |
| 134 | +### Circuit Structure |
| 135 | +The Semaphore circuit proves three things: |
| 136 | +1. **Membership**: User belongs to group (Merkle proof verification) |
| 137 | +2. **Authorization**: Same user created message and proof (nullifier check) |
| 138 | +3. **Message integrity**: Message hasn't been tampered with |
| 139 | + |
| 140 | +### Contract Architecture |
| 141 | +- **SemaphoreVerifier.sol**: Groth16 proof verification |
| 142 | +- **SemaphoreGroups.sol**: Group management (abstract) |
| 143 | +- **Semaphore.sol**: Complete implementation with proof validation |
| 144 | + |
| 145 | +## Extended Resources |
| 146 | + |
| 147 | +### 📚 Complete Guides |
| 148 | +- [Getting Started Tutorial](https://docs.semaphore.pse.dev/getting-started) - Full project setup with CLI |
| 149 | +- [Identities Deep Dive](https://docs.semaphore.pse.dev/guides/identities) - Advanced identity management |
| 150 | +- [Groups Management](https://docs.semaphore.pse.dev/guides/groups) - Comprehensive group operations |
| 151 | +- [Proof Generation](https://docs.semaphore.pse.dev/guides/proofs) - Detailed proof workflows |
| 152 | + |
| 153 | +### 🔧 Technical References |
| 154 | +- [Semaphore V4 Specification](https://github.com/zkspecs/zkspecs/blob/main/specs/3/README.md) - Protocol specification |
| 155 | +- [Circuit Documentation](https://docs.semaphore.pse.dev/technical-reference/circuits) - Circuit internals |
| 156 | +- [Contract Reference](https://docs.semaphore.pse.dev/technical-reference/contracts) - Solidity implementation details |
| 157 | +- [Deployed Contracts](https://docs.semaphore.pse.dev/deployed-contracts) - Network addresses |
| 158 | + |
| 159 | +### 🛠️ Development Tools |
| 160 | +- [GitHub Repository](https://github.com/semaphore-protocol/semaphore) - Source code and examples |
| 161 | +- [CLI Templates](https://github.com/semaphore-protocol/semaphore/tree/main/packages/cli) - Project boilerplates |
| 162 | +- [Boilerplate App](https://github.com/semaphore-protocol/boilerplate) - Complete example application |
| 163 | + |
| 164 | +### 🔐 Security & Audits |
| 165 | +- [Trusted Setup Ceremony](https://ceremony.pse.dev/projects/Semaphore%20V4%20Ceremony) - 400+ participants, July 2024 |
| 166 | +- [Security Audits](https://docs.semaphore.pse.dev/#audits) - PSE and Veridise audit reports |
| 167 | +- [Best Practices Guide](https://docs.semaphore.pse.dev/) - Security considerations section |
| 168 | + |
| 169 | +### 🌐 Community & Support |
| 170 | +- [Documentation](https://docs.semaphore.pse.dev/) - Complete documentation |
| 171 | +- [GitHub Discussions](https://github.com/semaphore-protocol/semaphore/discussions) - Community support |
| 172 | +- [PSE Website](https://pse.dev/) - Privacy & Scaling Explorations team |
| 173 | + |
| 174 | +### 📊 Data & Indexing |
| 175 | +- [@semaphore-protocol/data](https://github.com/semaphore-protocol/semaphore/tree/main/packages/data) - On-chain data fetching |
| 176 | +- [Subgraph Templates](https://github.com/semaphore-protocol/semaphore/tree/main/packages/cli-template-monorepo-subgraph) - Graph Protocol integration |
| 177 | + |
| 178 | +## Quick Start Commands |
| 179 | + |
| 180 | +```bash |
| 181 | +# Create new project |
| 182 | +npx @semaphore-protocol/cli create my-app --template monorepo-ethers |
| 183 | + |
| 184 | +# Get on-chain groups |
| 185 | +semaphore get-groups --network sepolia |
| 186 | + |
| 187 | +# Deploy contract |
| 188 | +yarn deploy --semaphore <address> --group <id> --network sepolia |
| 189 | +``` |
| 190 | + |
| 191 | +## Use Cases |
| 192 | +- **Private Voting**: Anonymous ballots with double-vote prevention |
| 193 | +- **Whistleblowing**: Anonymous reporting with verified membership |
| 194 | +- **Anonymous DAOs**: Governance without identity disclosure |
| 195 | +- **Mixers**: Privacy-preserving value transfers |
| 196 | +- **Anonymous Authentication**: Prove membership without revealing identity |
0 commit comments