A decentralized Rock Paper Scissors game built on Stacks using commit-reveal scheme for provably fair gameplay.
- Commit Phase: Players secretly commit to their moves using cryptographic hashes
- Reveal Phase: Players reveal their actual moves, proving they match their commitments
- Resolution: Smart contract determines winner and distributes rewards
- ✅ 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
- 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
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}
- 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
deposit(amount)- Deposit STX to get internal balancewithdraw(amount)- Withdraw internal balance to STXget-balance(user)- Check user's internal balance
commit-game(...)- Process both players' commitments and stakesreveal-game(...)- Process reveals and determine winnertimeout-claim(game-id)- Reclaim stakes if game times out (24 hours)
operator-withdraw()- Withdraw collected fees to operator address
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
- Backend will execute reveals fairly (reputation-based)
- Backend will stay online and operational
- Backend won't discriminate based on game outcomes
- Players cannot change moves after commitment
- Backend cannot modify game outcomes
- All transactions are transparent on blockchain
- Funds are held in auditable smart contract
- Open source contract code
- Public transaction history
- Timeout mechanisms for backend downtime
- Gradual reputation building with small stakes
- Deposit STX to get internal balance:
(deposit 1000000) - Sign commitment message off-chain
- Wait for game matching and commitment processing
- Sign reveal message when prompted
- Receive winnings automatically
- Deploy contract to Stacks blockchain
- Build frontend for signature generation
- Build backend for game matching and execution
- Implement proper key management and security
- 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)
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
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