Skip to main content
A complete reference implementation demonstrating how to build a privacy-preserving orderbook on Solana using Privora’s FHE capabilities.

Why Privacy Matters in Trading

Traditional orderbooks expose sensitive information:
Exposed DataPrivacy Risk
Order pricesFront-running attacks
Order quantitiesPosition size exposure
Trade historyTrading strategy leakage
With FHE, orders are matched without revealing prices or quantities to anyone - not even the validators processing transactions.

Architecture Overview

┌─────────────┐    Submit Order     ┌────────────────┐
│   Trader    │ ──────────────────→ │   Orderbook    │
│  (Client)   │                     │   (Program)    │
└─────────────┘                     └────────────────┘
      │                                     │
      │ Encrypt                             │ Match
      ▼                                     ▼
┌─────────────┐                     ┌────────────────┐
│ FHE Public  │                     │ FHE Operations │
│    Key      │                     │ (Encrypted)    │
└─────────────┘                     └────────────────┘


                                    ┌────────────────┐
                                    │ Match Result   │
                                    │ (Encrypted)    │
                                    └────────────────┘

Key Features

Encrypted Orders

Prices and quantities are encrypted client-side before submission

Private Matching

Orders matched using FHE comparisons - no plaintext exposure

Minimal Storage

Only 32-byte hash references stored on-chain

Authorization Control

PDAs control who can decrypt match results

Data Flow

1

Encrypt Order

Client encrypts price and quantity using FHE public key
2

Submit to Store

Encrypted data submitted to content-addressable store, receives hash
3

Create Order

Order account created with EncryptedRef hashes (32 bytes each)
4

Match Orders

Program loads encrypted data, performs FHE comparison and min
5

Store Result

Fill price and quantity stored, authorization PDAs created
6

Decrypt

Authorized users can request decryption of their fill details

Program Structure

fhe_orderbook/
├── src/
│   ├── lib.rs           # Entry point, instruction enum
│   ├── state.rs         # Order, Orderbook, MatchResult structs
│   └── instructions.rs  # Handler functions
└── tests/
    └── orderbook_test.rs # Integration tests

Account Sizes

The orderbook uses minimal account space by storing only hash references:
AccountSizeContents
Order106 bytesowner, price_ref, qty_ref, side, status, order_id
Orderbook56 bytesauthority, next_order_id, counters
MatchResult88 bytesorder IDs, fill_price_ref, fill_qty_ref, match_id
Compare to storing raw ciphertexts (~4KB each), this is a 40x reduction.

Instructions

InstructionDescription
InitializeCreate orderbook with authority
SubmitOrderSubmit buy/sell order with encrypted price and quantity
MatchOrdersMatch a buy and sell order using FHE
CancelOrderCancel an open order (owner only)

Next Steps

State Structures

Learn about Order, Orderbook, and MatchResult

Instructions

See instruction implementations

Matching Logic

Understand FHE comparison and min

Client Usage

Integrate with frontend