Program
This page documents the Private Raffle program’s instructions and account structures.Account Structures
Lottery
The main raffle account:Ticket
Each player’s ticket:Instructions
create_lottery
Creates a new raffle.buy_ticket
Purchase a ticket with an encrypted guess.- Transfers ticket price to vault
- Creates encrypted handle from guess
- Stores ticket with encrypted guess
- Allows buyer to decrypt their own guess
draw_winner
Authority sets the encrypted winning number and closes the raffle.- Verifies caller is authority
- Closes the raffle (
is_open = false) - Stores encrypted winning number
check_winner
Compares a ticket’s guess against the winning number (encrypted comparison).- Uses
e_eqto compareguess_handlewithwinning_number_handle - Stores encrypted boolean result in
is_winner_handle - Allows ticket owner to decrypt the result
claim_prize
Calculates the encrypted prize amount based on win/loss status.- Creates encrypted prize amount (vault balance)
- Creates encrypted zero
- Uses
e_select: if winner, get prize; else get 0 - Stores encrypted prize amount
- Marks ticket as claimed
withdraw_prize
Winner withdraws their prize with on-chain signature verification.- Verifies ticket owner and claimed status
- Verifies Ed25519 signature on-chain (proves decryption is valid)
- Parses plaintext to get prize amount
- Rejects if prize is 0 (not a winner)
- Transfers SOL from vault to winner
Error Codes
PDA Seeds
| Account | Seeds |
|---|---|
| Lottery | ["lottery", lottery_id] |
| Vault | ["vault", lottery_pubkey] |
| Ticket | ["ticket", lottery_pubkey, buyer_pubkey] |