
Legionは、プライバシーを重視して構築されたゼロ知識認証ファブリックです。
ハードウェアにバインドされたデバイスリング署名による真のゼロ知識認証
Legionは、自分が誰であるかを明かすことなく、承認されていることを証明するパスワードレスなゼロ知識認証システムです。
指紋 + 24語のリカバリフレーズ(MetaMaskのような)だけで認証できます。ユーザー名もパスワードもサーバー側の秘密も不要です。
git clone https://github.com/deadends/legion.git cd legion
chmod +x scripts/install.sh && ./scripts/install.sh
scripts\install.bat
**これで完了です!** ブラウザで http://localhost を開いてください。
### インストールされるもの
- ✅ Redis(セッションストレージ)
- ✅ Legion Server(ZKプルーフ検証器)
- ✅ Frontend(WASMクライアント)
- ✅ Nginx(リバースプロキシ)
**パフォーマンス**:登録 約5秒、認証 約2分(k=14 プルーフ生成)
---
### 手動セットアップ(Docker不使用)
<details>
<summary>クリックして手動インストールを展開</summary>```bash
# 1. Install Redis
# macOS: brew install redis && redis-server
# Ubuntu: sudo apt install redis && redis-server
# Windows: https://redis.io/docs/install/install-redis/install-redis-on-windows/
# 2. Run server (terminal 1)
cd legion-server
cargo run --release --features redis
# 3. Build frontend (terminal 2)
cd wasm-client
wasm-pack build --target web --release
python3 -m http.server 8000
# 4. Open http://localhost:8000
本番環境へのデプロイについては、DEPLOYMENT.md を参照してください
テストハードウェア: Lenovo IdeaPad 3 - Intel Core i3 11th Gen
注記: パフォーマンスはハードウェアの仕様によって異なる場合があります。
内訳:
内訳:
重要: パラメータ生成と鍵生成は一回限りのコストであり、キャッシュ可能です。キャッシュされると、検証は k 値に応じて約108〜967msしかかかりません。現在の実装ではパラメータはまだキャッシュされていません。
以前のベンチマークより遅いのはなぜか? パスワードレス回路は、1つの代わりに2つのMerkleツリー(ユーザー+デバイス)を検証するようになり、真のデバイスレベルの匿名性(ユーザーごとに1024台中1台のデバイス)を提供します。
📖 暗号技術の詳細を含むステップバイステップの認証フローについては、ARCHITECTURE_FLOW.md を参照してください
┌─────────────────────────────────────────────────────────────────────────┐ │ CLIENT (Browser + WASM) │ ├─────────────────────────────────────────────────────────────────────────┤ │ ┌────────────────┐ ┌─────────────────┐ ┌──────────────────────────┐ │ │ │ UI Layer │ │ WASM Prover │ │ Local Storage │ │ │ │ (Vanilla JS) │ │ (Rust→WASM) │ │ (IndexedDB) │ │ │ ├────────────────┤ ├─────────────────┤ ├──────────────────────────┤ │ │ │ • Registration │ │ • Blake3 Hash │ │ • Full Merkle Tree │ │ │ │ • Login Form │ │ • BIP-39 Derive │ │ • Device Trees │ │ │ │ • Session UI │ │ • Halo2 Prover │ │ • WebAuthn Credentials │ │ │ │ • Tree Sync │ │ • Merkle Proof │ │ • Tree Version Cache │ │ │ └────────────────┘ │ • Ring Sigs │ └──────────────────────────┘ │ │ └─────────────────┘ │ │ ┌──────────────────────────────────────────────────────────────────┐ │ │ │ Hardware Security (WebAuthn Level 2) │ │ │ ├──────────────────────────────────────────────────────────────────┤ │ │ │ • TPM 2.0 / Secure Enclave • FIDO2 Authenticator │ │ │ │ • Device Private Key (ECDSA) • Biometric/Touch Required │ │ │ └──────────────────────────────────────────────────────────────────┘ │ └────────────────────────────────┬────────────────────────────────────────┘ │ HTTPS/TLS 1.3 │ (Encrypted Channel) ▼ ┌──────────────────────────────────────────────────────────────────────────┐ │ LEGION SERVER (Rust/Axum) │ ├──────────────────────────────────────────────────────────────────────────┤ │ ┌─────────────────────────────────────────────────────────────────┐ │ │ │ API Layer (Axum) │ │ │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ POST /api/register-blind │ Blind registration │ │ │ │ GET /api/download-tree │ Download full Merkle tree │ │ │ │ POST /api/verify-anonymous-proof │ Verify ZK proof │ │ │ │ POST /api/verify-session │ Session validation │ │ │ │ POST /api/webauthn/* │ WebAuthn endpoints │ │ │ │ GET /health │ Health check │ │ │ └─────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ┌─────────────────────────────────────────────────────────────────┐ │ │ │ Business Logic Layer │ │ │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ • Blind Registration │ • Tree Synchronization │ │ │ │ • ZK Proof Verifier │ • Nullifier Tracker (replay) │ │ │ │ • Session Manager │ • Linkability Tag Validator │ │ │ │ • WebAuthn Service │ • Timestamp Validator (±10min) │ │ │ │ • Device Revocation │ • Rate Limiter (5/hour) │ │ │ └─────────────────────────────────────────────────────────────────┘ │ │ │ │ │ ┌─────────────────────────────────────────────────────────────────┐ │ │ │ Cryptographic Layer │ │ │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ • Halo2 Verifier (PLONK) │ • Poseidon Hash (ZK-friendly) │ │ │ │ • Blake3 (credential) │ • BIP-39 (recovery phrase) │ │ │ │ • Merkle Tree (2^20) │ • Device Trees (2^10 per user) │ │ │ │ • Ring Signature Verify │ • WebAuthn Signature Verify │ │ │ └─────────────────────────────────────────────────────────────────┘ │ └────────────────────────┬──────────────────────┬──────────────────────────┘ │ │ ▼ ▼ ┌────────────────────────┐ ┌───────────────────────────┐ │ Redis (In-Memory) │ │ RocksDB (Persistent) │ ├────────────────────────┤ ├───────────────────────────┤ │ • Session Tokens │ │ • Merkle Tree Leaves │ │ • Linkability Tags │ │ • Device Trees │ │ • Spent Nullifiers │ │ • Nullifier History │ │ • Rate Limit Counters │ │ • WebAuthn Credentials │ │ TTL: 1 hour │ │ • Revoked Devices │ └────────────────────────┘ └───────────────────────────┘
### 認証フロー(簡略版)```
┌─────────────┐ ┌──────────────┐
│ Client │ │ Server │
│ (Browser) │ │ (Verifier) │
└──────┬──────┘ └──────┬───────┘
│ │
│ 1. Generate 24-word recovery phrase (BIP-39) │
│ → 256-bit entropy (like MetaMask) │
│ → User writes down on paper │
│ │
│ 2. Derive account_id from phrase (Blake3) │
│ account_id = Blake3("LEGION_ACCOUNT_V2" || bip39_seed) │
│ → Deterministic, no server interaction │
│ │
│ 3. Hash account_id for tree leaf (Poseidon) │
│ credential_hash = Poseidon(account_id) │
│ │
│ 4. Blind registration (TRUE zero-knowledge) ────►│
│ → Sends ONLY credential_hash (no phrase/identity) │
│ → Server adds to tree, returns tree_index │
│ ◄────│ {tree_index: 114}
│ │
│ 5. Download full Merkle tree (one-time sync) ────►│
│ → Client stores entire tree in IndexedDB │
│ → Enables TRUE zero-knowledge (no server queries) │
│ ◄────│ {tree_data: [all leaves],
│ │ merkle_root, version}
│ │
│ 6. Generate WebAuthn key (TPM/Secure Enclave) │
│ → Fingerprint prompt creates hardware-bound key │
│ → device_pubkey (ECDSA P-256, non-exportable) │
│ → Stored in TPM 2.0 / Secure Enclave │
│ │
│ 7. Register device in device tree ────►│
│ → device_commitment = Blake3(credential_id) │
│ → Server converts to valid field element if needed │
│ → Server adds to user's device tree (1 of 1024 slots) │
│ ◄────│ {device_position: 0,
│ │ device_tree_root}
│ │
│ 8. LOGIN: Touch fingerprint to authenticate │
│ → WebAuthn verifies hardware-bound key │
│ → Decrypts recovery phrase from local storage │
│ → Re-derives account_id from phrase │
│ │
│ 9. Fetch device Merkle proof ────►│
│ → Sends account_id (derived from phrase) │
│ → Server returns device tree path │
│ ◄────│ {device_path: [siblings],
│ │ device_root}
│ │
│ 10. Compute user Merkle proof CLIENT-SIDE │
│ → Uses local tree from IndexedDB │
│ → Computes path for tree_index │
│ → Server NEVER learns which user! │
│ │
│ 11. Compute nullifier (replay protection) │
│ nullifier = Poseidon(account_id || challenge) │
│ → ONE-TIME USE: Different every login │
│ → Prevents proof replay attacks │
│ │
│ 12. Compute linkability tag (session binding) │
│ linkability_tag = Blake3(device_pubkey || nullifier) │
│ ⚠️ Binds session to specific device+user │
│ │
│ 13. Generate ZK proof (Halo2 PLONK, ~2min for k=14) │
│ Proves in zero-knowledge: │
│ ✓ User exists in Merkle tree (1 of 2^20) │
│ ✓ Device exists in device tree (1 of 2^10) │
│ ✓ account_id hashes to credential_hash │
│ ✓ Nullifier computed correctly │
│ ✓ Timestamp is fresh │
│ WITHOUT revealing which user or device │
│ │
│ 14. Submit proof ────►│
│ {proof, public_inputs, linkability_tag, k=14} │
│ │ • Check device not revoked
│ │ • Verify timestamp (±10min)
│ │ • Rate limit check (5/hour)
│ │ • Check nullifier (replay?)
│ │ • Verify ZK proof (~115s)
│ │ • Mark nullifier as used
│ │
│ ◄────│ {session_token, expires_at}
│ │
│ 15. Verify session (every request) ────►│
│ {session_token, linkability_tag} │
│ │ • Lookup in Redis
│ │ • Verify linkability_tag
│ │ (prevents session theft)
│ │ • Check not spent
│ ◄────│ {valid: true}
│ │
🔍 詳細を知りたいですか? ARCHITECTURE_FLOW.md を参照してください:
┌─────────────────────────────────────────────────────────────────────────┐ │ SESSION SECURITY MECHANISMS │ ├─────────────────────────────────────────────────────────────────────────┤ │ │ │ 1. LINKABILITY TAG (Zero-Knowledge Device Binding) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ linkability_tag = Blake3(device_pubkey || nullifier) │ │ │ │ • Computed client-side using hardware-bound device key │ │ • Sent with every session validation request │ │ • Server verifies: stored_tag == provided_tag │ │ │ │ ✅ PREVENTS: Session token theft/replay on different device │ │ ✅ ENSURES: Same user + same device for entire session │ │ ✅ MAINTAINS: Zero-knowledge (server doesn't learn identity) │ │ │ │ ───────────────────────────────────────────────────────────────── │ │ │ │ 2. SESSION TOKEN (Cryptographic Binding) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ session_token = Poseidon(nullifier || timestamp || linkability_tag) │ │ │ │ • Generated server-side after proof verification │ │ • Stored in Redis with linkability_tag as value │ │ • Cannot be forged without knowing nullifier │ │ │ │ ✅ PREVENTS: Token forgery │ │ ✅ ENSURES: Cryptographic binding to proof │ │ │ │ ───────────────────────────────────────────────────────────────── │ │ │ │ 3. NULLIFIER (Replay Protection) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ nullifier = Poseidon(credential_hash || challenge) │ │ │ │ • Unique per authentication attempt │ │ • Tracked in RocksDB (permanent) and Redis (cache) │ │ • Server rejects if nullifier seen before │ │ │ │ ✅ PREVENTS: Proof replay attacks │ │ ✅ ENSURES: One-time use per challenge │ │ │ │ ───────────────────────────────────────────────────────────────── │ │ │ │ 4. TIMESTAMP VALIDATION (Time-Bound Security) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ • Proof includes timestamp (Unix epoch) │ │ • Server validates: |proof_time - server_time| < 5 minutes │ │ • Session TTL: 1 hour (sliding window) │ │ │ │ ✅ PREVENTS: Old proof replay │ │ ✅ ENSURES: Fresh authentication │ │ │ │ ───────────────────────────────────────────────────────────────── │ │ │ │ 5. CHALLENGE-RESPONSE (Freshness Guarantee) │ │ ═══════════════════════════════════════════════════════ │ │ │ │ • Server generates random 32-byte challenge │ │ • Stored in Redis with 5-minute TTL │ │ • Client must include in proof │ │ • Server verifies challenge matches and deletes │ │ │ │ ✅ PREVENTS: Pre-computed proof attacks │ │ ✅ ENSURES: Proof generated for this specific session │ │ │ └─────────────────────────────────────────────────────────────────────────┘
## 🔐 ゼロ知識特性
### サーバーが把握できること
- ✅ 匿名性セット内の誰かが認証済み
- ✅ 証明が暗号学的に有効
- ✅ リンカビリティタグによる同一ユーザー+デバイス
- ✅ レート制限ステータス(残り試行回数)
- ✅ デバイス失効ステータス
- ✅ 登録ユーザー総数
- ✅ マークルツリールート(公開)
### サーバーが把握できないこと
- ❌ 特定のユーザーが誰か(100万分の1)
- ❌ 特定のデバイスがどれか(ユーザーごとに1000分の1)
- ❌ リカバリーフレーズ(BIP-39シード)
- ❌ account_id(フレーズから派生)
- ❌ デバイス秘密鍵(TPM/Secure Enclave内)
- ❌ どのツリーリーフがどのユーザーに属するか
- ❌ ユーザーのマークルパス(クライアント側で計算)
- ❌ ユーザーのtree_indexの位置
## 📦 デプロイ
詳細な本番デプロイガイドについては [DEPLOYMENT.md](https://github.com/deadends/legion/blob/HEAD/docs/DEPLOYMENT.md) を参照してください。
### Dockerによるクイックデプロイ```bash
# Production build
docker-compose -f deployment/docker-compose.yml up -d
# Check logs
docker-compose -f deployment/docker-compose.yml logs -f legion-server
# Check health
curl http://localhost/health
RUST_LOG=info LEGION_DATA_PATH=/var/lib/legion/data REDIS_URL=redis://127.0.0.1:6379
## 🧪 テスト```bash
# Run all tests
cargo test --workspace
# Run with Redis features
cargo test --workspace --features redis
# Benchmark
cargo bench
コントリビューション歓迎! 最初に CONTRIBUTING.md をお読みください。
git checkout -b feature/amazing)git commit -m 'Add amazing feature')git push origin feature/amazing)セキュリティの問題を発見しましたか? 責任ある開示については SECURITY.md を参照してください。
絶対に 脆弱性について公開の issue を開かないでください。
MIT ライセンス - 詳細は LICENSE ファイルを参照してください。
主な変更点:
アーキテクチャ:
主な変更点:
追加:
セキュリティ修正:
プライバシーとセキュリティのために ❤️ を込めて作られました
| プロパティ | 保証 |
|---|
| 認証 | パスワードレス (BIP-39 + 指紋) |
| ユーザーの匿名性 | 2^20分の1 (1,048,576) |
| デバイスの匿名性 | ユーザーごとに 2^10分の1 (1,024) |
| 健全性エラー | 2^-128 |
| 証明システム | Halo2 PLONK (透過的セットアップ) |
| 認証情報の導出 | Blake3 (BIP-39 シード) |
| ハードウェア結合 | WebAuthn Level 2 (TPM/Secure Enclave) |
| マルチデバイス | アカウントごとに最大2台 |
| レート制限 | 1時間あたり5回の試行 |
| デバイス失効 | 即時ブラックリスト |
| セキュリティレベル | k | 証明時間 | 証明サイズ | 用途 |
|---|
| 開発 | 12 | ~30s | 3.2 KB | テスト |
| 本番 | 14 | ~2min | 3.4 KB | 推奨 |
| メトリクス | 値 | 備考 |
|---|
| 証明サイズ | 3,264バイト | 圧縮後 3.19 KB |
| 公開入力 | 10 | ユーザーツリールート、デバイスツリールート、nullifier など |
| パラメータ生成 | 7.03s | k 値ごとの一回限りのセットアップ |
| 回路作成 | 2.3µs | 無視できるオーバーヘッド |
| 検証鍵生成 | 1.29s | 一回限りの鍵生成 |
| 証明検証 | 107.7ms | 実際のZK証明チェック |
| 合計検証 | 8.43s | エンドツーエンド(キャッシュなし) |
| メトリクス | 値 | 備考 |
|---|
| 証明サイズ | 3,392バイト | 圧縮後 3.31 KB |
| 公開入力 | 10 | ユーザーツリールート、デバイスツリールート、nullifier など |
| パラメータ生成 | 100.78s | k 値ごとの一回限りのセットアップ |
| 回路作成 | 5µs | 無視できるオーバーヘッド |
| 検証鍵生成 | 12.89s | 一回限りの鍵生成 |
| 証明検証 | 967.2ms | 実際のZK証明チェック |
| 合計検証 | 114.65s | エンドツーエンド(キャッシュなし) |