Mental Poker for Turn-Based Strategy Games – Securing Fairness Without a Trusted Third Party
Total Page:16
File Type:pdf, Size:1020Kb
Mental poker for turn-based strategy games – securing fairness without a trusted third party Stian Aleksander Ellingsen 15-12-2016 Master’s Thesis Master of Science in Applied Computer Science 30 ECTS Department of Computer Science and Media Technology Norwegian University of Science and Technology, Supervisor: Mariusz Nowostawski Abstract Strategy video games typically provide players with only partial information about the game world, hiding everything outside the range of vision of each player’s units. A third party is typically trusted with running the game and lim- iting the information given to players. A player colluding with the third party could gain a huge unfair advantage by accessing more information than allowed by the rules, and such cheating is generally undetectable. Between players who don’t trust a common third party, a different solution is needed. The same problem arises for card games when implemented over a computer network in a provably fair way without a trusted third party. In card games, this problem is known as mental poker, and a solution to this problem was first suggested in 1981. While turn-based strategy games and card games have some important elements in common, the methods provided in mental poker solutions do not translate directly to turn-based strategy games. Some work has been done on hiding player units in strategy games without a trusted third party, but not completely without unwanted information exposure. There is also previous work on securely generating maps for strategy games with- out a third party, but not in a way that hides unexplored terrain. This project applies the problem of mental poker to provide a protocol for playing a turn-based strategy game over a network, with computational require- ments that can be met by a normal computer. This includes securely generating random maps, hiding unexplored terrain and units with negligible information exposure during gameplay, while dissuading attempts at cheating or disruption. Mental poker for turn-based strategy games – securing fairness without a trusted third party Contents Contents .................................... i 1 Introduction ................................ 1 1.1 Problem description . .1 1.2 Threat model and principles . .2 2 Related work ................................ 3 2.1 Fair play . .3 2.2 Obtaining randomness . .4 2.3 Map generation . .5 2.4 Consequences of the game outcome . .5 3 Protocol ................................... 7 3.1 Game initialisation . .7 3.1.1 Game parametres . .7 3.1.2 Private keys . .8 3.1.3 Contract . .8 3.1.4 Modulus . .9 3.1.5 The game state . 10 3.1.6 Initialisation of the game state . 10 3.2 Privately retrieving randomness . 10 3.3 Updating and retrieving encrypted game state . 11 3.4 Verification . 11 3.5 Ending the game . 11 3.6 Cipher . 12 4 Map generation .............................. 14 4.1 Algorithms . 15 5 Security parametres ............................ 19 6 Performance analysis ........................... 20 6.1 Blockchain scripts . 21 7 Enforcing fair play ............................ 23 8 Conclusion and future work ....................... 25 A Blockchain details ............................. 27 A.1 Features . 27 A.2 Objects . 27 i Mental poker for turn-based strategy games – securing fairness without a trusted third party A.2.1 State . 27 A.3 Branches . 28 A.3.1 REVEALp ............................ 28 A.3.2 GENERIC ............................ 28 A.3.3 TIMEOUTp ........................... 28 A.3.4 CHEATi;j;p;q ........................... 28 A.4 Programs . 29 A.4.1 progMain . 29 A.4.2 progRevealp;q ......................... 29 A.4.3 progWithStatei;p;q ....................... 29 A.5 Transactions . 29 A.5.1 txFunding . 29 A.5.2 txResignp;q .......................... 30 A.5.3 txRevealp;q .......................... 30 A.5.4 txWithStatei;p;q ........................ 30 A.5.5 txDefaultp;q .......................... 30 B Source code ................................ 32 B.1 Blockchain.hs . 32 B.2 Compile.hs . 42 B.3 Game.hs . 54 Glossary .................................... 59 Bibliography .................................. 62 ii Mental poker for turn-based strategy games – securing fairness without a trusted third party Chapter 1 Introduction The project deals with the problem of playing a turn-based strategy (TBS) game between two or more players over a network, in such a way that each player is able to ensure that the game is fair, without players having to trust each other or a common third party. This problem is greatly complicated when each player should be restricted to seeing only the parts of the game world that their own units can see, a typical feature in strategy games. 1.1 Problem description In strategy video games, players typically control a set of units placed in a game world shared with opponents. Depending on their type, units can be commanded to explore the world, to collect resources found in the world, or to combat against opponent units. Two main sub-genres are real-time strategy (RTS) games and TBS games, which mainly differ in the way timekeeping works. In RTS, time is continuous, while in TBS, players’ actions are grouped in turns. An important feature in many strategy video games is the effect referred to as fog of war: A player can only see the part of the game world that is within their unit’s line of sight [1]. However, the whole game state is usually available to the computer which is running the game logic, and may easily be accessed by the owner, which could be one (or all) of the players, or a third party which could be colluding with one of the players. This type of cheating may give a player a huge advantage over honest players and can’t be detected directly, if at all. Mental poker, introduced by Shamir, Rivest and Adleman [20], involves play- ing a game of cards at a distance, using only messages between the players. To ensure a fair method of playing mental poker, important properties of a physical equivalent of the game are preserved, such as ensuring a fair deal, being able to hide one’s own hand from other players, and making sure that two players can’t have the same card. This is made possible with the use of cryptography. For example, securely shuffling the deck can be done by having each player encrypt 1 Mental poker for turn-based strategy games – securing fairness without a trusted third party each card in the deck, shuffle the deck and then pass it to the next player. While mental poker is mostly concerned with card games [21], the same prob- lem can be applied to other types of games as well. The element of incomplete information is similar to fog of war in strategy games, and TBS games in partic- ular are played in turns like card games. Applying the problem of mental poker to TBS games prompts the need for a protocol for playing a TBS game over a network, fairly, and with negligible information exposure, enforcing fog of war on units as well as the rest of the game world. This project seeks to provide a practical solution to this, including methods to sufficiently dissuade attempts at cheating or disruption. 1.2 Threat model and principles Two players want to play a TBS game against each other over the Internet. They do not trust each other to play fairly, nor do they have a trusted third party (TTP) in common to run the game and decide on the outcome. Each player is assumed to play the game on a computer system that they fully control and trust. For the purpose of this project, cheating involves retrieving information that should not be accessible to the player or modifying the game state in a way that is not allowed by the game rules. Other actions that may be considered cheating, such as disrupting the network connection of the other player or using additional computer software to aid in or automate selection of game actions, are not considered in this project. 2 Mental poker for turn-based strategy games – securing fairness without a trusted third party Chapter 2 Related work 2.1 Fair play This thesis applies the problem of mental poker to turn-based strategy (TBS) games. There has been a lot of research on mental poker, but this has mostly focused on card games [21]. It is not obvious how to apply methods of shuffling and dealing cards to a TBS game. Nonetheless, the cryptographic primitives used for these games could be useful. The mental poker protocol given by Shamir, Rivest and Adleman [20] relies on a commutative encryption scheme, meaning that the order of encryption doesn’t matter when a message is doubly encrypted with different keys – a description of such a scheme is given by Pohlig and Hellman [18]. In a game between Alice and Bob, Bob starts by encrypting and shuffling the cards, sending the deck to Alice. To obtain her hand, Alice takes a random set of cards, encrypts them and gets Bob to decrypt them. Alice then decrypts these. This way, Alice can’t control which cards she obtains, and Bob can’t know Alice’s hand. Goldreich, Micali and Wigderson [13] give a general solution for playing any mental game as long as the majority of the participants are honest. This is done by building circuits of logic gates to implement the whole game. The purpose of their paper is to prove that such a model exists, and efficiency is not a concern. However, for something as complex as a full TBS game, performance will quickly become an issue. Chambers et al. [9] give a method for detecting when a player has bypassed the fog of war to reveal opponents’ units and positions. The method works by exchanging bitmaps of the visible areas between players, and only sending infor- mation about the units that should be seen by each opponent.