Skip to content

Security: 1BDO/shadow_match

Security

docs/SECURITY.md

Security & Privacy Considerations

Overview

Shadow Match's security model is built on three pillars:

  1. Arcium's encrypted compute platform
  2. Solana's account model security
  3. Protocol-level privacy guarantees

Privacy Features

1. Order Privacy

Protected Information

  • Order price
  • Order quantity
  • Trading intention (before match)
  • Trader identity (optional)

Implementation

// 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
}

2. Commitment Scheme

Orders are committed on-chain using a privacy-preserving commitment scheme:

  1. Hash-based commitment:

    commitment = SHA256(
        orderID || 
        traderPubkey || 
        side || 
        price || 
        quantity || 
        nonce
    )
  2. Properties:

    • Binding: Cannot change order after commitment
    • Hiding: Cannot derive order details from commitment
    • Unique: Each order has distinct commitment

3. Match Privacy

  1. Circuit-level privacy:

    • Matching occurs in Arcium's encrypted environment
    • Only match results are revealed
    • Price discovery remains confidential
  2. Settlement privacy:

    • Token transfers reveal final execution price
    • Partial fill amounts stay private
    • Trading history is pseudonymous

Security Model

1. Threat Model

In Scope

  • Front-running attacks
  • Order manipulation
  • Privacy leaks
  • Settlement attacks
  • Relayer misbehavior

Out of Scope

  • Solana network attacks
  • Arcium platform compromises
  • Hardware-level attacks
  • Social engineering

2. Security Properties

  1. Order Integrity

    • Orders cannot be forged
    • Commitments cannot be altered
    • Matches must be valid
  2. Economic Security

    • No free option attacks
    • Price/time priority preserved
    • Fair match execution
  3. Privacy Guarantees

    • Order details stay encrypted
    • Minimal information leakage
    • Optional trader anonymity

3. Attack Vectors & Mitigations

  1. Front-running

    • Vector: MEV bots observing pending orders
    • Mitigation: Encrypted order details + commitments
  2. Order Manipulation

    • Vector: Relayer reordering matches
    • Mitigation: Provable fair matching in circuit
  3. Privacy Leaks

    • Vector: Transaction graph analysis
    • Mitigation: Optional mixer integration

Implementation Security

1. Smart Contract Security

// 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)?;

2. Circuit Security

// 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
}

3. Relayer Security

// 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();
        }
    });
});

Audit & Review Process

1. Code Review Guidelines

  • All PRs require 2 approvals
  • Security-critical changes need audit
  • Automated security scanning
  • Regular dependency audits

2. Testing Requirements

// 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
    });
});

3. Monitoring & Alerts

  • Circuit execution monitoring
  • Unusual order patterns
  • Settlement failures
  • Balance discrepancies

Incident Response

1. Emergency Procedures

  1. Circuit compromise:

    • Pause matching
    • Investigate breach
    • Generate new circuits
  2. Contract vulnerability:

    • Trigger circuit breaker
    • Pause operations
    • Deploy fixes

2. Recovery Process

  1. Assessment phase:

    • Identify scope
    • Evaluate impact
    • Plan mitigation
  2. Resolution phase:

    • Deploy fixes
    • Verify security
    • Resume operations

3. Communication

  • Security alerts channel
  • Status page updates
  • Post-mortem reports

Regular Security Reviews

1. Weekly

  • Dependency updates
  • Error monitoring
  • Performance analysis

2. Monthly

  • Circuit audits
  • Contract reviews
  • Integration tests

3. Quarterly

  • Full security audit
  • Penetration testing
  • Process review

There aren't any published security advisories