mirror of
https://github.com/luxfi/crypto.git
synced 2026-07-27 01:54:50 +00:00
- Consolidated all cryptographic primitives into ONE implementation each - SECP256K1: Decred (pure Go) + libsecp256k1 (CGO optimized) - Verkle/IPA: Single unified implementation replacing external deps - Added VOPRF, HPKE, and KangarooTwelve from Cloudflare CIRCL - Performance: 2-6x improvement with CGO enabled - All packages (geth, node, evm, coreth) now use luxfi/crypto - Removed github.com/ethereum/go-verkle dependency - Removed github.com/crate-crypto/go-ipa dependency - Added comprehensive precompiles for Verkle operations - Full test coverage for CGO=0 and CGO=1 builds
3.7 KiB
3.7 KiB
Crypto Consolidation Migration Plan
Overview
Consolidate all cryptographic implementations from various packages into /Users/z/work/lux/crypto to eliminate duplication and ensure consistency.
Current Situation
Duplicate Implementations Found
-
BLS Signatures
/Users/z/work/lux/node/utils/crypto/bls/- Usessupranational/blst(C library, high performance)/Users/z/work/lux/crypto/bls/- Usescloudflare/circl(Pure Go)- Decision: Keep BLST implementation for performance, move to crypto package
-
SECP256K1
/Users/z/work/lux/node/utils/crypto/secp256k1/- Full implementation/Users/z/work/lux/crypto/secp256k1/- Existing implementation- Decision: Merge best features from both
-
Keychain & Ledger
/Users/z/work/lux/node/utils/crypto/keychain/- Key management/Users/z/work/lux/node/utils/crypto/ledger/- Hardware wallet support- Decision: Move to crypto package as-is
Migration Steps
Phase 1: BLS Consolidation
-
Create new BLS structure in crypto
/Users/z/work/lux/crypto/bls/ ├── bls.go (BLST-based implementation from node) ├── bls_circl.go (CIRCL-based for compatibility) ├── interface.go (Common interface) └── bls_test.go (Unified tests) -
Merge implementations
- Primary: BLST for performance
- Fallback: CIRCL for pure Go environments
- Build tags to select implementation
Phase 2: SECP256K1 Consolidation
- Merge node SECP256K1 into crypto
- Keep best test coverage
- Maintain API compatibility
- Add RFC6979 deterministic nonce support
Phase 3: Move Supporting Infrastructure
- Keychain:
/Users/z/work/lux/crypto/keychain/ - Ledger:
/Users/z/work/lux/crypto/ledger/ - Common utilities: Extract and consolidate
Phase 4: Extract Common Crypto from Other Packages
-
From threshold package:
- Blake3 hash →
/Users/z/work/lux/crypto/hashing/blake3/ - Keep threshold-specific logic in place
- Blake3 hash →
-
From MPC package:
- Age encryption utilities →
/Users/z/work/lux/crypto/encryption/age/ - Ed25519 wrappers →
/Users/z/work/lux/crypto/ed25519/
- Age encryption utilities →
Phase 5: Update Import Paths
All imports need to be updated from:
"github.com/luxfi/node/utils/crypto/bls"
"github.com/luxfi/node/utils/crypto/secp256k1"
To:
"github.com/luxfi/crypto/bls"
"github.com/luxfi/crypto/secp256k1"
Files Requiring Import Updates
Consensus Package
/Users/z/work/lux/consensus/snowman/validator.go/Users/z/work/lux/consensus/ctx.go
Node Package
/Users/z/work/lux/node/vms/platformvm/signer/*.go/Users/z/work/lux/node/wallet/subnet/primary/*.go/Users/z/work/lux/node/staking/*.go
Implementation Plan
Step 1: Create Compatibility Layer
Create interfaces that both implementations satisfy to ensure smooth migration.
Step 2: Move and Test
- Copy node crypto to crypto package
- Update imports in crypto package
- Run tests to ensure functionality
- Update external imports one package at a time
Step 3: Remove Duplicates
Once all imports are updated and tests pass, remove the original implementations from node.
Testing Strategy
- Unit Tests: Ensure all existing tests pass
- Integration Tests: Test with consensus and node packages
- Performance Tests: Verify no performance regression
- Compatibility Tests: Ensure API compatibility
Risk Mitigation
- Backup: Keep original implementations until migration is complete
- Gradual Migration: Update one package at a time
- Feature Flags: Use build tags to switch implementations if needed
- Rollback Plan: Git tags at each migration phase