Skip to content

TobieTom/echobet-pro

Repository files navigation

Solana Devnet Anchor React MIT License

🎲 EchoBet Pro

Privacy-Preserving Prediction Markets on Solana

Bet privately. Reveal fairly. Win transparently.

A decentralized prediction market that uses commit-reveal cryptography to prevent front-running and ensure fair betting β€” built for the Indie.fun Hackathon.


🌐 Live Demo β€’ πŸ“œ On-Chain Program β€’ πŸš€ Quick Start


✨ Core Features

Feature Description
πŸ”’ Private Betting Bets are hidden using SHA-256 commitment hashes until reveal phase
⚑ Front-Running Protection Commit-reveal scheme prevents miners/validators from exploiting bet information
πŸ’° Trustless Payouts Winnings are distributed proportionally from PDA-controlled vaults
🎯 Simple UX Clean interface for creating markets, placing bets, and claiming rewards
πŸ“Š Real-Time Dashboard Track all your bets, reveals, and winnings in one place
πŸ” Non-Custodial Your funds stay in smart contract vaults β€” no central authority

πŸ”„ How It Works

EchoBet Pro uses a three-phase commit-reveal mechanism to ensure fair and private betting:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           ECHOBET PRO FLOW                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                             β”‚
β”‚   πŸ“ PHASE 1: COMMIT          πŸ”“ PHASE 2: REVEAL         πŸ† PHASE 3: CLAIM β”‚
β”‚   ──────────────────          ──────────────────         ───────────────── β”‚
β”‚                                                                             β”‚
β”‚   User places bet with        After deadline,            Winners claim      β”‚
β”‚   hidden commitment:          user reveals:              proportional       β”‚
β”‚                                                          payouts:           β”‚
β”‚   hash(amount + outcome       β€’ Original outcome                            β”‚
β”‚        + random_salt)         β€’ Secret salt              payout = stake Γ—   β”‚
β”‚                               β€’ Verified on-chain          (total_pool /    β”‚
β”‚   ↓                           ↓                              winning_pool)  β”‚
β”‚   Stored on-chain             Bet counted in pool        ↓                  β”‚
β”‚   (hidden from others)        (YES or NO)                SOL transferred    β”‚
β”‚                                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Step-by-Step:

  1. πŸ” Commit Phase β€” Place your bet by submitting a hash of your choice + amount + secret salt. Nobody can see your bet.

  2. πŸ”“ Reveal Phase β€” After the betting deadline, reveal your original bet. The smart contract verifies your hash matches.

  3. πŸ† Claim Phase β€” Once the market is resolved, winners claim their proportional share from the prize pool.


πŸ—οΈ Architecture

System Overview

flowchart TB
    subgraph Frontend["πŸ–₯️ Frontend (React + Vite)"]
        UI[User Interface]
        WA[Wallet Adapter]
        IDL[Anchor IDL]
    end

    subgraph Blockchain["⛓️ Solana Devnet"]
        Program[EchoBet Program]
        
        subgraph Accounts["πŸ“¦ Program Accounts"]
            Market[Market PDA]
            Commitment[Commitment PDA]
            Vault[Vault PDA]
        end
    end

    subgraph User["πŸ‘€ User"]
        Phantom[Phantom Wallet]
        LocalStorage[Local Storage\n- Salt backup]
    end

    User --> Frontend
    Phantom <--> WA
    WA <--> Program
    Frontend --> IDL --> Program
    Program --> Accounts
    LocalStorage -.->|Salt for reveal| Frontend
Loading

On-Chain Account Structure

erDiagram
    MARKET ||--o{ COMMITMENT : "has many"
    MARKET ||--|| VAULT : "owns"
    
    MARKET {
        pubkey creator
        pubkey oracle
        u64 market_id
        string question
        i64 deadline
        i64 reveal_deadline
        enum status
        u8 outcome
        u64 total_pool
        u64 yes_pool
        u64 no_pool
        u32 yes_count
        u32 no_count
    }
    
    COMMITMENT {
        pubkey market
        pubkey user
        bytes32 commitment_hash
        u64 amount
        u8 revealed_outcome
        bytes32 revealed_salt
        bool is_revealed
        bool is_claimed
    }
    
    VAULT {
        lamports balance
        pubkey market
    }
Loading

Instruction Flow

sequenceDiagram
    participant U as User
    participant F as Frontend
    participant P as Program
    participant V as Vault PDA

    Note over U,V: πŸ“ Phase 1: Create & Commit
    U->>F: Create Market
    F->>P: create_market(question, deadline)
    P->>P: Initialize Market + Vault PDAs
    
    U->>F: Place Bet (amount, YES/NO)
    F->>F: Generate salt, compute hash
    F->>P: commit_bet(hash, amount)
    P->>V: Transfer SOL to vault
    F->>F: Save salt to localStorage

    Note over U,V: πŸ”“ Phase 2: Reveal
    U->>F: Reveal Bet
    F->>F: Load salt from localStorage
    F->>P: reveal_bet(outcome, salt)
    P->>P: Verify hash matches
    P->>P: Update pool counts

    Note over U,V: βš–οΈ Phase 3: Resolve & Claim
    U->>F: Resolve Market (Oracle only)
    F->>P: resolve_market(winning_outcome)
    
    U->>F: Claim Winnings
    F->>P: claim_winnings()
    P->>P: Calculate proportional payout
    V->>U: Transfer SOL to winner
Loading

πŸ› οΈ Tech Stack

Backend (Solana Program)

Technology Purpose
Anchor 0.32.1 Solana development framework
Rust Smart contract language
SHA-256 Commitment hash generation
PDAs Secure account derivation

Frontend

Technology Purpose
React 18 UI framework
TypeScript Type safety
Vite 7 Build tool
TailwindCSS Styling
@solana/wallet-adapter Wallet integration
@coral-xyz/anchor Program interaction

Infrastructure

Service Purpose
Solana Devnet Blockchain network
Vercel Frontend hosting
GitHub Version control

πŸ” Security Highlights

Security Feature Implementation
Commitment Scheme SHA-256 hash of (amount + outcome + 32-byte salt)
Front-Running Prevention Bets hidden until reveal phase ends
PDA Vaults Funds controlled by program, not individuals
Time-Locked Phases Strict deadline enforcement on-chain
Oracle Authorization Only designated resolver can set outcome
Duplicate Prevention One commitment per user per market
Overflow Protection Safe math on all pool calculations

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • Rust & Cargo
  • Solana CLI
  • Anchor CLI 0.32.1

Clone & Install

# Clone the repository
git clone https://github.com/TobieTom/echobet-pro.git
cd echobet-pro

# Install dependencies
npm install
cd app && npm install && cd ..

Run Tests

# Start local validator and run tests
anchor test

Local Development

# Terminal 1: Start local validator
solana-test-validator

# Terminal 2: Deploy program
anchor build
anchor deploy

# Terminal 3: Start frontend
cd app
npm run dev

Open http://localhost:5173 in your browser.


🌐 Devnet Deployment

Resource Value
Program ID HTDC5bDN6u7q1FCYnEuevztZM1ZqKcD9ujPTTLwNfTCc
Network Solana Devnet
Live Demo echobet-pro.vercel.app
Explorer View on Solana Explorer

Testing on Devnet

  1. Install Phantom Wallet
  2. Switch to Devnet in Phantom settings
  3. Get devnet SOL from faucet.solana.com
  4. Visit echobet-pro.vercel.app
  5. Connect wallet and start betting!

πŸ“ Project Structure

echobet-pro/
β”œβ”€β”€ programs/
β”‚   └── echobet_pro/
β”‚       └── src/
β”‚           β”œβ”€β”€ lib.rs          # Main program logic
β”‚           β”œβ”€β”€ state.rs        # Account structures
β”‚           └── errors.rs       # Custom errors
β”œβ”€β”€ app/
β”‚   └── src/
β”‚       β”œβ”€β”€ pages/
β”‚       β”‚   β”œβ”€β”€ Markets.tsx     # Market listing
β”‚       β”‚   β”œβ”€β”€ CreateMarket.tsx
β”‚       β”‚   β”œβ”€β”€ MarketDetail.tsx
β”‚       β”‚   └── Dashboard.tsx
β”‚       β”œβ”€β”€ components/
β”‚       β”œβ”€β”€ hooks/
β”‚       β”‚   β”œβ”€β”€ useProgram.ts   # Anchor integration
β”‚       β”‚   └── useBetStorage.ts
β”‚       β”œβ”€β”€ utils/
β”‚       β”‚   β”œβ”€β”€ commitment.ts   # Hash generation
β”‚       β”‚   └── pda.ts          # PDA derivation
β”‚       └── idl/
β”‚           └── echobet_pro.json
β”œβ”€β”€ tests/
β”‚   └── echobet_pro.ts          # 23 comprehensive tests
β”œβ”€β”€ Anchor.toml
└── README.md

πŸ§ͺ Test Coverage

βœ“ Creates a market (409ms)
βœ“ Commits a bet (YES) (452ms)
βœ“ Commits a bet (NO) (443ms)
βœ“ Prevents duplicate commits (201ms)
βœ“ Reveals a bet correctly (389ms)
βœ“ Rejects invalid reveal (wrong salt) (198ms)
βœ“ Rejects invalid reveal (wrong outcome) (195ms)
βœ“ Resolves market as oracle (367ms)
βœ“ Rejects unauthorized resolver (189ms)
βœ“ Claims winnings for winner (412ms)
βœ“ Rejects claim for loser (187ms)
βœ“ Rejects double claim (184ms)
... and 11 more tests

23 passing (8.2s)

🎯 Future Roadmap

  • Mainnet Deployment β€” Launch on Solana mainnet
  • Multiple Outcomes β€” Support markets with 3+ options
  • Decentralized Oracles β€” Integrate Pyth/Chainlink for resolution
  • Mobile App β€” React Native companion app
  • Liquidity Pools β€” AMM-style market making
  • Governance Token β€” DAO for protocol decisions

πŸ‘₯ Team

Built by TobiasBond for the Indie.fun Hackathon


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


🎲 EchoBet Pro β€” Where Privacy Meets Prediction

Try the Demo β€’ View Source β€’ Explore On-Chain

About

Privacy-preserving prediction market on Solana using commit-reveal scheme

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors