EIP-712 Signing
Overview
EIP-712 is the cryptographic foundation of Frontier Chain's security model. It provides structured, human-readable signing that's compatible with all major Ethereum wallets while achieving 369K operations/second throughput through careful optimization.
Key Features:
Wallet Compatible: Works with MetaMask, WalletConnect, Ledger, etc.
Human Readable: Clear prompts showing what you're signing
Type Safe: Structured data prevents blind signing
High Performance: Pre-computed hashes for 40% CPU reduction
Cryptographically Secure: secp256k1 + Keccak256
What is EIP-712?
The Standard
EIP-712 (Ethereum Improvement Proposal 712) defines a standard for signing typed structured data.
Without EIP-712:
Sign this:
0x1234abcd5678ef90... (raw bytes, unreadable)With EIP-712:
Benefits:
Users understand what they're signing
Wallets can display structured data
Prevents phishing attacks
Industry standard
How It Works
Signing Process
1. Structure Data:
2. Compute Hash:
3. Sign Hash:
4. Verify Signature:
Domain Separator
The domain separator prevents signature reuse across different contexts.
Structure:
Purpose:
Binds signatures to specific chain
Prevents cross-chain replay
Identifies the application
Part of signed message
Computation:
Message Types
Market Orders
Structure:
Type Hash:
Signing:
Compute order hash from fields
Wrap in MarketForgeAction structure
Combine with domain separator
Sign final EIP-712 hash
Leverage Updates
Structure:
Usage:
Set leverage for perpetuals trading
Change margin mode (cross/isolated)
Signed separately from orders
Same EIP-712 wrapper
Order Cancellations
Structure:
Usage:
Cancel specific order
Must be signed by order owner
Prevents unauthorized cancellations
Includes nonce for replay protection
Agent Registration
Structure:
Usage:
Authorize agent wallet
Must be signed by main wallet
Proves ownership
Enables delegated signing
Hash Computation Details
Order Hash (Internal)
Fields (in order):
Packing:
EIP-712 Final Hash
Structure:
This final_hash is what gets signed
Pre-Computation Optimization
The Problem
Without optimization:
The Solution
Pre-compute once, include in order:
Flow:
Signature Format
Components
r (32 bytes):
First half of ECDSA signature
x-coordinate related value
s (32 bytes):
Second half of ECDSA signature
Curve point value
v (1 byte):
Recovery ID
Value: 27 or 28 (or 0/1 internally)
Allows public key recovery
Total: 65 bytes
Encoding
Byte Layout:
Example:
Signature Verification
Recovery Process
secp256k1 Recovery:
Address Derivation:
Validation
Full Verification:
Error Cases:
InvalidSignature: Malformed signature bytes
RecoveryFailed: Cannot recover public key
AddressMismatch: Recovered address ≠ expected user
InvalidHash: Hash doesn't match order data
Performance Characteristics
Throughput
With Pre-Computation:
Hash computation: ~50μs (client-side, once)
Signature verification: ~100μs per validator
Parallel processing: 369K orders/sec achieved
Without Pre-Computation:
Hash computation: ~50μs × 4 (client + 3 validators)
Total overhead: +150μs per order
Throughput reduction: ~40%
Optimization Techniques
1. Pre-Computed Hashes:
Compute once on client
Include in SignedOrder structure
Validators use directly
40% CPU reduction
2. Cached Signer Addresses:
Store recovered address in Signature struct
Skip recovery for repeated validation
Useful for order book updates
3. Parallel Verification:
Batch signature verifications
Use all CPU cores
Process multiple orders simultaneously
Achieves 369K ops/sec
4. Trust Mode (Optional):
Leader node verifies all signatures
Follower nodes trust leader
80% CPU reduction on followers
Trade-off: Trust assumption
Security Properties
Cryptographic Guarantees
Cannot Forge:
Requires private key to create valid signature
Computationally infeasible to forge
secp256k1 security (same as Bitcoin/Ethereum)
Cannot Modify:
Any change to data invalidates signature
Hash binds signature to exact data
Tampering detected immediately
Cannot Replay (with nonces):
Nonce included in signed data
Each nonce valid only once
Timestamp bounds prevent old replays
Cannot Impersonate:
Signature recovery proves ownership
Address verification enforced
No way to sign for another user
Attack Resistance
Signature Malleability:
Not vulnerable to low-s attack
Standard signature validation
Ethereum-compatible checks
Hash Collisions:
Keccak256 collision resistance
2^256 search space
Infeasible to find collisions
Domain Separation:
Chain ID prevents cross-chain replay
Application name prevents cross-app replay
Version prevents cross-version replay
Wallet Integration
MetaMask
Signing Code (JavaScript):
Hardware Wallets (Ledger)
Support:
Full EIP-712 support on Ledger Nano S/X
Displays structured data on device
User confirms on hardware device
Private key never leaves device
User Experience:
WalletConnect
Mobile Wallet Support:
EIP-712 over WalletConnect protocol
QR code connection
Mobile wallet displays typed data
Signature returned to browser
Best Practices
For Users
Verify Before Signing:
Read the structured data carefully
Check amounts, prices, sides
Verify contract address
Confirm chain ID
Security:
Only sign on trusted devices
Use hardware wallets for large amounts
Never sign blank or unclear messages
Keep wallet software updated
For Developers
Implementation:
Always use EIP-712 (not raw signatures)
Pre-compute hashes for performance
Validate all signature components
Handle errors gracefully
Testing:
Test signature generation
Verify recovery works
Check edge cases (invalid v, etc.)
Test with real wallets
Security:
Never skip signature validation
Always verify recovered address
Check nonces for replay protection
Log signature failures
Common Issues
"Invalid Signature"
Causes:
Wrong private key used
Hash mismatch (data modified)
Incorrect v value
Malformed signature bytes
Solutions:
Verify hash computation matches
Check signature byte order
Ensure v is 27 or 28
Re-sign with correct key
"Hash Mismatch"
Causes:
Field packing order wrong
Missing or extra fields
Incorrect data types
Endianness issues
Solutions:
Match exact field order in code
Use same packing as reference
Verify all fields included
Check little-endian encoding
"Recovery Failed"
Causes:
Invalid curve point
Out-of-range r or s values
Corrupted signature data
Solutions:
Validate signature bytes
Check r and s in valid range
Re-generate signature
Use known-good signature for testing
Technical Reference
Type Definitions (from codebase)
Hash Functions
Conclusion
EIP-712 provides the cryptographic foundation for Frontier Chain's security while maintaining compatibility with the Ethereum ecosystem. The pre-computation optimization achieves institutional-grade performance without sacrificing security.
Key Takeaways:
Industry-standard typed data signing
Human-readable wallet prompts
Pre-computed hashes for 40% performance gain
369K operations/second achieved
Compatible with all major Ethereum wallets
Next Steps:
Agent WalletsAuthenticationNonce ManagementLast updated