Provably Fair Randomness

Lotto Balls uses Chainlink VRF (Verifiable Random Function) to ensure all game outcomes are provably fair and cannot be manipulated.

Why Randomness Matters

In any lottery or gambling game, fair randomness is critical. Players need assurance that:

  • The house cannot predict or manipulate outcomes

  • Results cannot be influenced by miners or validators

  • The randomness source is verifiable and auditable

Chainlink VRF is the industry-standard solution for generating verifiable random numbers on blockchain.

How It Works

  1. Request: When you place a bet, the Lotto Balls contract requests a random number from Chainlink VRF

  2. Generation: Chainlink nodes generate a random number using their private key and your request data

  3. Proof: Along with the random number, a cryptographic proof is generated

  4. Verification: The smart contract verifies the proof before accepting the random number

  5. Resolution: Your bet is resolved using the verified random number

Security Guarantees

  • Unpredictable: Neither the game operators, miners, nor Chainlink nodes can predict outcomes

  • Tamper-proof: Any attempt to manipulate the random number would fail cryptographic verification

  • Transparent: The proof is publicly verifiable on-chain

Number Generation

From a single VRF random word, four numbers are derived:

This process:

  1. Takes the VRF random number

  2. Combines it with the position index (0, 1, 2, 3)

  3. Hashes the combination using keccak256

  4. Takes modulo 10 to get a number 0-9

Each position is derived independently, ensuring uniform distribution.

VRF Parameters

The Lotto Balls contract uses these Chainlink VRF settings:

Parameter
Value
Description

Confirmations

3

Block confirmations before fulfillment

Callback Gas

800,000

Gas limit for result processing

Num Words

1

Single random word requested

Payment

Native (ETH)

VRF fees paid in ETH

Timeline

After placing a bet:

  1. Transaction confirmed (~12 seconds on Base)

  2. VRF request sent (same block)

  3. Wait for confirmations (3 blocks, ~36 seconds)

  4. VRF fulfillment (Chainlink delivers random number)

  5. Bet resolved (prizes distributed automatically)

Total time: approximately 1-2 minutes

Verifying Fairness

You can verify any game result:

On-Chain Verification

  1. Find the GameResolved event for your bet

  2. Note the gameId (VRF request ID)

  3. The VRF proof is verified automatically by the contract

Public Audit

  • All VRF requests and fulfillments are visible on-chain

  • Chainlink provides a VRF explorer to track requests

  • Anyone can verify the cryptographic proofs

Emergency Handling

If a VRF callback fails (extremely rare):

  • The game owner can call manualOverrideGame(requestId)

  • This unsticks the player without awarding prizes

  • The player's "pending bet" status is cleared

  • This is logged via the ManualGameOverride event

This emergency function exists only to prevent players from being permanently locked out of the game in edge cases.

Last updated