Skip to content

Commit a224f95

Browse files
authored
docs(docs): add llm setup docs (#993)
* docs(docs): add llm setup docs * docs(docs): updated llms.txt to v4 updated llms.txt to only include Semaphore v4 --------- Co-authored-by: wslyvh <wslyvh@users.noreply.github.com>
1 parent bb089c5 commit a224f95

File tree

5 files changed

+254
-3
lines changed

5 files changed

+254
-3
lines changed

apps/docs/static/llms.txt

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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

apps/docs/versioned_docs/version-V4/credits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 13
2+
sidebar_position: 14
33
---
44

55
# Credits

apps/docs/versioned_docs/version-V4/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 12
2+
sidebar_position: 13
33
---
44

55
# FAQ
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
sidebar_position: 11
3+
---
4+
5+
# Code editors and LLM setup
6+
7+
LLMs often rely on outdated or generic information. Use this guide to help set up your code editor to pull in more accurate, up-to-date documentation and examples. It will help provide better answers and generate more accurate Semaphore code using LLMs (large language models) and MCP (Model Context Protocol) servers.
8+
9+
## Quick use
10+
11+
[llms.txt](https://docs.semaphore.pse.dev/llms.txt) is a compact, text version of the Semaphore docs.
12+
13+
Add this link directly to your chat window for enhanced context.
14+
15+
## Permanent setup
16+
17+
Depending on your IDE, you can add custom docs to VS Code, Cursor or others.
18+
19+
Example for Cursor...
20+
21+
1. Press `CMD + Shift + P` (unix), `Ctrl + Shift + P` (Windows)
22+
1. Type `Add new custom docs`.
23+
1. Add https://docs.semaphore.pse.dev/llms.txt
24+
1. In chat you can know `@docs` and choose `semaphore` to provide additional context.
25+
26+
Refer to the documentation of your IDE to properly set it up.
27+
28+
## MCP Server
29+
30+
Depending on your IDE, you can add a MCP server to communicate your docs to the AI model.
31+
32+
- [Context7 MCP server](https://github.com/upstash/context7) is a server that provides many libraries, incl. Semaphore.
33+
34+
Example for Cursor...
35+
36+
1. Press `CMD + Shift + J` (unix), `Ctrl + Shift + J` (Windows)
37+
1. Click on `MCP` on the sidebar
38+
1. Click `Add new global MCP server`
39+
1. Add the following code to `mcp.json`
40+
41+
```
42+
{
43+
"mcpServers": {
44+
"Context7": {
45+
"type": "stdio",
46+
"command": "npx",
47+
"args": ["-y", "@upstash/context7-mcp@latest"]
48+
}
49+
}
50+
}
51+
```
52+
53+
You can now prompt anything about Semaphore and write `use context7` at the end of your prompt. E.g. `create a new Semaphore identity in TypeScript. use context`. This will call the MCP tool and automatically fetch the latest documentation.
54+
55+
Refer to the documentation of your IDE to properly set it up.

apps/docs/versioned_docs/version-V4/troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 11
2+
sidebar_position: 12
33
---
44

55
import Tabs from "@theme/Tabs"

0 commit comments

Comments
 (0)