Devnet

Test funds only. Transactions are not real.

How It Works

Step-by-step explanation of the Daily Lottery process from ticket purchase to winner payout.

The Complete Lottery Flow

This page walks through every step of a Daily Lottery, explaining what happens on-chain and how you can verify each phase.

Phase 1: Lottery Creation

An admin creates a new lottery by calling the program to create the Lottery and Vault PDAs.

This creates an on-chain lottery account with:

  • Unique lottery ID
  • Buy and upload windows
  • Prize pool (starts at 0)
  • Status: Active

Each lottery has a deterministic Program Derived Address (PDA) that stores all lottery data. This address is derived from the config + lottery ID and can be looked up by anyone.

Phase 2: Ticket Purchase

User Flow

1

Connect Wallet

User connects their Solana wallet to the Daily Lottery app.

2

Select Tickets

User chooses number of tickets and enters a lucky secret (kept private until upload).

3

Approve Transaction

User signs a transaction that transfers SOL and mints their tickets.

4

Receive Confirmation

Participant account is created or updated and linked to the user's wallet.

What Happens On-Chain

When a ticket is purchased:

  1. SOL is transferred from user to lottery pool account
  2. A participant account is created or updated (PDA from lottery + wallet)
  3. Proof-of-chance hash is stored on first purchase (lucky secret + random salt)
  4. Lottery account is updated: participant count, ticket totals, prize pool

Participant Data Structure

FieldTypeDescription
walletPubkeyParticipant wallet
proof_of_chance_hash[u8; 32]Hash of lucky secret + random salt
tickets_boughtu64Total tickets for participant
attested_uploadedboolAttested during upload window
voted_number_of_winnersu64Vote for winner count
reveal_scoreu64Informational score derived from lucky secret

Phase 3: Upload Window & Attestation

When the buy window ends, the upload window opens:

  1. Upload lucky secret: Participants send their lucky secret to the provider
  2. Attest on-chain: Participants submit an attestation with their winner-count vote
  3. Accountability: Winner count is locked from attester votes; reveal inclusion is tracked on-chain per participant

Phase 4: Provider Uploads & Verification

The provider uploads batched lucky secrets for attested participants with available reveal data. The program:

  1. Verifies each lucky secret against its on-chain hash
  2. Marks participants as reveal-included for settlement eligibility
  3. Computes a reveal score for analytics/transparency
  4. Computes the selected winner count from weighted attester votes

The result is a deterministic, public settlement input stored on-chain.

Phase 5: Winner Selection & Settlement

After uploads complete (or after upload deadline with partial reveals), winner selection runs from the reveal-included subset:

Selection Algorithm

S0 = SHA256(0x494B494741495F5250445F56325F53454544 || lottery_id || eligible_count || total_revealed_tickets || poc_aggregate_hash)
S = hash-chain over sorted reveal-included (wallet, tickets)
round_j = SHA256(0x494B494741495F5250445F56325F44524157 || S || j) % remaining_tickets
walk ticket ranges in wallet order to find winner
remove winner, repeat for k winners

Key properties of this algorithm:

  • Deterministic: Same inputs always produce same outputs
  • Reproducible: Anyone with the on-chain data can verify winners
  • Weighted: Ticket counts define each participant's range
  • Multi-winner: Winner count comes from weighted attester votes

See Winner Selection for the full algorithm, tie breaks, and worked examples.

After winners are selected:

  1. Winners are finalized and stored on-chain
  2. Prize amounts are calculated
  3. Payouts are processed in batches and can be audited

Prize Calculation

prize_per_winner = (total_pool * (1 - protocol_fee)) / selected_winner_count

Prizes remain claimable indefinitely. There's no expiration on claiming your winnings.

Verifying Each Step

Every step described above creates an on-chain event that can be audited:

EventWhat to Verify
Lottery CreatedParameters and windows match expectations
Tickets PurchasedYour commitment and ticket totals are correct
Upload Phase BeganUpload window timing is correct
Attestation SubmittedYour attestation and vote are recorded
Reveals UploadedLucky secrets match on-chain hashes
Winners FinalizedAlgorithm matches documented behavior
Payouts CompleteCorrect amounts transferred

See AI Audit Flow for detailed verification instructions.

Edit this pageLast updated: January 2026