Shadow Match's security model is built on three pillars:
- Arcium's encrypted compute platform
- Solana's account model security
- Protocol-level privacy guarantees
- Order price
- Order quantity
- Trading intention (before match)
- Trader identity (optional)
// Encrypted order data structure
#[derive(ArcisType, Copy, Clone, ArcisEncryptable)]
pub struct Order {
pub id: mu64, // Order ID
pub trader: mu128, // Encrypted trader ID
pub is_buy: mbool, // Encrypted order side
pub price: mu64, // Encrypted price
pub quantity: mu64, // Encrypted quantity
pub timestamp: mu64, // Submission time
}Orders are committed on-chain using a privacy-preserving commitment scheme:
-
Hash-based commitment:
commitment = SHA256( orderID || traderPubkey || side || price || quantity || nonce )
-
Properties:
- Binding: Cannot change order after commitment
- Hiding: Cannot derive order details from commitment
- Unique: Each order has distinct commitment
-
Circuit-level privacy:
- Matching occurs in Arcium's encrypted environment
- Only match results are revealed
- Price discovery remains confidential
-
Settlement privacy:
- Token transfers reveal final execution price
- Partial fill amounts stay private
- Trading history is pseudonymous
- Front-running attacks
- Order manipulation
- Privacy leaks
- Settlement attacks
- Relayer misbehavior
- Solana network attacks
- Arcium platform compromises
- Hardware-level attacks
- Social engineering
-
Order Integrity
- Orders cannot be forged
- Commitments cannot be altered
- Matches must be valid
-
Economic Security
- No free option attacks
- Price/time priority preserved
- Fair match execution
-
Privacy Guarantees
- Order details stay encrypted
- Minimal information leakage
- Optional trader anonymity
-
Front-running
- Vector: MEV bots observing pending orders
- Mitigation: Encrypted order details + commitments
-
Order Manipulation
- Vector: Relayer reordering matches
- Mitigation: Provable fair matching in circuit
-
Privacy Leaks
- Vector: Transaction graph analysis
- Mitigation: Optional mixer integration
// PDA derivation with proper seeds
[account(
seeds = [b"order", commitment_hash.as_ref()],
bump,
payer = user,
space = OrderAccount::SIZE
)]
pub order_account: Account<'info, OrderAccount>;
// Proper authority checks
#[account(
mut,
constraint = user_account.owner == user.key()
)]
pub user_account: Account<'info, UserAccount>;
// Safe math operations
let new_balance = user_account.balance
.checked_add(amount)
.ok_or(ErrorCode::Overflow)?;// Secure matching logic
#[instruction]
pub fn match_orders(
new_order: Enc<Shared, Order>,
book_orders: Enc<Mxe, &[Order]>,
) -> Enc<Mxe, MatchResult> {
// Constant-time matching
// No control flow leaks
// Secure comparisons
}// Rate limiting
const rateLimiter = new RateLimiter({
windowMs: 15 * 60 * 1000,
max: 100
});
// Request validation
function validateOrder(order: EncryptedOrder) {
if (!order.signature || !verifySignature(order)) {
throw new Error("Invalid order signature");
}
}
// Secure WebSocket handling
wss.on('connection', (ws) => {
ws.on('message', async (msg) => {
try {
// Validate message
// Process safely
// Handle errors
} catch (e) {
ws.close();
}
});
});- All PRs require 2 approvals
- Security-critical changes need audit
- Automated security scanning
- Regular dependency audits
// Property-based testing
describe("Security Properties", () => {
it("maintains privacy", async () => {
// Generate random orders
// Verify no information leakage
// Check commitment properties
});
});
// Invariant testing
describe("Security Invariants", () => {
it("preserves balances", async () => {
// Track all balances
// Execute random trades
// Verify conservation
});
});- Circuit execution monitoring
- Unusual order patterns
- Settlement failures
- Balance discrepancies
-
Circuit compromise:
- Pause matching
- Investigate breach
- Generate new circuits
-
Contract vulnerability:
- Trigger circuit breaker
- Pause operations
- Deploy fixes
-
Assessment phase:
- Identify scope
- Evaluate impact
- Plan mitigation
-
Resolution phase:
- Deploy fixes
- Verify security
- Resume operations
- Security alerts channel
- Status page updates
- Post-mortem reports
- Dependency updates
- Error monitoring
- Performance analysis
- Circuit audits
- Contract reviews
- Integration tests
- Full security audit
- Penetration testing
- Process review