[V0.1.4] - SteemCasino - Roulette, Dices and Slots are now provably fair.

Repository

https://github.com/andreistalker/steemcasino

Pull Request

https://github.com/andreistalker/steemcasino/pull/27

New Features

  • Jackpot now shows it's secret and hash, it was always there, but hidden in the console.

To implement this, every time a new jackpot starts, a new secret and hash are received and changed using those lines.

$("#hash").text("Current hash: " + msg['hash']);
$("#secret").text("Last round secret: " + msg['lastSecret']);
  • We are now generating the blackjack decks using a seed, so blackjack is now provably fair.

A random seed is created using the mt_rand function, salted using the generateSecret function that returns a random string with the first letter being A or B, and the secret is getting hashed, the hash will be shown to the player after the game starts.

$seed = mt_rand();
+                   
+                   $secret = $seed."-".generateSecret();
+                   $hash = hash("sha256", $secret);
+                   
+                   $deck = createDeck($seed);

The createDeck function, firstly creates a default deck with all the cards in order like this: 2 of hearts, 2 of diamonds, 2 of spades, 2 of clubs, etc.... Then the deck is shuffled using the seed.

function createDeck ($seed) {
    
    $deck = [];
    
    for($i = 2; $i <= 14; $i++ ) {
        array_push($deck, [$i, "A"]);
        array_push($deck, [$i, "B"]);
        array_push($deck, [$i, "C"]);
        array_push($deck, [$i, "D"]);
        
    }
    $deck = shuffleDeck($deck, $seed);
    return $deck;
}

function shuffleDeck(&$items, $seed)
{
    @mt_srand($seed);
    for ($i = count($items) - 1; $i > 0; $i--)
    {
        $j = @mt_rand(0, $i);
        $tmp = $items[$i];
        $items[$i] = $items[$j];
        $items[$j] = $tmp;
    }
    
    return $items;
}

The secret is shown after the game has finished so the player can take the seed out of the secret and recreate the deck using the previous 2 functions.

  • Roulette is now provably fair.

Now, after each game finishes we are generating the next roll and salting it then hashing it and showing it to the players so they know that we don't change the result. The hash is shown when the betting round starts and the secret is shown after the roll happend.

+      rouletteRoll = roll();
+   var secretos = rouletteRoll + "-" + randomstring.generate(100);
+   rouletteHash = sha('sha256').update(secretos).digest('hex');
  • Dices and Slots are now provably fair.
    Those 2 work almost the same and will explain only dices.

Now, you will need to provide your own secret when you play dices, the secret you provide will change the outcome of the game.

You can see a hash on that photo. A new secret is now created when you first join the website or after a game. The secret will only change when you create a new game. The first generateSecret acts as the seed and the second as the salt for the hash.

$dices = generateSecret()."-".generateSecret();

So, how do you influence the outcome of the dice roll????

Simple, we're now using a hash_hmac function that takes your secret and uses it as a seed.
The hash_hmac function will return a 128 hex hash. We're taking the first 5 characters and we're converting in base 10, the number will be between 0 and 1048575, if the number is over 1000000 we're taking the next 5 characters and converting in base 10, if all the numbers are over 1000000 then the roll will always be 4500, but this is extremely rare. When we find a number under 1000000 we're dividing it with 100 giving us a number between 0 and 9999 which is perfect for our roll. Here is the function.

function dicesPick($seed, $secret) {
    $result = hash_hmac('sha512', $seed, $secret);
    
    $found = 0;
    $new = 0;
    
    for($i = 5; $i < 128; $i += 5) {
        $new = substr($result, ($i - 5), $i);
        $new = base_convert($new, 16, 10);
        if($new <= 999999) {
            $found = 1;
            break;
        }
    }
    
    if($found == 0)
        $new = 4500;
    else
        $new /= 100;
    
    return floor($new);
}

And here is the function for the slots. (It is run 3 times)

function slotPick($seed, $secret) {
    $result = hash_hmac('sha512', $seed, $secret);
    
    $found = 0;
    $new = 0;
    
    for($i = 5; $i < 128; $i += 5) {
        $new = substr($result, ($i - 5), $i);
        $new = base_convert($new, 16, 10);
        if($new <= 1000000) {
            $found = 1;
            break;
        }
    }
    
    if($found == 0)
        $new = 1;
    else
        $new /= 10000;
    
    $pick = floor($new);
    
    if($pick <= 30)
        return 0;
    else if($pick <= 60)
        return 3;
    else if($pick <= 75)
        return 2;
    else if($pick <= 90)
        return 1;
    else if($pick <= 97)
        return 4;
    else
        return 5;
}

And if the player wants to verify he will use this functions.

  • Implemented Insurance and Double Down for Blackjack
H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now