← Back to home

On-Chain Mental Poker

A "Mental Poker" based card shuffling and dealing scheme, a demo application of a fully on-chain "High Card Wins" game with MUD framework.

Screenshots

On-Chain Mental Poker screenshot 1
On-Chain Mental Poker screenshot 2
On-Chain Mental Poker screenshot 3
On-Chain Mental Poker screenshot 4

Problem Statement

This project is a on-chain version of Mental Poker. We developed a simple demo of “High Card Wins”, and it can be change for various types of Poker card games.For the “High Card Wins” demo, there must be 3 players. We call the first player Alice, the second player Bob, the third player Carl.Steps: 1 Create the game with a game id.Karl inputs a game id and creates the game, generates a key then join the game2 Others Join the Game2.1 Bob inputs the game id, join the game, generates a key2.2 Carl inputs the game id, join the game, generates a key3 Shuffle and Encryption3.1 Alice shuffles and encrypts cards, the plaintext card changed to Ea(card)3.2 Bob shuffles and encrypts cards, Ea(card) changed to Eb(Ea(card))3.2 Carl shuffles and encrypts cards, Eb(Ea(card)) changed to Ec(Eb(Ea(card)))4 Deal Cards4.1 Alice picks up one card: EaEbEc(card)4.1 Bob picks up one card: EaEbEc(card)4.1 Carl picks up one card: EaEbEc(card)5 Decryption for Others5.1 Alice decrypts for Bob and Carl , Bob and Carl’s card will be changed to EbEc(card)5.2 Bob decrypts for Alice and Carl , Carl’s card will be changed to Ec(card), Alice’s card will be changed to EaEc(card)5.3 Carl decrypts for Alice and Bob, Alice’s card will be changed to Ea(card), Bob’s card will be changed to Eb(card)6 All players decrypt for themselves6.1 Alice decrypts Ea(card) and get plaintext card6.2 Bob decrypts Eb(card) and get plaintext card6.3 Carl decrypts Ec(card) and get plaintext card7 Upload KeyAll players upload their own keys.8 Get WinnerThe contract determines the winner based on the rules.The current round of the game has ended, and a new round can be started by creating a new game ID.

Solution

MUD: framework, contract develop and test, client developSolidity: contract developmentRC4: a commutative encryption algorithm, for encryption and decryption cardsethers: data formattruffle: contract testweb3js: two util function hexToAscii and asciiToHex. We tried to import web3.js to the client project ,but there was a compatible problem, then we copy the source code of hexToAscii and asciiToHex from web3.js to our project and it worked.

Hackathon

Autonomous Worlds

2024

Contributors