# Privacy model

A Sanctum keeps the contract source, the breach condition and the exploit encrypted from the moment they are written. Each piece is sealed in the browser (or the agent) to the exact keys that need it, and every box is bound to one task and one purpose. This page lists who can read what, then documents the sealing scheme so you can check it against the code in `warden/sealing.mjs` and `warden/terms.mjs`.

## Who reads what

| Item | Owner | Breaker (approved) | Warden | Public |
|---|---|---|---|---|
| Summary line, template, compiler, bounty, attempts, deadline | yes | yes | yes | yes |
| Contract source and exact breach condition | yes | yes, after approval | yes | `termsHash` only |
| Exploit source | — | yes (author) | yes | `exploitHash` only, in the verdict |
| Run report | yes | yes | yes (author) | — |
| Verdict outcome, `checkedAt`, signature | yes | yes | yes | yes |
| Bounty lock, release, refund | yes | yes | yes | yes, on chain |

Other Breakers who requested the Sanctum see only the public line. The SANCTRA server stores ciphertext and the public fields and relays boxes. The only private key on the service side is the Warden's; boxes sealed to an Owner or a Breaker open only with that person's own key.

## What you trust, and how to check it

- **The Warden key.** The Warden opens exploits and terms in order to run them. That is its job, and it is the one party you rely on for confidentiality during a check. Its public sealing key and signer address are published at [`/api/v1/warden`](/api/v1/warden).
- **Your own browser.** Sealing happens client-side with WebCrypto. The code is a single file you can read.
- **Everything else is checkable.** `termsHash` on chain commits to the exact terms; `exploitHash` in the verdict commits to the exact exploit; the verdict signature recovers to the Warden signer. See [Verify](/docs/verify).

## Boxes (`sanctra-box-v1`)

Each box is encrypted for one recipient public key:

1. Generate a fresh ephemeral X25519 key pair. It is discarded after encryption.
2. `shared = X25519(ephemeralPrivate, recipientPublic)`
3. `key = HKDF-SHA256(shared, salt = epk || recipientPub, info = "sanctra-box-v1|" + ctx)` → AES-256-GCM key
4. `ct = AES-256-GCM(key, iv = 12 random bytes, plaintext, additionalData = info)`

The box is plain JSON:

```json
{ "v": 1, "to": "<hex 32 bytes>", "epk": "<hex 32 bytes>", "iv": "<hex 12 bytes>", "ct": "<base64>", "ctx": "terms:0x…" }
```

### Contexts

The context string `ctx` is mixed into both the HKDF `info` and the GCM additional data, and the opener must state the context it expects. A box made for one purpose cannot be opened as another, even with the right key.

| Context | Sealed by | Sealed to |
|---|---|---|
| `terms:<taskId>` | Owner | Warden, Owner, then the approved Breaker |
| `exploit:<taskId>:<n>` | Breaker | Warden |
| `report:<taskId>:<n>` | Warden | Owner and Breaker |

`taskId` is `0x` followed by 64 lowercase hex characters; `n` is the attempt number.

## Your sealing key

Owners and Breakers do not store a private key. The app asks the wallet to sign this exact message (the text of `KEY_DERIVATION_MESSAGE` in `warden/sealing.mjs`):

```text
SANCTRA sealing key

Sign to unlock your private sealing key for Sanctra sanctums.
This signature stays in your browser and cannot move funds.
```

The key is then derived as:

```text
seed       = SHA-256( utf8("sanctra-x25519-key-v1") || signatureBytes )
privateKey = X25519 private key from seed (32 bytes)
```

Wallet signatures over a fixed message are deterministic (RFC 6979), so the same wallet always yields the same key, on any device. Only the public key is registered (`POST /api/v1/keys`).

## Commitments

The terms are `{source, compiler, scenarioEth, condition, salt}`, where `salt` is 32 random bytes. They are committed as:

```text
canonical  = JSON with keys sorted recursively, no whitespace
commitment = keccak256( utf8("sanctra-terms:v1:" + canonical) )
termsHash  = keccak256( utf8("sanctra:" + commitment) )      // commitment as 0x-prefixed lowercase hex
```

`termsHash` is what the Owner passes to `lock()` and what the Warden signs inside every verdict. The salt means a public hash cannot be matched against a guessed or already-public source.

The exploit is committed as `exploitHash = keccak256(utf8(exploitSource))`.

## What we store

Ciphertext boxes, the public task fields listed above, wallet addresses, registered public keys, verdicts and Yard runs. Yard runs are public by design: The Yard is open practice and its exploits are shown so anyone can rerun them.
