> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloak.ag/llms.txt
> Use this file to discover all available pages before exploring further.

# How Cloak works

> The SDK, the program, the circuits and your RPC, and how a private transaction moves through them

Cloak is a shielded pool on Solana. Value enters as **notes**, moves between owners inside the pool,
and leaves to public addresses. A zero-knowledge proof, built on the client, accompanies every state
change, and the on-chain program accepts nothing without one.

## The four pieces

| Piece | You | Responsible for |
| - | - | - |
| **`@cloak.dev/sdk`** | write code against it | Keys, notes, proofs, signing, submission, scanning and storage. Everything private happens here, on the client |
| **Shield Pool program** | rely on it | Verifying proofs, rejecting reused nullifiers, enforcing amounts and fees, appending commitments to each pool's Merkle tree |
| **Circuits bundle** | verify it | The proving artifacts from the trusted-setup ceremony. The SDK checks their hashes before every proof, so a substituted artifact fails closed |
| **Your RPC** | choose it | Reading chain state and sending deposits. Cloak hosts none and never proxies it |

The program is mint-scoped: each token has its own pool, treasury and Merkle tree. It collects the
withdrawal fee from that pool's own on-chain config, and nothing else in the system charges one.
See [Shield Pool program](https://docs.cloak.ag/concepts/shield-pool-program.md).

## One instruction, three directions

Shield, private send and withdraw are the same `Transact` instruction. What differs is the
public amount crossing the pool's edge:

| Public amount | Flow | Value |
| - | - | - |
| `> 0` | shield (deposit) | flows into the pool |
| `= 0` | private send | nothing leaves the pool; only ownership changes |
| `< 0` | withdraw | flows out to a public address, minus the fee |

Every transaction spends up to two notes and creates up to two. The proof shows the inputs exist in
the tree, belong to the spender and balance against the outputs:

```
sum(inputs) = sum(outputs) + public_amount
```

Private swaps use a second instruction, `TransactSwap`, which escrows the input and settles it
through Jupiter in a follow-up transaction. See [Private swaps](https://docs.cloak.ag/guides/private-swaps.md).

## A private send, end to end

1. **Open the account.** The wallet signs a fixed message once. The SDK derives the account's
   spending key, its viewing key `nk` and its `cloak_` address from the signature.
2. **Select notes.** The SDK picks unspent notes that cover the amount, merging first if more than
   two are needed.
3. **Build outputs.** One note for the recipient, one for the change. The recipient's note secrets
   are sealed to the recipient's viewing key so they can find it.
4. **Prove.** The SDK fetches Merkle paths, builds the witness and generates a Groth16 proof in
   workers on the device.
5. **Submit.** The request is signed and submitted for the user, so the user's wallet does not
   appear and pays nothing.
6. **Verify on chain.** The program checks the proof against a recent root, records the two
   nullifiers, and appends the two new commitments.
7. **Confirm.** The SDK confirms settlement from chain state and stores the change note.

The same steps run for a withdrawal, with a negative public amount and a recipient address. A shield
is signed and submitted by the funding wallet. [Transaction lifecycle](https://docs.cloak.ag/concepts/transaction-lifecycle.md)
has the per-flow detail.

## What stays private

An observer sees that a transaction touched a pool, the public amount, two nullifiers and two opaque
commitments. A private send reveals no amount and no parties. Deposits and withdrawals reveal their
public endpoints. [Privacy guarantees](https://docs.cloak.ag/concepts/privacy-guarantees.md) lists exactly what each party can
see.

## Compliance by design

Deposits carry a signed risk assessment that the program checks. Withdrawals and swaps are screened
before they are authorized. Every transaction posts a small encrypted record readable with the
sender's viewing key, which is what lets a user disclose their own history to an auditor. See
[Viewing keys and compliance](https://docs.cloak.ag/concepts/viewing-keys-compliance.md).

## Where to go next

> [card] [UTXO model](https://docs.cloak.ag/concepts/utxo-model.md)
>
> Commitments, nullifiers, keys and the Merkle tree.

> [card] [Privacy architecture](https://docs.cloak.ag/concepts/privacy-architecture.md)
>
> On-chain state, the fee model and history scanning.

> [card] [Zero-knowledge proofs](https://docs.cloak.ag/concepts/zero-knowledge-proofs.md)
>
> The circuit, the ceremony bundle and how to verify it.

> [card] [Quickstart](https://docs.cloak.ag/get-started/quickstart.md)
>
> Move money privately in a few calls.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.