Explained: Equine Racing Smart Contracts with George Flerovsky

December, 5 2023

Introduction

Last year, Equine NFT initiated a collaboration with the esteemed MLabs to forge the blockchain infrastructure by developing the smart contracts codebase required for horse races to operate seamlessly. George Flerovsky led the efforts from the MLabs side, while Equine co-founder and lead developer Nick Ayotte took on a leadership role within the Equine NFT team. Together, focused work has been directed towards the smooth integration of Smart contracts into the core of the Equine racing engine. In the following article, the fascinating journey and lesson on how Equine horse racing comes to life is delivered under George Flerovsky’s expert guidance.

What is the Partnership behind Equine NFT & MLabs?

Last year, when the team at MLabs was initially contacted by Equine, they had a conversation about the overall scope of the Equine application. This encompassed different aspects like racing, breeding, trading, and metadata. It became apparent early in the process that implementing smart contracts would be essential specifically for the racing component of the game. For a game like Equine NFT, smart contracts would ensure security, transparency, and immutability.

Here’s the Reasoning Behind it

Participating in Equine racing involves a unique commitment, as it entails dedicating your horse exclusively to a specific race. This commitment creates a tangible connection within the virtual blockchain environment. Essentially, when you enter your horse into a race, you are designating it solely for that particular event, ensuring it cannot engage in multiple races simultaneously. To achieve this on the blockchain, you must securely house your horse within a smart contract. Additionally, please note that certain races may entail an entry fee.

What are the Stages of the Equine Races?

An Equine race unfolds through eight distinct stages:

  1. In the initial stage, Equine makes an official announcement about an upcoming race on the blockchain, detailing the race’s terms and particulars.
  2. Subsequently, horse owners partake in the race by registering their horses and submitting the requisite entrance fee.
  3. Following registration, Equine proceeds to allocate gates and discloses the race track and prevailing weather conditions that will be applicable during the event.
  4. Before the race commences, horse owners are afforded an opportunity to withdraw their horses from participation, a process known as “scratching.”
  5. The next stage involves the execution of the randomized race, simulated through Equine’s sophisticated physics model, and presented in a visually captivating 3D viewer for spectators.
  6. As the race concludes, the official results are recorded and published on the blockchain for transparency.
  7. Subsequently, based on these race results, rewards from the prize pool are distributed to the deserving winners.
  8. Finally, upon their exit from the race, horse owners retrieve their horses.

We will delve into each of these stages in greater detail later in this article.

What are Smart Contracts and why use them?

Before we get into each of these stages, let’s take a quick detour to talk about smart contracts.

Wallets

Many of you are likely acquainted with the operation of cryptocurrency wallets. To transfer your tokens to another party, you need to sign and submit a transaction to the blockchain. In essence, a transaction is a written statement that outlines the tokens being utilised. This statement also encompasses additional context, such as the creation or removal of tokens, the distribution of outputs to recipients, and the essential individuals authorised to sign off on the transaction. When tokens involved in a transaction originate from a wallet, the critical factor revolves around the wallet’s authentication of the transaction. Smart contracts allow us to encode a rich set of rules to control what happens on the blockchain, often without any specific person being given a special authority.

Smart Contracts

The primary motivation for employing smart contracts stems from the inherent custodial nature of wallets. The fundamental limitation of wallets lies in their ability to oversee and influence only the process of signing a transaction. When your horses are stored under a wallet address, the sole action you can perform is to verify whether a transaction has been signed by that specific wallet or not. This limitation poses a significant inconvenience when it comes to participating in Equine races, as it would essentially compel you to send your horses and fees directly to Equine solely to facilitate your horses’ engagement in the race.

However, with smart contracts, the smart contract’s rules can comprehensively analyze the entirety of the transaction. Moreover, you have the flexibility to embed intricate logic within these contracts. Smart contracts are especially well-suited for non-custodial setups and processes. This is precisely why we employ them in such contexts.

What do we gain from using Smart Contracts inside Equine?

We eliminate the necessity for Equine to maintain custody of horses, entrance fees, and the prize pool during races. Instead, all these aspects are governed by well-defined regulations encoded within the Equine smart contracts. These regulations not only outline the standard race proceedings but also encompass provisions for addressing exceptional scenarios that may occur. For instance, Equine possesses the authority to cancel a race before the starting bell, with a guarantee that horse owners can retrieve both their horses and entrance fees in such instances. Likewise, if a race experiences delays for any reason, owners can reclaim their horses and fees once a predefined safety timeout period has elapsed.

Similarly, if Equine fails to fulfil its obligations, such as announcing race results or providing gate assignments based on the random simulation, your digital assets do not become trapped within the smart contracts. We have implemented a safety mechanism to ensure your ability to reclaim all your assets in such circumstances.

Race Announcement: How will players be informed about upcoming Races?

Equine showcases the forthcoming race schedule prominently on its website. Once the registration window becomes available for a particular race, Equine will make an official blockchain announcement, providing comprehensive information about the race, including key details and terms. This announcement encompasses critical elements such as the race’s commencement time, registration cutoff, entrance fee, racecourse location and description, as well as the prize pool and the distribution mechanism for race winners. The blockchain announcement serves as a crucial step to ensure transparency, making the race visible to all and safeguarding the unalterable preservation of race terms for future reference.

Fairness and Reproducibility of Horse Races

Equine places a strong emphasis on both fairness and the ability to replicate races. On one hand, we aim to maintain the excitement for players as they discover their horses’ potential in races filled with unpredictability. This objective necessitates the safeguarding of certain information by Equine. On the other hand, we prioritize instilling trust in players regarding the game’s integrity and fairness. To achieve this, we employ reproducible algorithms for the calculation of horse matchups, race simulations, and the generation of race outcomes. These algorithms exhibit determinism, except for two key variables: the random seed used to introduce randomness into the race, and the specific set of horses registered for the race at the time of the race announcement.

To maintain transparency and ensure the integrity of the process, Equine includes cryptographic hashes of both the simulation engine code and the random seed in the race announcement. This strategic measure serves as a safeguard against any potential manipulation. If Equine were to employ a different simulation engine or random seed to generate race results, any inconsistency with the provided hashes and the announcement would become evident. Consequently, all race outcomes within Equine should be replicable by an independent third party who cross-references private data with publicly available information and conducts the race simulations.

If discrepancies arise in the outcomes, it indicates that something changed between the race announcement and the actual race results. This meticulous process is Equine’s method of introducing fairness and reproducibility into its races.

Registration: How Players can enter an Upcoming Race?

Once a race is announced, you can join by sending your horse and the required entrance fee to the racing smart contract while specifying the race you wish to register for. Additionally, you have the option to customize your horse’s appearance by choosing from your collection of jockeys, horse skins, and jockey skins to enhance your horse’s presentation during the race.

The process is quite straightforward. All you need to do is transmit your horse and the entrance fee to the specified entry point within the smart contract before the registration deadline, clearly indicating your preferred race. Importantly, any tokens sent in this process are not retained within the smart contract but are promptly returned to the sender.

Gate Assignment

Following the registration process, Equine proceeds to pair up horses and allocate them specific numbered gates on the racetrack. This operation is executed through a blockchain query that identifies the registered horses, filtering out any entries that do not adhere to the race regulations. Furthermore, the process incorporates the use of a random seed to ensure a randomised pairing of horses and their subsequent gate assignments. Subsequently, these horse matchups and gate allocations are documented on the blockchain, alongside comprehensive information about the racetrack conditions and prevailing weather.

Scratching your horse from the race

Upon the unveiling of the matchups, gate assignments, and track conditions, participants are presented with the chance to withdraw their horses from the race before it officially commences. This opportunity arises when they gain insight into their competitors’ horses, as well as the prevailing racetrack conditions and weather forecasts. It allows horse owners to opt out of the race if they deem it necessary. However, it’s important to note that a scratching fee applies, and this fee is calculated as a percentage of the initial entrance fee.

The Simulation Model

At the commencement of the race, Equine employs its advanced model to conduct a simulation of the horse race. The resulting race outcome is influenced by various factors, including the physical and mental attributes of the racing horses, the personality of the jockeys, and the prevailing conditions on the race track and in the weather. These elements are intricately intertwined and amalgamated with a random seed, which is then processed by the simulation engine. This engine meticulously takes into account the complex physics involved when horses sprint alongside and ahead of each other, all the way to the finish line. As a result, spectators are treated to a visually captivating 3D representation of each race, accessible through the Equine website.

Results & Rewards

After the race concludes, Equine takes the initiative to publish the race simulation results directly onto the blockchain. This ensures transparency and provides a reliable source for all participants to access the outcome of the race. Moreover, the process of reward distribution is seamlessly executed by the racing smart contracts, eliminating the necessity for any additional involvement from Equine. Participants, especially the winners, can conveniently claim their prizes through the front-end smart contract interface without requiring any manual intervention from Equine. This automated system underscores the primary purpose of smart contracts in this context – to facilitate efficient and trustless operations within the horse racing ecosystem.

Next article

Introducing Equine NFT Skins Collections