EndlessGame: Provable Fairness on the EOS Blockchain — Dev Blog 1

Endless Game
Endless Game
Published in
5 min readOct 25, 2018
“ball with number lot” by dylan nolte on Unsplash

When it comes to probability games like dice, roulette, poker, etc. It is of the utmost importance to ensure randomness is generated with a fair and unbiased mechanism.

In the pre-blockchain age, players had no choice but to trust centralized game mechanisms generally referred to as “the house.” Lack of transparency for the process of randomness generation often left players with no choice but to use poor signals, such as the reputation of the house or the appearance of the website to gauge the fairness of the games.

Throughout the history of online gaming, these half-measure checks for fairness have been abused consistently. Now, with blockchain we can now implement a trustless way to generate provably fair randomness in a completely transparent manner.

The Big Idea

How can I generate random numbers inside a smart contract?

“person holding black ace and king spades playing cards on poker table” by Michał Parzuchowski on Unsplash

The question of “how to generate randomness on a blockchain” has been a popular conundrum for smart contract developers since the industry began. This answer on StackExchange by the great Bytemaster himself provides a two-party randomness generation model.

Bytemaster on randomness generation

In layman’s term, this process is like having two players comparing numbers on their cards:

First Step: Both players put down a card of their choice facedown (Submitting hashes of their secrets)

Second Step: Both players reveal the cards within a certain time (Reveal players’ secrets)

Third Step: Comparing the numbers of the cards (Combining secrets to generate the final random number)

The core of this method is that neither of the players can change the card or know another player’s card before revealing both cards.

In this way, the final result is generated with seeds provided by both parties, player & house. However, the method has a minor flaw — it requires two steps, hash submission and seed submission. This might not seem to be a big issue at first glance. However, when it comes to actual engineering implementation, it requires that the player of the game to take two separate steps in order to play one simple round of dice. This interrupts the user’s experience of the game and is thus sub-optimal design.

An Optimized Solution

In order avoid this issue and give our player a seamless gaming experience, we made adjustments and improvements to the model proposed by Bytemaster, so that players can finish everything in one step.

Back to our layman’s poker analogy for a moment.

Before the game, player 1 places a card facedown. In this way, it is certain that player 1 cannot change the card during the game. Then, player B puts their card down face up. In this way, players can finish the game in one step.

A Closer Look

The following sequence diagram is an excellent illustration of the whole process.

0. The player initiate the game by placing bet on desired number and clicking the “Roll” button on the website;

  1. After the user’s action, the user’s request will be sent to our server along with referral information.
  2. The house will create a random seed for each player and each game. And then calculate the hash.
  3. In order to ensure the house cannot change the house seed during the game, information provided by the user and the hash of the house seed will be used to create a signature and sent back to the player — All information will be displayed in Scatter Memo.
Player’s customized seed, Hash of house seed and the signature provided by the house

4. After the player’s approval of the transaction, all the information will be sent to the smart contract together with the plaintext of the player’s seed.

5. Then, the house will submit the house seed in plaintext to the smart contract in order to reveal the final lucky number.

6. The lucky number is generated using both the user-provided seed and the house-generated seed.

A code snippet from our smart contract

How to verify?

You might be curious that how can I verify the result is actually fairly generated?

After revealing the lucky number each game, we will post a transaction log on the blockchain — You can find them in endlesslogs1.

A piece of transaction log posted by us (endlesslogs1)

You are able to calculate the lucky number yourself with the code shown below.

Furthermore, since all the results are recorded on EOS blockchain , one can easily see if the number is distributed evenly in the 1~100 range. During our test stage, we have conducted simulations to see the distribution of the lucky number. There was no pattern detected.

Questions?

if you have any question, you could reach out to us via our email (team@endless.game) or our social media channels.

Discord | Twitter | Medium

--

--