Features: - Add FROST keygen and signing sessions for EdDSA/Taproot - Add LSS keygen and signing sessions with dynamic resharing - Add CBOR serialization for FROST and LSS configs (fix JSON corruption) - Add recovery byte calculation for Ethereum compatibility - Add FROST signing handler for EdDSA signatures - Upgrade threshold library to v1.5.2 Security: - Fix config serialization using CBOR instead of JSON - Add security audit findings to LLM.md - Document blockchain support matrix Files added: - frost_config_marshal.go, frost_keygen_session.go - lss_config_marshal.go, keygen_session_lss.go - signing_session_frost.go, signing_session_lss.go - recovery.go, signing_handler_frost.go
13 KiB
LLM.md - Hanzo MPC Signer Architecture & Development Guide
This document provides comprehensive guidance for AI assistants working with the Hanzo MPC (Multi-Party Computation) codebase.
📚 Overview
Hanzo MPC is a threshold signing service that provides:
- ECDSA (secp256k1) for Bitcoin/Ethereum/EVM chains
- EdDSA (Ed25519) for Solana/Polkadot/Sui
- Threshold signatures (t-of-n) with CGGMP21 protocol
- Key resharing for rotation without changing addresses
Architecture Position
Hanzo MPC is designed as a pluggable signer backend for Hanzo KMS:
┌─────────────────────────────────────────────────────────────────┐
│ Hanzo KMS (Control Plane) │
│ ┌──────────┬─────────────┬──────────────┬─────────────────┐ │
│ │ Policy │ Approvals │ Audit Log │ Key Registry │ │
│ └────┬─────┴──────┬──────┴───────┬──────┴───────┬─────────┘ │
│ │ │ │ │ │
│ ┌────▼────────────▼──────────────▼──────────────▼─────────┐ │
│ │ Unified Signing API │ │
│ └────┬────────────┬──────────────┬──────────────┬─────────┘ │
│ │ │ │ │ │
│ ┌────▼────┐ ┌────▼────┐ ┌─────▼─────┐ ┌─────▼─────┐ │
│ │ HSM │ │ MPC │ │ Software │ │ Remote │ │
│ │ Signer │ │ Signer │ │ Signer │ │ Signer │ │
│ └─────────┘ └─────────┘ └───────────┘ └───────────┘ │
└─────────────────────────────────────────────────────────────────┘
Product Architecture
-
Hanzo KMS Platform (Control Plane)
- Key registry + metadata
- Policy + workflow (quorum, time locks, spend limits, allowlists)
- Audit log
- Unified API
- Secrets manager
-
Hanzo MPC Signer (This Project - Data Plane)
- DKG / key share management
- Threshold signing sessions
- Reshare/rotate shares
- Optional hardware-rooted modes
-
Hanzo HSM (Alternative Signer)
- HSM-backed keys for classic KMS workloads
- HSM-sealed share storage for MPC nodes
-
Hanzo Treasury (Optional UI)
- Transaction building + chain adapters
- Simulation / policy previews
- Approvals UI (backed by KMS workflow engine)
🚀 Quick Start
Build and Install
# Build binaries
make build
# Or install directly
go install ./cmd/hanzo-mpc
go install ./cmd/hanzo-mpc-cli
Basic Usage
# Generate peers configuration
hanzo-mpc-cli generate-peers -n 3
# Register peers to Consul
hanzo-mpc-cli register-peers
# Generate event initiator
hanzo-mpc-cli generate-initiator
# Generate node identity
hanzo-mpc-cli generate-identity --node node0
# Start MPC node
hanzo-mpc start -n node0
📁 Project Structure
/Users/z/work/hanzo/mpc/
├── cmd/ # Command-line applications
│ ├── hanzo-mpc/ # Main MPC node binary
│ └── hanzo-mpc-cli/ # CLI tools for configuration
├── pkg/ # Core packages
│ ├── client/ # Go client library
│ ├── mpc/ # MPC implementation (TSS)
│ ├── kvstore/ # BadgerDB storage
│ ├── messaging/ # NATS messaging
│ ├── identity/ # Ed25519 identity management
│ └── eventconsumer/ # Event processing
├── e2e/ # End-to-end tests
├── examples/ # Usage examples
└── scripts/ # Utility scripts
🏗️ Core Components
1. MPC Engine
Based on threshold cryptography:
- CGGMP21 protocol for ECDSA (secp256k1) - IMPLEMENTED & TESTED
- FROST protocol for EdDSA (Ed25519) - IMPLEMENTED & TESTED (keygen generates both ECDSA and EdDSA keys)
- Configurable threshold (t-of-n)
- Default: t = ⌊n/2⌋ + 1 (majority)
2. Storage Layer: BadgerDB
- AES-256 encrypted key shares
- Session data persistence
- Automatic backups
3. Messaging: NATS JetStream
- Pub/sub for broadcasts
- Direct messaging for P2P
- Message persistence
4. Service Discovery: Consul
- Node registration
- Health checking
- Configuration management
5. Identity: Ed25519 keypairs
- Node authentication
- Message signing/verification
- Encrypted with Age
🔧 Configuration
# config.yaml
environment: development
consul:
address: localhost:8500
nats:
url: nats://localhost:4222
badger_password: "secure-password"
event_initiator_pubkey: "hex-encoded-pubkey"
Environment Variables
HANZO_MPC_CONFIG- Path to config.yamlHANZO_MPC_BACKUP- Backup file identifier
🔐 Security Model
- Threshold Security: No single node has the complete key
- Message Authentication: All messages signed with Ed25519
- Storage Encryption: BadgerDB encrypted with user password
- Network Security: TLS + mutual authentication
- Key Rotation: Supports resharing without changing addresses
📊 Performance
- Key Generation: ~30s for 3 nodes
- Signing: <1s for threshold signatures
- Storage: ~100MB per node (with backups)
- Network: Low bandwidth, resilient to failures
🔗 Integration with Hanzo Commerce
The MPC Signer integrates with Commerce for crypto payments:
// Commerce uses MPC via the processor interface
type MPCProcessor struct {
kmsClient *kms.Client // Hanzo KMS for policy/approval
mpcClient *mpc.Client // Hanzo MPC for signing
}
func (p *MPCProcessor) Charge(ctx context.Context, req PaymentRequest) (*PaymentResult, error) {
// 1. KMS validates policy and approvals
// 2. MPC signs the transaction
// 3. Transaction broadcast to blockchain
}
🔧 Development Workflow
Testing
# Run unit tests
make test
# Run with coverage
make test-coverage
# Run E2E tests
make e2e-test
Common Tasks
-
Generate 3-node test cluster:
./setup_identities.sh -
Recover from backup:
hanzo-mpc-cli recover --backup-dir ./backups --recovery-path ./recovered-db -
Production deployment:
- Use
--encryptflag for identity generation - Enable TLS on all services
- Use
--prompt-credentialsto avoid hardcoded passwords
- Use
🐛 Common Issues
- Port conflicts: Default ports are 4222 (NATS), 8500 (Consul)
- Database locks: Ensure single process per node
- Network delays: Check NATS/Consul connectivity
- Backup failures: Verify disk space and permissions
CGGMP21 Protocol Issues (Debugged Jan 2026)
-
Protocol message serialization: Protocol messages MUST use
MarshalBinary/UnmarshalBinaryto preserve all fields (SSID, RoundNumber, etc.). Raw JSON marshaling loses critical protocol state. -
Party ID ordering: Party IDs must be sorted consistently across all nodes. The
GetReadyPeersIncludeSelf()function inregistry.gosorts peer IDs to ensure deterministic ordering. -
NATS topic naming: Result topics must match JetStream stream configuration:
- Keygen results:
mpc.mpc_keygen_result.<walletID>(note thempc.mpc_prefix) - Signing results:
mpc.mpc_signing_result.<walletID> - Stream expects pattern:
mpc.mpc_*_result.*
- Keygen results:
-
Self-message rejection: It's NORMAL for nodes to log "Handler cannot accept message" warnings when they receive their own broadcast messages back. This is expected behavior in pub/sub systems.
-
Binary rebuild for e2e tests: E2E tests use
hanzo-mpcfrom PATH. After code changes, rungo install ./cmd/hanzo-mpc && go install ./cmd/hanzo-mpc-clito update the installed binaries. -
Session result publishing pattern: Individual protocol sessions (CGGMP21, FROST) should NOT publish success events directly to the result queue. The handler (
keygen_handler_cggmp21.go) is responsible for publishing the combined result with both ECDSA and EdDSA keys. Sessions should only:- Publish FAILURE events to the queue (for immediate error notification)
- Send success pubkey via
externalFinishChansoWaitForFinish()returns - Always send to
externalFinishChan(even empty string for errors) to prevent blocking
-
Dual keygen architecture: The
handleKeyGenEventCGGMP21function runs both ECDSA (CGGMP21) and EdDSA (FROST) keygen protocols in parallel via goroutines with WaitGroup. Both sessions must complete before the handler publishes the combined result containing both public keys.
FROST Signing Issues (Debugged Jan 2026)
-
FROST config serialization (CRITICAL):
frost.TaprootConfigcontains crypto types (*curve.Secp256k1Scalar,*curve.Secp256k1Point) that do NOT have JSON marshalers. Usingjson.Marshal()corrupts the key shares. MUST use CBOR serialization viaMarshalFROSTConfig()andUnmarshalFROSTConfig()infrost_config_marshal.go. -
FROST signing result type: The FROST Taproot signing protocol returns
taproot.Signature(which is[]byteof 64 bytes), NOT*frost.Signature. Thesigning_session_frost.gohandles this correctly with:s.signature = result.(taproot.Signature). -
BIP-340/Taproot signature format: FROST signing produces BIP-340 compatible signatures (64 bytes: R_x || s). The
taproot.Signaturetype is already in this format, so no additional conversion is needed inpublishResult().
LSS Protocol Issues (Fixed Jan 2026)
-
LSS config serialization (CRITICAL - FIXED): Similar to FROST,
lssConfig.Configcontains crypto types (curve.Scalar,curve.Point) that do NOT have JSON marshalers. Fixed by implementingMarshalLSSConfig()andUnmarshalLSSConfig()inlss_config_marshal.gousing CBOR serialization. -
LSS capabilities vs CGGMP21: LSS supports dynamic resharing (change T-of-N without reconstructing keys), threshold changes, and adding/removing participants. CGGMP21 only supports refresh (same committee). Both produce valid ECDSA signatures.
Security Audit Findings (Jan 2026)
-
Message authentication: Protocol messages between nodes are not signed. Ed25519 signing code exists but is disabled. Consider re-enabling for production deployments.
-
Deduplication map cleanup: The
processingmap used for deduplication grows unbounded. Recommend adding TTL-based cleanup for long-running sessions. -
Protocol timeouts: No timeout enforcement on protocol handlers. Recommend adding context with timeout to prevent indefinite hangs from stalling parties.
🌐 Blockchain Support
| Blockchain | Support | Curve | Protocol |
|---|---|---|---|
| Bitcoin (Legacy/SegWit) | ✅ Full | secp256k1 | CGGMP21/LSS |
| Bitcoin (Taproot) | ✅ Full | secp256k1 | FROST |
| Ethereum/EVM | ✅ Full | secp256k1 | CGGMP21/LSS |
| XRPL (XRP Ledger) | ✅ Full | secp256k1 | CGGMP21/LSS |
| Lux Network | ✅ Full | secp256k1 | CGGMP21/LSS |
| Solana | ⚠️ Partial | Ed25519 | FROST (Taproot mode) |
| TON | ⚠️ Partial | Ed25519 | FROST (Taproot mode) |
Note: Solana/TON use Ed25519 natively but our FROST implementation produces Taproot/BIP-340 signatures. Native Ed25519 support requires implementing the Ed25519 FROST variant.
🎯 Best Practices
- Always backup BadgerDB before major operations
- Test locally with 3-node setup before production
- Monitor health via Consul UI (http://localhost:8500)
- Rotate keys periodically using reshare functionality
- Use Age encryption for production identities
- Keep logs for debugging MPC rounds
Context for All AI Assistants
This file (LLM.md) is symlinked as:
.AGENTS.mdCLAUDE.mdQWEN.mdGEMINI.md
All files reference the same knowledge base. Updates here propagate to all AI systems.
Rules for AI Assistants
- ALWAYS update LLM.md with significant discoveries
- NEVER commit symlinked files (.AGENTS.md, CLAUDE.md, etc.) - they're in .gitignore
- NEVER create random summary files - update THIS file