On-Chain Game Mechanics With ChainSafe And Toshimon
Authored by Timothy Hao Chi Ho
Designing and building blockchain-enabled games
Thank you to Willem Olding and Megs Doyle for their contributions to this article.
① · Introduction
② · Overview: A solution to fair, decentralized, and quality gameplay
③ · Understanding the building blocks of blockchain gaming
④ · Battle game design: Toshimon mechanics
⑤ · Technical aspects: Facilitating ‘proof of fairness'
⑥ · ChainSafe Solutions: Proposal and game development solution
⑦ · Extensibility of base game via state transition decomposition
⑧ · Conclusion: ChainSafe and Toshimon outcome
⑨ · About ChainSafe
Introduction: Full-stack solution providers will drive web3 game adoption
Advancements in blockchain technology have resulted in an entirely new era of gaming. However, the blockchain gaming industry is still in its infancy and will require stakeholders to be educated on the possibilities offered by the technology. This experimentation will allow gamers, studios, and developers alike to co-create new frontiers in gaming.
Fundamentally, the hope of employing blockchain technology in game development is to promote new ways of making games more accessible to all types of gamers. While there is an ongoing debate as to whether blockchain and web3 principles genuinely enhance the gaming experience, the advantages of web3 are clear: decentralization, provenance, sovereign ownership, composable applications, and trust-minimization frameworks.
Big-name game studios have already begun exploring blockchain integrations with use cases spanning marketplaces, multiplayer games, and collectibles. Even smaller-scale indie gaming teams are beginning to explore new primitives such as non-fungible tokens (NFTs), GameFi, and play-to-earn mechanics, as well as how each of these technological innovations can be leveraged in service of advancing today's gaming experiences.
While the future of blockchain gaming is bright and on track to become the frontrunner for web3 adoption, there are still a number of challenges that need to be overcome. Gaming teams must develop blockchain expertise in-house or collaborate with an external organization in order to decrease the human and economic capital associated with building a blockchain-enabled game. As a result, full-stack __ solution providers that are experienced in multi-disciplines, multi-languages, and multi-blockchain ecosystems are crucial as development partners. They point to a future where they are increasingly relied on for the buffing effect they have on web3 game development.
As experts in infrastructure development and protocol engineering, ChainSafe has developed a reputation as one such full-stack solutions provider. This experience crosses over into ChainSafe Gaming, where ChainSafe's gaming SDK, web3.unity deploys key infrastructure for Unity developers integrating blockchain elements into their games. The library has over 10k downloads to date. In addition, ChainSafe's R&D department, ChainSafe Solutions, has engineered novel blockchain solutions for gaming teams. Together, the two - ChainSafe Gaming and ChainSafe Solutions - have unblocked thousands of gaming developers and studios to create games seamlessly, securely, and with dedicated support.
It was ultimately ChainSafe's years of experience, global team of experts, and proven track record of infrastructure development that led the team at Toshimon to collaborate with ChainSafe in researching new ways to leverage blockchain for gaming.
Overview: A solution to fair, decentralized, and quality gameplay
Toshimon is a browser-based online player vs. player (PVP) battle-style trading card game (TCG) that requires the use of non-fungible tokens (NFTs) on the Ethereum/Polygon platforms to act as immutable in-game assets. The project takes after its predecessor, Pokemon, with a clear difference - bringing elements of the game design on-chain. Toshimon targets a wide berth of end-users, including collectors, traders, and gamers. Toshimon's gamification of various aspects of blockchain allows it to double as a fun educational tool for new web3 users.
As part of the solutions engagement between both organizations, the Toshimon team approached the experts at ChainSafe with the following question:
"How can we (Toshimon) make our PVP battle system provably fair and decentralized without compromising the player experience?"
Understanding the building blocks of blockchain gaming
To better understand the need for a solution to the problem statement, it is necessary to understand the common terms associated with blockchain game design:
Provable fairness refers to a system where the fairness of a game can be cryptographically proven. This means that it should be impossible for the game's outcome to be manipulated by any of the players or by the game's operator. To devise such a system, some notion of (1) randomness and (2) the assurance of this randomness must be attained.
Decentralization centers around the concept of immutability and trust minimization. Decentralization mechanics endeavor to decrease the degree of trust that users place in one another and dissuade their capacity to put forth authority or command over each other in a manner that corrupts the potency of the network. Any system devised should minimize (or require zero) trust between players and additionally minimize (or require zero) trust in a third party.
Next, an understanding of compromising the player experience __ must be achieved. In the dial-up era of blockchain, frequent writes to a blockchain state can quickly make a game prohibitively slow and expensive to play. Excessive token approvals, endless prompts by a digital wallet such as MetaMask to sign signatures or send transactions, slow finality, and other web3-native UX could easily break player immersion.
For Toshimon, these are unimpeachable, foundational principles that needed a true web3 solution.
Battle game design: Toshimon mechanics
In order to better understand the approach ChainSafe took to solve the problem statement presented by Toshimon, it's important to break down the game mechanics at hand. The rules of Toshimon should be familiar to anyone who has played a mainline Pokemon game. However, for anyone unfamiliar, here is a high-level overview of the Toshimon gameplay:
There are over 160 different monsters in Toshimon, each with its own set of unique statistics and 140 different moves, as well as 10 different game items. Each of these moves and items has a varied effect on the monsters in battle depending on their stats. As an added layer of complexity, some aspects of the game have a randomized component. For example, a random chance of a critical hit (or miss) and random variation for attacks.
Technical aspects: Facilitating ‘proof of fairness' with Toshimon
As the Toshimon game mechanics do not expand beyond the 1v1 environment, there are useful two-party precedents to draw from: (1) state channels and (2) commit-reveal schemes.
(1) State channels
State channels allow two participants to conduct off-chain transactions directly with each other. Only two transactions are made on-chain: those confirming the initial and the final state. Otherwise, most of the game actions take place within the channel, which is off-chain, free, and has instant finality.
State channels were initially proposed as one scaling solution to Ethereum, where state changes are executed and validated by interested parties, minimizing computation on Ethereum's execution layer. It has seen limited adoption and has since been supplanted by rollup technology. There are a number of reasons for this, but the primary challenges of state channels include:
- Liveness requirements
- Participants must remain online to respond in case another player tries to cheat
- Complexity of implementation
- For a dApp to be state channel compatible, it must be reducible to a state machine that can be implemented in a smart contract
- Restricted participants
- Participants of a channel are fixed upon initialization and cannot be changed thereafter.
However, in the context of a 2-player game with relatively bounded complexity, state channels are a fitting implementation option and can be frequently seen being used in simple 2-player games such as tic-tac-toe and chess.
Points 1 and 3 In the above diagram are non-issues for a typical PVP card game. To put this into context, imagine two people playing cards together at a table. The games are generally quite short in duration, and the player set does not change. As a result, one unanswered question remained:
"Is it possible to implement a game with a vastly more complex ruleset, like Toshimon, in a way that can still be played within a state channel?"
(2) Commit-reveal schemes
Commit-reveal schemes allow for hidden-information games to be played in public environments such as smart contracts and state channels. Without a commit-reveal phase, the player that goes first has a disadvantage as the other player can always see their movements and respond to them accordingly. With commit-reveal, both players submit a blind commitment to their move and only reveal what it is after the protocol has locked in both players' commitments.
This can also be used for creating shared randomness within a two-party protocol. In this scheme, both players commit to some element of randomness in addition to their moves. The contributions from both players can then be combined to determine the outcome of any move where randomness may be required (e.g., critical hits or misses). The two-state commit-reveal ensures that neither player can influence the outcome of the random moves in a predictable way and therefore gain an advantage.
While the above section aims to provide a high-level explanation of the solution ChainSafe designed for Toshimon, a more comprehensive and technical overview can be found here.
ChainSafe Solutions: Proposal and game development solution
Keeping the aforementioned primitives and constraints in mind, ChainSafe proposed improved design mechanics for the Toshimon game.
The implementation of state channels for off-chain transactions makes battles in Toshimon fast, cheap, and transaction-minimizing - one of Toshimon's top concerns for enhanced UX. Within the state channel, an interactive commit-reveal scheme using a randomness protocol was devised to ensure a provably fair battle. The combination of these two elements allows Toshimon NFT holders to conduct off-chain battles with on-chain settlements.
For the state channel implementation, a channel contract was written that allows two players to deposit some tokens on-chain. In doing so, they agree on some initial __ state (e.g., which cards they are using, the health and moves available to each monster, the cryptocurrency wager, etc.) and the rules by which the state can be updated. Players then take turns signing state updates — in Toshimon's case, these are attacks, using items, or forfeiting the game. These updates modify the agreed-upon initial state according to the game's rules. At the end of the battle, th_e_ final state of the channel is committed to the blockchain (such as outstanding balances or the result of a battle).
Since Toshimon battles have a probability associated with each action, a source of randomness must come from a random seed committed by each player during each turn. The action + random seed must then also be revealed along with the action at the end of each turn. This scheme is called a rolling commit-reveal. A clever bit of cryptography assures randomness in a provably fair way, which is then used to dictate the outcome of each state-evolving move. This is the aforementioned randomness protocol.
Extensibility of base game via state transition decomposition
One of the key innovations of this design is observing that the state itself can contain contract addresses for small pieces of the game logic (e.g. one move or one item). As a result, there's no need for a single registry for all of the game rules.
This has a number of very useful outcomes:
-
The game logic can be decomposed into small state-mutating functions. This allows for the large ruleset to be decomposed into a collection of contracts to be deployed incrementally. Much like how cards in games such as Magic: The Gathering or Pokemon TCG can add new rules to the existing game.
-
It makes the game extensible. Anyone can add new functionality at any time, but it is only allowed in a game if both players agree when initializing the channel.
This is implemented in the state by having separate contract addresses for:
-
Items players may have, and
-
Moves each Toshimon is capable of making
Again, it is the responsibility of the players to ensure the initial state is valid (e.g. Toshimon do not know moves they are incapable of). For players using the official Toshimon game client, this can be done automatically, but advanced players may choose to ignore this and play with their own custom rules. A useful analogy would be to imagine a group of individuals taking mainline Pokemon cards and using the printed stats and moves on each card to create their own custom variants of the game.
In the near future, on-chain games with composable game logic will meaningfully modify the in-game experience. This will provide extensibility to the base game in infinitely creative ways. This is a novel innovation for web3 gaming. In fact, it's already being leveraged in games such as Dark Forest, where its community iterates on the game by extending and modifying the base set rule through the use of composable, interoperable smart contracts. In many ways, this is the true promise of blockchain-enabled gaming.
Conclusion: ChainSafe and Toshimon engagement outcome
ChainSafe is proud to have had the opportunity to share our expertise and experience in helping the Toshimon team understand and unlock the potential of state channels.
As a result of the schema recommended by ChainSafe, the Toshimon team went on to finish 2nd in the Grand Prize track at Polygon's BUIDL IT Summer 2022 hackathon. This was indeed fruitful validation for ChainSafe's research and recommendations.
Since Toshimon is built in Unity, we were also able to find natural synergies with ChainSafe Gaming's web3.unity team. In the proposed battle system, it was suggested that transactions and state channel messages be made through the web3.unity SDK. Incidentally, Toshimon had also previously engaged with ChainSafe by bootstrapping their game development with web3.unity - thanks to the web3 sign-in and check ERC-1155 balance prefabs, they were able to effortlessly implement core infrastructure for their game.
ChainSafe Gaming has already done a lot of the groundwork for Unity NFT game developers with its web3.unity SDK. In-game minting, in-game marketplace, web3 sign-in, social sign-in, verifying Solidity messages, sending transactions, and anti-cheat voucher systems are just a few of the features already available with the latest web3.unity release. To learn more, check out NFT Minting And Marketplace For web3.unity.
If you are a gaming team eager to design and implement real web3 solutions - look no further. Enlist the help of an experienced full-stack solutions provider like ChainSafe today. Our around-the-clock and hands-on dedicated team of experts ensure that our services are suited to the needs of your project. We provide a solution for every game so that gamers can experience the new world of web3.
Everything you need starts right here.
About ChainSafe
ChainSafe is a leading blockchain research and development firm specializing in infrastructure solutions for web3. Alongside its contributions to major ecosystems such as Ethereum, Polkadot, Filecoin, and more. ChainSafe creates solutions for developers and teams across the web3 space utilizing our expertise in gaming, bridging, NFTs, and decentralized storage. As part of its mission to build innovative products for users and improved tooling for developers, ChainSafe embodies an open source and community-oriented ethos to advance the future of the internet. To learn more, click here.
Website | Twitter | Linkedin | GitHub | Discord | YouTube | Newsletter