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

# Provably Fair (vfair) — Verification Engine

> How Dark Matter's unified provably fair engine operates across Crash, Plinko, Limbo, Mines, and Keno with cryptographic commit-reveal verification.

# Provably Fair (vfair) Verification Engine

All Dark Matter Casino games are governed by an unalterable **vfair commit-reveal architecture**. Every game result—whether a multiplayer crash multiplier or a private single-player drop—is pre-committed before your stake is accepted.

***

## Core Architecture

The engine guarantees two mathematical properties:

1. **Pre-determination:** The server commits to the seed *before* you place your bet.
2. **Deterministic Derivation:** The outcome is computed using public, verifiable mathematical algorithms that anyone can independently execute.

```mermaid theme={null}
sequenceDiagram
    participant Player
    participant Server (vfair)
    participant Ledger / DB

    Note over Server,Ledger: PHASE 1: COMMIT
    Server->>Server: Generate Server Seed + Salt
    Server->>Ledger: Store keccak256(Server Seed)
    Server-->>Player: Public Seed Hash displayed

    Note over Player,Server: PHASE 2: PLAY
    Player->>Server: Place Bet (Client Seed + Parameters)
    Server->>Server: Compute Outcome from (Server Seed + Client Seed + Nonce)
    Server->>Ledger: Settle Result & Realized Edge

    Note over Player,Server: PHASE 3: VERIFY
    Server-->>Player: Reveal Plaintext Server Seed
    Player->>Player: keccak256(Seed) == Seed Hash
    Player->>Player: Re-run Outcome Formula
```

***

## How It Works in Practice

| Step | Action | Guarantee |
| - | - | - |
| **1. Seed Commitment** | Before betting opens, `seed_hash = keccak256(server_seed)` is committed. | The operator cannot change the outcome after seeing your bet. |
| **2. Randomness Derivation** | A uniform floating point value $u \in [0, 1)$ is derived via `keccak256(server_seed : client_seed : nonce)`. | Completely uniform, immune to timing or stake size manipulation. |
| **3. Result Generation** | The game's specific formula maps $u$ to game outcomes (multiplier, drop path, grid). | Pure, deterministic output. |
| **4. Reveal & Audit** | Upon settlement, the plaintext `server_seed` is exposed. | Anyone can run the verifier locally to prove zero manipulation. |

***

## Verifying Outcomes Yourself

Every settled round or bet exposes its raw cryptographic seeds in the in-app modal or via API.

```javascript theme={null}
// Universal vfair Verification Routine (Pure JS)
const { ethers } = require('ethers');

function verifyGame({ serverSeed, serverSeedHash, clientSeed, nonce, gameType }) {
  // 1. Verify that the revealed seed matches the committed hash
  const computedHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(serverSeed));
  if (computedHash !== serverSeedHash) {
    throw new Error("Seed tampering detected! Committed hash does not match revealed seed.");
  }

  // 2. Derive the outcome float u in [0, 1)
  const combined = ethers.utils.solidityKeccak256(
    ["string", "string", "uint256"],
    [serverSeed, clientSeed || "", nonce || 0]
  );
  const bigInt = BigInt(combined);
  const u = Number(bigInt % 100000000n) / 100000000;

  console.log(`✅ Seed integrity verified. Derived uniform float: ${u}`);
  return u;
}
```

***

## Game Formulas

### Crash

Multiplier formula with **99% RTP** (1% House Edge):
$crash = \min\left(100.00, \; \max\left(1.00, \; \left\lfloor \frac{0.99}{1 - u} \times 100 \right\rfloor \div 100\right)\right)$

### Limbo

Crash-style targeted multiplier with **99% RTP** (1% House Edge):
$multiplier = \max\left(1.00, \; \left\lfloor \frac{0.99}{1 - u} \times 100 \right\rfloor \div 100\right)$
*Win condition:* $multiplier \ge targetMultiplier$.

### Plinko

Binomial peg drop with 16 rows and **99% RTP**:
Each row step derives direction from sequential bits of the derived hash:
$bit = (hash \gg row) \;\&\; 1 \quad \implies \quad \text{0: Left}, \quad \text{1: Right}$
Bucket index is simply the sum of rights: $\sum_{i=0}^{15} bit_i \in [0, 16]$.

***

## API Audit Endpoints

You can verify any round programmatically using the public API:

```bash theme={null}
# Fetch recent verification parameters for multiplayer Crash
curl -s "https://darkmatter.rdytobash.tech/api/crash?action=verify-seeds" | jq .
```


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