Skip to content

Rapha-btc/funluck

Repository files navigation

FunLuck - Provably Fair Rock Paper Scissors

A decentralized Rock Paper Scissors game built on Stacks using commit-reveal scheme for provably fair gameplay.

🎮 How It Works

Commit-Reveal Scheme

  1. Commit Phase: Players secretly commit to their moves using cryptographic hashes
  2. Reveal Phase: Players reveal their actual moves, proving they match their commitments
  3. Resolution: Smart contract determines winner and distributes rewards

Key Features

  • Provably Fair: Impossible to cheat using cryptographic commitments
  • No Gas Fees for Players: Users only sign messages off-chain
  • MEV Resistant: Moves are hidden until both players reveal
  • Internal Balance System: Deposit once, play multiple games
  • Automatic Fee Collection: 2.5% fee on winnings for platform sustainability

🔧 Technical Architecture

Trust Model

  • Players trust the backend to execute reveals fairly (similar to poker sites)
  • Backend cannot cheat - outcomes are cryptographically enforced
  • Backend cannot steal funds - only execute what players signed
  • Timeout protection - players can reclaim stakes if backend goes offline

Message Signing

Players sign structured messages containing:

Commit Message:

FUN_COMMIT:{contract_address}:{game_id}:{commitment_hash}:{stake}

Reveal Message:

FAK_REVEAL:{contract_address}:{game_id}:{move}:{salt}

Security Features

  • Signature replay protection: Each signature can only be used once
  • Cross-contract protection: Messages bound to specific contract address
  • Commitment verification: Reveals must match original commitments
  • Balance validation: Players cannot stake more than they have

📋 Contract Functions

Player Functions

  • deposit(amount) - Deposit STX to get internal balance
  • withdraw(amount) - Withdraw internal balance to STX
  • get-balance(user) - Check user's internal balance

Game Functions

  • commit-game(...) - Process both players' commitments and stakes
  • reveal-game(...) - Process reveals and determine winner
  • timeout-claim(game-id) - Reclaim stakes if game times out (24 hours)

Admin Functions

  • operator-withdraw() - Withdraw collected fees to operator address

🎯 Game Rules

Rock Paper Scissors Logic:

  • Rock beats Scissors
  • Paper beats Rock
  • Scissors beats Paper
  • Same moves = Tie (full refund)

Payouts:

  • Winner: Gets opponent's stake minus 2.5% fee
  • Tie: Both players get full refund
  • Timeout: Both players get full refund after 24 hours

🔒 Security Considerations

What Players Trust

  • Backend will execute reveals fairly (reputation-based)
  • Backend will stay online and operational
  • Backend won't discriminate based on game outcomes

What's Cryptographically Guaranteed

  • Players cannot change moves after commitment
  • Backend cannot modify game outcomes
  • All transactions are transparent on blockchain
  • Funds are held in auditable smart contract

Risk Mitigation

  • Open source contract code
  • Public transaction history
  • Timeout mechanisms for backend downtime
  • Gradual reputation building with small stakes

🚀 Getting Started

For Players

  1. Deposit STX to get internal balance: (deposit 1000000)
  2. Sign commitment message off-chain
  3. Wait for game matching and commitment processing
  4. Sign reveal message when prompted
  5. Receive winnings automatically

For Developers

  1. Deploy contract to Stacks blockchain
  2. Build frontend for signature generation
  3. Build backend for game matching and execution
  4. Implement proper key management and security

📊 Economics

  • Game Stakes: Any amount (limited by player balance)
  • Platform Fee: 2.5% on winnings
  • Gas Costs: Only paid by backend operator
  • Timeout: 144 blocks (~24 hours)

🔍 Contract Verification

All game logic is on-chain and verifiable:

  • Commitment hashes are stored publicly
  • Reveal verification is transparent
  • Winner determination is deterministic
  • All fund movements are recorded

⚠️ Disclaimer

This is experimental software. While the contract has been designed with security in mind, users should:

  • Start with small stakes
  • Understand the trust assumptions
  • Verify backend reputation
  • Monitor for any unusual behavior

Built with ❤️ for the Stacks ecosystem

About

blaze based games

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors