The /flip command on Keybase chat implements a commitment scheme protocol allowing the members of a channel to participate in secure coin flips. Leveraging the fact that all messages in chat are signed by the sender, building such a protocol on top of chat is a natural fit. In addition to flipping coins, the shared randomness can also be used to present different forms of the flip; such as shuffling items, picking a random number, and even dealing hands of playing cards.
The types of flips supported right now include the following:
- /flip - Flip a coin.
- /flip 6 - Roll a _k_-sided die.
- /flip -10..10 - Pick a random number in a range
- /flip apple, orange, pear - Shuffle a list of items
- /flip cards - deal a deck of cards
- /flip cards 5 mike, chris, max, patrick - Deal out a hand of 5 cards to a list of people
- /flip @here - shuffle the members of a channel
- /flip cards 5 @here - deal out hands of 5 cards to the channel
The following is a description of the protocol the chat client uses to implement the commitment scheme.
- The initiator starts the flip by issuing a /flip command.
- All members of the channel commit to a secret by sending a chat message into a special hidden "developer" channel including the same members as the host channel.
- The initiator collects all commitments in a set time interval, and sends a message with all of the participants that responded in time. These are the participants in the flip result.
- Upon reception of this message, clients send chat messages revealing their secrets, and confirm that the secrets of others match their commitments.
- The final result is displayed in the chat channel once all secrets are revealed.
As long as a participant trusts at least one person in the flip (including themselves if they participated), then the result of the flip is fair.
A caveat with this protocol is that participants can disappear after commiting to a flip. In this case, the chat client will render an error for the flip, since it could be the case that a disappearing participant is just trying to force a new flip to happen (although it is more likely the user just disconnected).
A special feature of the UI is rendering the flip while it is in progress. This can be seen with the orange and purple boxes that animate while the flip is happening. These boxes are a visualization of the bytes of the commitments and secrets as they are received by the chat client. The color of each cell maps a byte of a commitment or secret to a color pallete.