A "Mental Poker" based card shuffling and dealing scheme, a demo application of a fully on-chain "High Card Wins" game with MUD framework.
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 game
2 Others Join the Game
2.1 Bob inputs the game id, join the game, generates a key
2.2 Carl inputs the game id, join the game, generates a key
3 Shuffle and Encryption
3.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 Cards
4.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 Others
5.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 themselves
6.1 Alice decrypts Ea(card) and get plaintext card
6.2 Bob decrypts Eb(card) and get plaintext card
6.3 Carl decrypts Ec(card) and get plaintext card
7 Upload Key
All players upload their own keys.
8 Get Winner
The 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.
MUD: framework, contract develop and test, client develop
Solidity: contract development
RC4: a commutative encryption algorithm, for encryption and decryption cards
ethers: data format
truffle: contract test
web3js: 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.