Inspiration

It was friday night, and we were out of ideas. We were joking about doing a card game called mao, but p2p. We laughed it off, until we realised that it was not as easy as it seemed: how do you shuffle the cards? Do you trust in the shuffler? Of course not! As soon as we realized this, we got sucked into this idea of making a zero trust game. And there is no game that fits this principle as well as mao: which is a game where you cannot talk about the rules, and so, nobody must be allowed to get the rules directly from the program, since it would lose all of its charm.

What it does

Our project is a peer to peer card game, with the added complexity that the rules are a secret, as we’ve mentioned before, so you can’t directly code the rules into the source code without risking someone finding them and ruining the fun of the game.

It allows players to either play or draw a card on their turn and decide whether to say (write) something, having the rest of the players vote if that person has either broken the rules or played out of turn. This voting helps us avoid a malicious agent abusing the ability to penalize other players for no reason and win in a forceful manner. Our project does all of the checking via hashes to avoid people cheating and looking at the rules.

How we built it

To make this work, we used the pears framework to implement peer to peer communication between all the players, without a central server. This presented a challenge especially since the rules of mao shouldn’t be accessible by anyone, and we didn’t have a server who could hide them.

Moreover, to hide the rules we used a list of hashes. We hashed together the state of the game (to keep things simple, we only kept the last 2 cards, and how many cards you have on the hand) and an action that you must do. For instance, if after playing the card 5♠ you need to say hello and bye; then in the list we would have: 5♠ hashed with hello, and 5♠ hashed with bye.

Challenges we ran into

We really wanted to make a zero knowledge proof to shuffle the deck as well, so that it could truly be a zero trust implementation of mao. However, we weren’t able to implement it due to some technical problems with the library we used for encrypting, and of course the lack of time.

Accomplishments that we're proud of

We’re very proud of were we got. We didn’t really expect to make a working program. Moreover the way that we actually managed to implement the rules of the game in a p2p system, is quite fascinating; since making things p2p is a very interesting challenge.

What we learned

One fascinating thing that we learned is the protocol for mental poker; thought of by the same guys who made RSA. And it goes like this: First Alice encrypts the cards (using a commutative algorithm like elliptic curves); then she shuffles the cards. Then she gives the cards to Bob, who does the same. Now Bob gives the cards back to Alice, who unencrypts them and encrypts them again with a unique key for each card. After having done that, Bob does exactly the same (note that if there were more players, they would do the same). The first part of the method makes it so that nobody knows the order of the cards; and the second part makes it so that everybody agrees on the order of the deck.

What's next for p2p mao

We have so many ideas for other things we could implement for this game. For starters, we would love to apply the mental poker protocol to ensure that malicious actors cannot cheat in any way (in particular, to implement the mental poker).

Another idea we would love to implement but we would need a lot more time to develop would be the ability to add a rule every time you win a game. This is one of the mechanics that really makes mao what it is, and it would be great to implement it.

Finally, it would be nice to eventually add more variables to the information about cards played to allow for more creative rules, but that would mean a different checking algorithm unless we want the complexity to really spike.

Built With

Share this project:

Updates

Submission history