Skip to main content
The private lottery tutorial is a focused mental-model tutorial. It teaches the reveal-boundary habit: a private computation can open one authorized result without turning every private input and intermediate value into app data. Runnable source:

What this teaches

A lottery is a small version of a common product shape:
The app still owns signups, deadlines, participant slots, and winner announcement. Stoffel owns the sensitive draw. The program opens only the winner index. Use this after the Rust SDK quickstart or the private matchmaking app when you want to isolate one concept: the authorized output is not the whole computation trace.

Privacy boundary

The private computation can reveal the winner without giving the provider a board it can rerun, tune, export, or use to rank non-winners.

Code map

Read the files in this order:
  1. normal/lottery.rs: see what the trusted server can see and control.
  2. private/lottery.rs: see the authorized output model.
  3. src/client.rs: see each participant’s private eligibility payload.
  4. src/app.rs: see the Rust service compile, attach inputs, run local MPC, and map the winner index back to a participant.
  5. src/main.stfl: see private ticket generation, private comparison, private selection, and the single reveal.

Run it

From the tutorial repository root:
Then run the Stoffel project directly:
The direct CLI run returns the opened winner index for the sample slots.

What not to copy

Do not turn this into a global rule that every app should use lotteries or randomness. Copy the boundary pattern:
  1. The product needs one opened decision.
  2. The private inputs and intermediate trace are not useful product surfaces.
  3. The app names the recipient of the opened result.
  4. Everything else stays inside the private computation.

Return to the app-shaped path

After this focused tutorial, return to Build a private matchmaking service to see the same reveal-boundary habit inside a richer Rust app, or step back to the Rust SDK quickstart if you want the smallest app-shaped version of the service boundary. Use N-party Battleship hidden state when you want the next mental model: private state transitions with recipient-specific views.