Created on 22nd June 2025
โข
LeoMafia is a revolutionary implementation of the classic Mafia party game built on the Aleo blockchain using the Leo programming language. This project combines the strategic gameplay of traditional Mafia with cutting-edge zero-knowledge proofs and decentralized smart contracts to create a trustless, verifiable, and privacy-preserving gaming experience.
game_id
is assigned and broadcasted on-chain.Players with special roles perform secret actions via ZK proofs:
All night actions are submitted as zero-knowledge transactions, where both inputs and results are hidden but cryptographically verifiable.
Player Record: Each player has a smart contract record containing owner, role, game_id, stake, and is_alive.
Role Privacy: Roles are hashed using BHP256 and stored in a
role_commitments
mapping.Phase Timing:
round_deadline
mapping handles deadlines for each phase, ensuring fair progression.Game Logic: All player actions (investigation, vote, protect, kill) are implemented as verifiable private functions using ZKPs.
Built using Next.js and TypeScript, interfaced with Leo CLI and the Aleo blockchain.
Connects directly to the Leo Wallet for transaction signing and role verification.
Implements real-time state polling to reflect game events and updates via on-chain reads.
Displays cryptographic operations (like proofs, commitments, hashes) in an intuitive format for players.
Detective Results: Players submit a proof to validate anotherโs role without revealing their own.
Vote Validation: Votes are cast as commitments; tallying is done through ZK aggregation.
Protection and Kill Logic: Intersecting ZK operations determine if a Mafia kill was blocked by the Angel.
Stake to Join: Each player deposits a stake, which forms the reward pool.
Vote Staking: Additional tokens can be staked to back a vote (e.g., higher conviction = higher weight).
Reward Distribution: On game completion, the prize pool is auto-distributed to the surviving winning team.
Gaining a solid understanding of Leo was challenging, especially during deployment and testing where we encountered several issues.
Wallets frequently threw errors related to locating contracts and differentiating between the testnet and testnetBeta environments.
Assigning the Detective role to a user was tricky, as it risked exposing sensitive information about players during detective phase. For now, weโve implemented a centralized oracle to handle this logic, but we plan to transition to a decentralized oracle soon.
Tracks Applied (2)
Aleo
Technologies used
Cheering for a project means supporting a project you like with as little as 0.0025 ETH. Right now, you can Cheer using ETH on Arbitrum, Optimism and Base.