What is ZKP suitable for in the gaming field?

Written by Yooma

Image source: https://unsplash.com/photos/people-inside-library-1mwPOXb_pB8

Problems encountered

PopCraft is a full-chain elimination game. Each game lasts 4 minutes. Players will receive token rewards if they eliminate all elements on the board within the specified time.

Due to the full-chain nature, every operation of the player during the game needs to interact with the blockchain. The block time of Ethereum Layer 2 is usually 2 seconds, which means that players need to wait at least 2 seconds for each operation in the game to complete, which is much longer than the waiting time in similar Web2 games, making the PopCraft game experience poor.

PopCraft game main interface


Conceived plan

We envision using zero-knowledge proof technology (hereinafter referred to as ZKP) in PopCraft to reduce the number of interactions players have with the blockchain during the game.

The expected approach is: the game process is not on-chain, but there is a mechanism to ensure that there is no risk of cheating. Players will generate ZKP for each step in the game, and the ZKP of the next step is generated based on the ZKP of the previous step, thus forming a self-contained ZKP similar to the blockchain structure. At the end of the game, the ZKP of the last step will be sent to the chain and the result will be verified by the smart contract.

Solution research and derivation

1. Anti-cheating of game process and results: It is not enough to generate ZKP only for the game results, because cheating is also possible during the game process. Therefore, it is necessary to generate ZKP for the game results and verify the game process.

2. Technical challenges of gradually generating ZKP: To prevent cheating, it is necessary to generate ZKP for each operation of the player in the game, and to verify the last ZKP on the chain at the end of the game. In this process, each step of the ZKP will depend on the previous step of the ZKP until the end of the game.

But the difficulty is:

1> The generation of a new ZKP depends on the previous ZKP, which makes the verification process complicated and uncertain whether it can be implemented. In addition, ZKP verification is done through smart contracts (on-chain). How to verify that the previous ZKP is correct when generating ZKP in the next step?

2> When verifying whether the ZKP at each step is correct through the smart contract, how to ensure the consistency of each ZKP with the previous ZKP. It is not certain whether there is a solution to this problem.

3. The problem of public game data: PopCraft's game data is public, so it is unnecessary to hide information through ZKP. If the above verification steps can be achieved, the next step is to consider saving the game data on the contract side. However, the problem is that the nature of ZKP cannot solve the specific game data, and the game result data sent by the client to the smart contract cannot be directly trusted at this time, which means that the smart contract cannot directly store this data.

4. Issues with consuming game props (consuming tokens) in PopCraft: When the game process involves eliminating isolated elements through game props, it essentially corresponds to token consumption, and the corresponding tokens in the user's wallet need to be transferred. How to handle this step of ZKP generation and verification is also a problem.

1> A possible solution is: this step continues to generate ZKP according to the previous process, verifies the number of tokens consumed and finally sends it to the smart contract. However, since the smart contract cannot obtain specific game data through ZKP, it is impossible to determine the number of tokens that should be transferred.

In addition, if a player has 3 Token A but tries to consume 4 Token A in the game, this error will not be discovered until the end of the game, rather than in real time during the user's operation.

2> Another possible solution is: when using tokens to eliminate isolated elements, directly interact with the smart contract to complete the elimination, and then update the player's token balance. The generated ZKP is only responsible for saving the proof of game operations and status at this time.

So after the token is successfully transferred, you need to continue to generate ZKP as in the previous operation. If you do not generate it, there will be an extra step of interacting with the smart contract between the ZKP generated in the previous step of the token transfer operation and the ZKP generated next time. Then the game status in the ZKP will conflict, and whether the ZKP generated at the end of the game is valid is also an unresolved issue.

5. Data hiding issues with ZKP: For scenarios like PopCraft, which do not need to hide game data, data hiding through ZKP is redundant and increases the difficulty of obtaining game data and the uncertainty of engineering implementation solutions. PopCraft only needs to ensure that there is no risk of cheating in the game process and results, and does not need to hide the game process data.

in conclusion

In games like PopCraft, game data does not need to be hidden, so there is no need to hide information through ZKP. In order to improve the gaming experience by shortening the response time, it is possible to consider not putting the game process on the chain, but only putting the final result on the chain. The key is to find a way to ensure that there is no possibility of cheating from the first step to the last step of playing the game, and finally put the correct result on the chain for verification.

If information is hidden through ZKP, it will increase the difficulty of engineering implementation. The second is how to ensure that there is no risk of cheating during the game process. Using ZKP can ensure that there is no risk of cheating in a single game operation, but in order to reduce the number of interactions with the blockchain, ZKP cannot be generated once and submitted once. So how to ensure that there is no risk of cheating from the first step of the game to the end of the game? At present, it seems that ZKP cannot solve this problem.

From our research, we can see that ZKP in the gaming field is suitable for two types of tasks:

  1. Information hiding in incomplete information game games, such as Dark Forest, Texas Hold'em, Werewolf, Hearthstone, etc.

  2. The game process is a single-step game result proof, such as: lottery, number guessing, rock-paper-scissors, dice games, etc.

Due to our limited knowledge of zero-knowledge proof technology, the content of this article may contain factual errors or unreasonable engineering assumptions. We sincerely ask experts with rich experience in the field of zero-knowledge proof to criticize and correct us.