Bluff & Barrel
A fully on-chain, FHE-encrypted 4-player card bluffing game with Russian Roulette elimination and USDC stakes. Built on Fhenix CoFHE. Deployed on Arbitrum Sepolia.
Videos




Tech Stack
Description
Bluff and Barrel : On-Chain Deception Game
A fully on-chain, FHE-encrypted 4-player card bluffing game with Russian Roulette elimination and USDC stakes. Built on Fhenix CoFHE. Deployed on Arbitrum Sepolia.
What is Bluff and Barrel?
A provably fair on-chain card bluffing game where:
Cards are encrypted : nobody can see your hand, not even the contract
Bluffs are verified cryptographically : no trusted server, no oracle
The revolver is real : bullet position is FHE-encrypted, unknown until it fires
Stakes are real : USDC wagers with automatic winner payout
Everything is provably fair : powered by Fhenix Fully Homomorphic Encryption
Game Modes
Mode | Status | Description |
|---|---|---|
Card and Barrel (Basic) | Live | 5 cards, bluff or call, loser spins |
Card and Barrel (Devil) | Live | Devil card punishes ALL other players |
Card and Barrel (Chaos) | Live | Shoot your opponents, Master/Chaos specials |
Dice and Barrel | Coming soon | Bid on hidden dice |
Slot and Barrel | Coming soon | Spin slots, lie about results |
How to Play
1. Choose your character (8 animal masks) and set USDC stake (or play free)
2. Create or join a table (4 players required)
3. Each round: a target card is announced (Ace, King, or Queen)
4. On your turn: play 1-3 cards face-down, claiming they're the target
5. Other players: believe you or call "LIAR!"
6. If challenged: cards are revealed via FHE decryption — everyone sees the actual cards
7. Russian Roulette: 6 chambers, 1 bullet, position unknown
8. Last player alive wins the pot (stake x 4, minus 5% platform fee)
Architecture
Syetem

Contract Architecture

FHE Data Flow

Basic Game flow

Deployed Contracts (Arbitrum Sepolia)
Shared In all modes
Contract | Address |
|---|---|
Revolver |
|
Basic Mode
Contract | Address |
|---|---|
BarGame |
|
BarDeck |
|
Devil Mode
Contract | Address |
|---|---|
DevilGame |
|
DevilDeck |
|
Chaos Mode
Contract | Address |
|---|---|
ChaosGame |
|
ChaosDeck |
|
FHE Integration
All encrypted values are computed on-chain through Fhenix CoFHE operations. Your hand remains encrypted until you explicitly permit decryption challenge reveals and spin outcomes use allowPublic() to broadcast results without exposing intermediate secrets. The bullet position stays fully encrypted until the revolver fires, ensuring no player (not even the contract) knows the outcome before the moment of truth.
What's Hidden | FHE Type | Who Can Decrypt |
|---|---|---|
Your cards |
| Only you (via permit) |
Challenge result |
| Anyone (public, after challenge) |
Revealed cards |
| Anyone (public, after challenge) |
Bullet position |
| Nobody (until spin resolves) |
Spin result |
| Anyone (public, after spin) |
FHE Operations Per Game
Operation | Per Round | x5 Rounds | Total |
|---|---|---|---|
Deal cards (20 draws) | ~200 | x5 | 1,000 |
Revolver init (once) | - | 20 | |
Challenge verify | ~8 | x5 | 40 |
Card reveal (allowPublic) | ~2 | x5 | 10 |
Spin (eq check) | ~2 | x5 | 10 |
On-chain total | ~1,080 |
Hand decrypt (5 cards x 4 players) | 20 | x5 | 100 |
Challenge + card reveal decrypt | 3 | x5 | 15 |
Spin decrypt | 1 | x5 | 5 |
Off-chain total (SDK) | ~120 |
Grand total per game ~1,200 FHE Operations Per Game
USDC Stake System
Table creator sets stake amount (0 = free game)
Each player deposits USDC on join (ERC20 approve + transferFrom)
Winner receives 95% of pot (stake x 4 players)
5% platform fee sent to treasury
Automatic payout on GameOver no manual claim needed
Tech Stack
Contracts: Solidity 0.8.28, Hardhat, @fhenixprotocol/cofhe-contracts, viaIR
Frontend: Vite, React 18, TypeScript, wagmi v2, viem, @cofhe/sdk, Zustand, Tailwind CSS, Framer Motion
Network: Arbitrum Sepolia (Chain ID: 421614)
FHE: Fhenix CoFHE (Threshold Network decryption)
Game Modes Detail
Basic Mode
20 cards: 6 Ace, 6 King, 6 Queen, 2 Joker (wild)
5 cards per player, play 1-3 per turn
Loser of challenge spins own revolver
Devil Mode
Same as Basic + 1 Devil Card (replaces one table-type card)
Devil can only be played alone
If challenged and Devil revealed: ALL other players face Roulette
Chaos Mode
12 cards: 5 King, 5 Queen, 1 Master, 1 Chaos
3 cards per player, play exactly 1 per turn
Winner of challenge shoots an opponent of choice
Master card: accused gets to shoot someone
Chaos card: ALL players shoot simultaneously
Features
8 selectable character masks (on-chain storage)
Card reveal on challenge (actual card images shown)
Per-player revolver with chamber indicators
60-second turn timer with on-chain forceTimeout()
Dramatic overlays (LIAR!, CLICK, BANG, Winner with wallet address)
Mode selector (Basic/Devil/Chaos) in lobby
USDC stake with automatic payout (5% platform fee)
Rules info button in lobby and game
WebSocket relay for real-time sync (3s polling fallback)
Multi-wallet support (MetaMask, Phantom, Rabby, Coinbase, etc.)
Security audited checked transfer returns, access controls, participant validation
Documentation
CONTRACTS.md FHE and contract implementation details
TESTING_GUIDE.md Step-by-step testing guide
Progress During Hackathon
How it started
Started as a minimal 2 player proof of concept to validate FHE encraypted card dealing and challenge verification was technically feasible on Fhenix CoFHE. The first working version had:
A single solidity contract with hardcoded 2 players
Phase 1 : Core Mechanics
LiarsBarDeck: encrypted 20-card shuffle using FHE.randomEuint8 + draw-without-replacement via FHE.selec chains
LiarsBarRevolver: per-player encrypted bullet position (1-6), chamber pointer, beginSpin → publishSpinResult
LiarsBarGame`: minimal state machine WaitingForPlayers → Dealing → PlayerTurn → Challenging → Spinning → GameOver
Challenge verification: verifyClaim returns ctHash of ebool, frontend decrypts and pushes result back
Initial Version Demo Video: V1 Bluff and barrel demo
Phase 2 : 4 players and Updated UI
🦊🐰🐱🦉 Animal mask avatars
Per-player revolver chamber indicators
Dramatic "LIAR!" challenge overlay with card reveal
Full-screen CLICK/BANG trigger pull animation
30-second turn timer with visual countdown
Game event log
Version 2 Demo Video: V2 Bluff and Barrel demo
Phase 3 : Two more card game types (Devil and Chaos) with custom UI assets
Character selection (8 animal masks) stored on-chain in Player struct
Lobby: create game, join by ID, stake USDC (approve flow)
Game room: card hand display, play cards, call liar, pull trigger
Challenge overlay with card reveal showing actual card images
Spin animation with revolver visual
USDC Stakes
Integrated Circle USDC ERC-20 on Arb Sepolia
Creator sets stake amount, players approve + deposit on join
Auto-payout to winner: 95% of pot, 5% platform fee
getStakeAmount view so joiners see the wager before committing
Devil Mode
New LiarsBarDevilDeck: 5 table-type + 1 Devil(4) + 6 + 6 + 2 Joker = 20 cards
New LiarsBarDevilGame: added MultiSpinning state
Devil card in played hand → ALL other alive players spin simultaneously
triggerMySpin per player, multiSpinCtHashes mapping, auto-resolve when last spinner submits
Frontend: mode selector in lobby, MultiSpinning UI with per-player trigger buttons
Chaos Mode
New LiarsBarChaosDeck: 12 cards (5 King + 5 Queen + 1 Master + 1 Chaos), 3 cards per hand
New LiarsBarChaosGame: added Targeting / MultiTargeting / Shooting states
Three outcomes on challenge: regular card → challenger shoots, Master card → accused shoots, Chaos card → everyone shoots simultaneously
chooseTarget / chooseTargetMulti, spinForTarget on the RevolverFrontend: targeting UI with alive player selection, only relevant player sees buttons
Polish + Infra
WebSocket relay server for real-time state sync (Node.js, port 8080)
Sound effects (card play, liar call, spin, bang/click, game over) Mute toggle in nav
invite links: ?join=ID&mode=MODE pre-fills lobby
Roadmap page at /roadmap
Share result at game over: download PNG + share on X
60s turn timer with forceTimeout() on-chain
Security Audit + Bug Fixes
Critical contract fixes:
Unchecked USDC transfers → require(usdc.transfer(...))
Access control on publishChallengeResult → participant-only check
onlyGame modifier on revolver publish functions
Dead players dealt to address(0) not first player
Frontend fixes:
Stale CoFHE permits removed before creating new ones
Wallet address change detection resets FHE client
Auto-retry on 503/gas errors (4 attempts with backoff)
Challenge overlay clears stale card data on state transitions
Gas + Stability
Identified eth_estimateGas returns garbage for FHE txs on Arb Sepolia
Adopted per-function explicit gas limits (like CofhePoker pattern)
Split _startRound (FHE deal) into separate dealNextRound tx to prevent spin+deal in one tx exceeding gas
2x baseFee floor for maxFeePerGas to prevent "less than baseFee" errors
Final State (Arbitrum Sepolia)
Functional Contracts (7 total)
Revolver: 0x1E83b93AF872BE24e6fD642640943fFebb9374d6
Basic Game: 0x0E2bFBC7124A0313E27172A1d7eb28136e45580F
Basic Deck: 0xA3FCd7571BC9A9f2ABB14BFDc4198D181dFC830e
Devil Game: 0x8b2c2C97Db8AbA07fb4790BE2A9D40635E3a6642
Devil Deck: 0x81631728A254B8d0aFf531615c35Ab728D54f61b
Chaos Game: 0x27C2E979EC550d1a2F6c637aE508640405227F9F
Chaos Deck: 0x406ba0147Fa54809048cbE6F6813c02504D77951
What works:
Basic mode: fully playable end-to-end (tested with 4 players)
All 3 modes deployable and joinable
USDC stakes functional
Character selection, card reveal, spin animation all working
WebSocket real-time sync working
Known limitations (Arb Sepolia):
Devil/Chaos multi-spin resolution consumes too much gas per tx (FHE deal + spin in same block)
MetaMask shows inflated fee estimates for FHE-heavy txs
dealNextRound workaround partially resolves the gas issue but not fully stable
Key Technical Numbers
~1,200 FHE operations per full game (5 rounds, 4 players)
20-card encrypted shuffle: ~200 FHE ops (draw-without-replacement)
Challenge verification: ~40 FHE ops (per played card: eq + or + and)
Spin: ~3 FHE ops (eq + add + rem)
Gas per `startGame` (deal): ~7.9M gas on Arb Sepolia