Skip to content

ANAVHEOBA/arcium_poker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸƒ Arcium Poker - Encrypted Texas Hold'em on Solana

A fully-featured poker game with Arcium Multi-Party Computation (MPC) integration

Tests Build Arcium Deployed


🎯 Project Overview

This project implements a complete Texas Hold'em poker game on Solana with real Arcium MPC integration for:

  • πŸ”€ Fair deck shuffling - Multi-party computation ensures no single player controls the shuffle
  • 🎴 Encrypted card dealing - Cards encrypted to specific players using owner-specific keys
  • πŸ‘οΈ Secure showdown - Threshold decryption reveals cards fairly

πŸš€ Live on Devnet

Program ID: Cm5y2aab75vj9dpRcyG1EeZNgeh4GZLRkN3BmmRVNEwZ
Network:    Solana Devnet
RPC:        https://api.devnet.solana.com
Explorer:   https://explorer.solana.com/address/Cm5y2aab75vj9dpRcyG1EeZNgeh4GZLRkN3BmmRVNEwZ?cluster=devnet

✨ Features

βœ… Complete Poker Game

  • Full Texas Hold'em rules (Pre-flop, Flop, Turn, River, Showdown)
  • Betting rounds with raise, call, fold, check, all-in
  • Side pot handling for multiple all-ins
  • Automatic blind posting
  • Tournament support
  • Statistics tracking

πŸ” Arcium MPC Integration

  • 4 MPC Circuits in encrypted-ixs/:

    • shuffle_deck() - Fisher-Yates shuffle in MPC
    • deal_card() - Encrypted card dealing
    • reveal_hole_cards() - Threshold decryption at showdown
    • generate_random() - Secure randomness
  • Dual-Mode Operation:

    • Production: Uses real Arcium MXE via CPI
    • Testing: Falls back to deterministic mock

πŸ§ͺ Comprehensive Testing

  • 48/48 tests passing
  • Full coverage of game logic
  • MXE integration tests
  • Edge case handling

πŸš€ Quick Start

Prerequisites

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install Solana
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"

# Install Anchor
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latest

# Install Node dependencies
yarn install

Build

# Build Solana program
anchor build

# Build MPC circuits
cd encrypted-ixs && cargo build

Test

# Run all tests (48 tests)
npm test

# Run specific test file
anchor test --skip-build tests/test_betting.ts

πŸ“ Project Structure

arcium_poker/
β”œβ”€β”€ programs/
β”‚   └── arcium_poker/          # Main Solana program
β”‚       └── src/
β”‚           β”œβ”€β”€ arcium/        # βœ… MPC integration (Phase 3 complete)
β”‚           β”‚   β”œβ”€β”€ mpc_shuffle.rs    # Dual-mode shuffle
β”‚           β”‚   β”œβ”€β”€ mpc_deal.rs       # Dual-mode dealing
β”‚           β”‚   β”œβ”€β”€ mpc_reveal.rs     # Dual-mode reveal
β”‚           β”‚   └── integration.rs    # MXE helpers
β”‚           β”œβ”€β”€ betting/       # Betting logic
β”‚           β”œβ”€β”€ cards/         # Card handling
β”‚           β”œβ”€β”€ game/          # Game flow
β”‚           β”œβ”€β”€ player/        # Player management
β”‚           └── showdown/      # Winner determination
β”‚
β”œβ”€β”€ encrypted-ixs/             # βœ… Arcium MPC circuits
β”‚   └── src/
β”‚       └── lib.rs             # 4 confidential instructions
β”‚
β”œβ”€β”€ tests/                     # βœ… 48 passing tests
β”‚   β”œβ”€β”€ test_betting.ts
β”‚   β”œβ”€β”€ test_game_flow.ts
β”‚   β”œβ”€β”€ test_mxe_integration.ts  # NEW: MXE examples
β”‚   └── ...
β”‚
└── Documentation/
    β”œβ”€β”€ PHASE_3_COMPLETE.md           # Integration guide
    β”œβ”€β”€ IMPLEMENTATION_STATUS.md      # Feature status
    └── FULL_MPC_INTEGRATION_ROADMAP.md

πŸ” Arcium MPC Architecture

How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  1. SHUFFLE                                         β”‚
β”‚     Players β†’ Entropy β†’ MPC Shuffle β†’ Encrypted Deckβ”‚
β”‚                                                     β”‚
β”‚  2. DEAL                                            β”‚
β”‚     Encrypted Deck β†’ MPC Deal β†’ Player-Specific Keyβ”‚
β”‚                                                     β”‚
β”‚  3. REVEAL                                          β”‚
β”‚     Encrypted Cards β†’ Threshold Decrypt β†’ Revealed β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Dual-Mode Operation

// Production: With MXE accounts
let result = mpc_shuffle_deck_with_mxe(MxeShuffleParams {
    mxe_program: Some(mxe_program),  // βœ… Real MPC
    comp_def: Some(comp_def),
    mempool: Some(mempool),
    cluster: Some(cluster),
    // ...
})?;

// Testing: Without MXE accounts
let result = mpc_shuffle_deck_with_mxe(MxeShuffleParams {
    mxe_program: None,  // βœ… Mock mode
    comp_def: None,
    mempool: None,
    cluster: None,
    // ...
})?;

πŸ§ͺ Testing

Run All Tests

npm test
# βœ… 48 passing (2m)

Test Categories

  • Betting Tests (12 tests) - Raises, calls, folds, all-ins
  • Game Flow Tests (11 tests) - Stage transitions, game lifecycle
  • Game Initialization (7 tests) - Valid/invalid configurations
  • Player Actions (7 tests) - Join, leave, edge cases
  • Side Pots (3 tests) - Multiple all-ins, complex scenarios
  • Edge Cases (7 tests) - Race conditions, zero values
  • MXE Integration (1 test) - Mock mode demonstration

πŸš€ Deployment

βœ… Deployed to Devnet!

Program ID: Cm5y2aab75vj9dpRcyG1EeZNgeh4GZLRkN3BmmRVNEwZ Network: Devnet RPC Endpoint: https://api.devnet.solana.com Deployed Slot: 416979428 MXE Cluster: 1078779259

Frontend Integration

import { Program, AnchorProvider } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import idl from "./idl/arcium_poker.json";
import { ArciumPoker } from "./types/arcium_poker";

// Program configuration
const PROGRAM_ID = new PublicKey("Cm5y2aab75vj9dpRcyG1EeZNgeh4GZLRkN3BmmRVNEwZ");
const RPC_ENDPOINT = "https://api.devnet.solana.com";

// Initialize program
const connection = new Connection(RPC_ENDPOINT, "confirmed");
const provider = new AnchorProvider(connection, wallet, {});
const program = new Program<ArciumPoker>(idl, PROGRAM_ID, provider);

// Call contract methods
await program.methods
  .initializeGame(gameId, smallBlind, bigBlind, minBuyIn, maxBuyIn, maxPlayers)
  .accounts({ authority: wallet.publicKey })
  .rpc();

Environment Variables

Create .env.local in your frontend:

NEXT_PUBLIC_PROGRAM_ID=Cm5y2aab75vj9dpRcyG1EeZNgeh4GZLRkN3BmmRVNEwZ
NEXT_PUBLIC_RPC_ENDPOINT=https://api.devnet.solana.com
NEXT_PUBLIC_NETWORK=devnet

Real MPC Integration

Deploy MXE Program βœ… DONE!

# MXE deployed to cluster 1078779259
arcium deploy --cluster-offset 1078779259 --keypair-path ~/.config/solana/id.json -u d

Use Real MPC in Frontend

// See HOW_TO_USE_REAL_MPC.md for complete integration guide
import { getMxeAccount, getCompDefAccount, getClusterAccount } from "./utils/arcium";

// Get MXE accounts for real MPC
const mxeAccount = getMxeAccount(PROGRAM_ID);
const compDefAccount = getCompDefAccount(PROGRAM_ID, 1);
const clusterAccount = getClusterAccount(PROGRAM_ID, 1078779259);

// Start game with REAL encrypted MPC!
await program.methods
  .startGame(entropy)
  .accounts({
    game,
    authority: wallet.publicKey,
    mxeProgram: PROGRAM_ID,
    compDef: compDefAccount,
    cluster: clusterAccount,
  })
  .rpc();

Step 1: Deploy MXE Program

cd encrypted-ixs
cargo build-sbf
solana program deploy target/deploy/encrypted_ixs.so

Step 2: Initialize Arcium

arcium init-mxe --program-id <YOUR_MXE_ID>
arcium init-cluster --name poker-cluster

Step 3: Update Client with MXE

const MXE_PROGRAM_ID = new PublicKey("YOUR_MXE_ID");

// Derive MXE accounts
const [compDef] = PublicKey.findProgramAddressSync(
  [Buffer.from("comp_def"), Buffer.from("shuffle_deck")],
  MXE_PROGRAM_ID
);

// Use in transactions
await program.methods
  .startGame(playerEntropy)
  .accounts({
    game,
    authority,
    // MXE accounts automatically enable real MPC
    mxeProgram: MXE_PROGRAM_ID,
    compDef,
    mempool,
    cluster,
  })
  .rpc();

πŸ“Š Project Status

Component Status Completion
Poker Game Logic βœ… DONE 100%
MPC Circuits βœ… DONE 100%
MXE Integration βœ… DONE 100%
Tests βœ… PASSING 48/48
Documentation βœ… COMPLETE 100%
Deployment βœ… DEPLOYED 100%

Overall: 100% Complete (Deployed to Devnet!)


πŸ† Hackathon Highlights

Innovation

  1. Dual-Mode Architecture - Seamless MXE/mock switching
  2. Cross-Program Invocation - Direct MXE calls from Solana
  3. Threshold Decryption - Multi-party showdown reveals
  4. Owner-Specific Encryption - Privacy-preserving card dealing

Technical Excellence

  • βœ… Clean, modular code
  • βœ… Comprehensive test coverage
  • βœ… Production-ready error handling
  • βœ… Detailed documentation

πŸ“š Documentation


How to Play

1. Initialize Game

await program.methods
  .initializeGame(
    gameId,
    smallBlind,
    bigBlind,
    minBuyIn,
    maxBuyIn,
    maxPlayers
  )
  .accounts({ authority: wallet.publicKey })
  .rpc();

2. Join Game

await program.methods
  .joinGame(buyIn)
  .accounts({ game, player })
  .rpc();

3. Start Game (with Real MPC!)

const playerEntropy = generateEntropy(); // Client-side

// Use mock mode (default)
await program.methods
  .startGame(playerEntropy)
  .accounts({ game, authority })
  .rpc();

// Or use REAL MPC (see HOW_TO_USE_REAL_MPC.md)
const PROGRAM_ID = new PublicKey("Cm5y2aab75vj9dpRcyG1EeZNgeh4GZLRkN3BmmRVNEwZ");
const mxeAccounts = {
  mxeProgram: PROGRAM_ID,
  compDef: getCompDefAccount(PROGRAM_ID, 1),
  cluster: getClusterAccount(PROGRAM_ID, 1078779259),
};

await program.methods
  .startGame(playerEntropy)
  .accounts({ game, authority, ...mxeAccounts })
  .rpc(); // πŸ” Real encrypted MPC shuffle!

4. Play

// Bet
await program.methods.bet(amount).rpc();

// Call
await program.methods.call().rpc();

// Fold
await program.methods.fold().rpc();

// All-in
await program.methods.allIn().rpc();

🀝 Contributing

This is a hackathon project, but contributions are welcome!

Areas for Improvement

  • Deploy to devnet - DONE!
  • Deploy MXE circuits to devnet - DONE! (Cluster 1078779259)
  • Add callback server for MPC results (optional - current architecture works)
  • Implement frontend UI
  • Add more game variants (Omaha, 7-Card Stud)
  • Performance optimization
  • Add tournament brackets
  • Implement rake/fees system

πŸ“„ License

MIT License - See LICENSE file for details


πŸ™ Acknowledgments

  • Arcium - For the amazing MPC infrastructure
  • Solana - For the fast, scalable blockchain
  • Anchor - For the excellent Solana framework

πŸ“ž Contact


🎯 Hackathon Submission

Track: Arcium's Side Track Category: Hidden-Information Games Status: βœ… DEPLOYED & READY

What We Built

A complete Texas Hold'em poker game with real Arcium MPC integration for fair, encrypted gameplay.

Key Features

  • βœ… 48/48 tests passing
  • βœ… 4 working MPC circuits deployed
  • βœ… Full integration layer with CPI calls
  • βœ… Dual-mode operation (mock + real MPC)
  • βœ… Deployed to Devnet (both Solana program & MXE)
  • βœ… Production-ready architecture

Live Deployment

  • Program ID: Cm5y2aab75vj9dpRcyG1EeZNgeh4GZLRkN3BmmRVNEwZ
  • MXE Cluster: 1078779259
  • Network: Solana Devnet
  • Explorer: View on Solana Explorer

Demo

See tests/test_mxe_integration.ts for live examples of MXE integration, and HOW_TO_USE_REAL_MPC.md for complete frontend integration guide.


Built with ❀️ for the Arcium Hackathon

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors