For a couple of years I’ve been wondering if it’s practical to build an open peer to peer poker system. I’ve talked to people working on this problem and seen articles describing the potential. Because I haven’t read a good explanation of how this would work, I thought I’d write about how it might be done.

The Ethereum network can do all sorts of interesting things with peer to peer payment so lets start there. A poker game could be a smart contract that you put on the block chain. You would construct this contract with max_players, minimum_bet and so on. Clients could discover this game and join by paying an ante.

That’s the easy part. How would you shuffle a deck? Random numbers are tricky on block chains. Here is my pseudo code.

Each player creates an array of shuffled indexes. Here is some python to show what I mean.

>>> shuffled_index_array=range(52);

>>> random.shuffle(shuffled_index_array);

>>> shuffled_index_array

[51, 18, 14, 2, 40, 36, 23, 11, 27, 28, 46, 6, 19, 10, 30, 26, 21, 13, 17, 0, 29, 3, 37, 4, 22, 35, 38, 9, 47, 7, 43, 34, 44, 1, 48, 50, 25, 41, 5, 20, 8, 15, 42, 32, 39, 33, 24, 16, 31, 12, 49, 45]

2. They then use public key encryption to encrypt each of these indexes

3. To enter a game, players pass this array of encrypted indexes to a function along with an ante.

Now we have a deck and players. When it’s time to put a card face up for all to see, each player would submit their private key for that card. The contract and other players could decrypt the shuffled index and determine the card. When it’s time for a player to look at their card privately, they just keep their key private. Here is how you would determine a card given the submitted_keys.



#shuffled_indexes is an array of encrypted shuffled_index_array #provided by players when they join. def getCard(cardnum,shuffled_indexes,submitted_keys):

for shuffled_index in shuffled_indexes:

cardnum = decrypt(shuffled_index[cardnum],submitted_keys)

return cardnum

This deck mechanism allows the group to grant a player access to a card, without making it public.

Players are forced by the rules of the contract to follow the rules of the game. If a player doesn’t provide their private key when the rules require, they timeout and forfeit their bet. The other players reshuffle the remaining cards and continue to play. (This means that the hidden cards from the leaving player could be redrawn. There is no way to know what they were. They player took their keys with them.)

Once you have a good mechanism for a peer to peer deck, the Ethereum contract can manage the game play. The only problem is that it might be too slow and expensive. Waiting ~20 seconds for someone to bet might be too boring. Of course collusion is also (always?) a problem…

Even with these issues I think we are pretty close to solving this challenge. It would a great demonstration and milestone for peer to peer systems.