Starknet Protocol
The Starknet protocol implementation provides cryptographic primitives specifically designed for the Starknet ecosystem and zero-knowledge proof systems.
Overview
The Starknet protocol uses the Stark curve (y² = x³ + x + b) and provides:
ECDSA signatures with public key recovery
ECDH key agreement on the Stark curve
Key derivation using SHA-256
Signature-based key recovery for enhanced privacy
Cryptographic Primitives
Curve Parameters
Curve: Stark curve (y² = x³ + x + b)
Field: Prime field with characteristic p
Base point: Generator point G
Order: Prime order n
Key Sizes
Private Key: 32 bytes (field element)
Public Key: 32 bytes (x-coordinate)
Ephemeral Public Key: 64 bytes (x || y coordinates)
Signature: 96 bytes (r || s || v)
Key Features
1. Public Key Recovery
The Starknet protocol supports recovering public keys from signatures and message hashes:
2. Signature-Based Encryption
You can encrypt keys using either:
Direct public key: Standard ECDH key agreement
Signature + message hash: Recover public key first, then perform ECDH
3. ECDSA Signing and Verification
Implementation Details
Key Generation
Key Agreement
Key Recovery
Usage Examples
Basic Key Encryption
Signature-Based Encryption
Key Decryption
Message Signing
Signature Verification
Data Formats
Public Key Format
Private Key Format
Signature Format
Ephemeral Public Key Format
Security Considerations
Key Management
Private Keys: Never share or log private keys
Key Generation: Use cryptographically secure random number generation
Key Storage: Store keys securely using appropriate key management systems
Signature Security
Nonce Reuse: Never reuse nonces for different messages
Message Hashing: Always hash messages before signing
Verification: Always verify signatures before processing
Curve Security
Stark Curve: Well-established curve with proven security
ECDSA: Standard signature scheme with recovery
Key Derivation: SHA-256 provides strong key derivation
Performance Characteristics
Timing Benchmarks
Key Generation
~2ms
Includes curve multiplication
Key Agreement
~3ms
ECDH computation
Signing
~5ms
ECDSA with recovery
Verification
~4ms
ECDSA verification
Key Recovery
~6ms
From signature and hash
Memory Usage
Key Storage: 32 bytes per key
Signature Storage: 96 bytes per signature
Ephemeral Keys: 64 bytes per encryption
Shared Secrets: 32 bytes (x-coordinate only)
Integration with Starknet
Smart Contract Integration
Zero-Knowledge Proofs
The Starknet protocol is designed to work with zero-knowledge proof systems:
Testing
Unit Tests
Integration Tests
Test Environment
Create a .env file for testing:
Error Handling
Common Errors
Error Recovery
Best Practices
Always verify signatures before processing
Use fresh ephemeral keys for each encryption
Hash messages before signing
Validate public keys before use
Handle errors gracefully in production code
Use secure random number generation for keys
Store keys securely using appropriate key management
Last updated