MoneroDice is a dice gambling game that uses cryptography for provably fair randomness.
How exactly does it proves its randomness?
MoneroDice is a dice gambling game that uses cryptography for provably fair randomness.
How exactly does it proves its randomness?
A hex string is created using a hash_hmac(serverSeed, clientSeed_nonce) function, where "clientSeed_nonce" is literally the client seed, the underscore character, and the nonce, all concatenated together.
Then five characters are taken from the hex string to create a roll number.
If the roll number is over 999 999 the process is repeated with the next five characters.
The resulting number (0 to 999 999) has a modulus of 10^4 applied to obtain a roll number (0 to 9999), and then divided by 10^2 to get a final result (0 to 99.99).
The nonce is the sum of bets you made with the current server and client seed.
With the nonce you roll results can be verified with this PHP code below
- Verify the roll results of Monerodice.net *
- required inputs:
- serverHash = $argv[1]
- serverSeed = $argv[2]
- userSeed = $argv[3]
- nonce = $argv[4] *
- outputs:
- server hash correctness
- roll result
code:
if(count($argv) != 5){ print "useage: php verifyMonerodice.php serverHash serverSeed userSeed nonce \n"; exit; }
if(hash('sha256', $argv[2]) == $argv[1]){ //check if hashed serverSeed matches serverHash print "Server Hash is correct! \n"; }else{ print "Server Hash is incorrect! \n"; }
//simulate dice roll to get the exact roll result print "Roll result is: " . rollDice($argv[2], $argv[3].'_'.$argv[4]);
//function which executes dice roll based on your input function rollDice($server_seed, $secret) { $hash = hash_hmac('sha512', $server_seed, $secret);
for($i = 0; $i < strlen($hash); $i += 5)
{
$sub = substr($hash, $i, 5);
if(strlen($sub) == 5)
{
$decimal_number = hexdec($sub);
if($decimal_number < 1000000)
{
$decimal_fourc = bcmod($decimal_number, 10000);
$final_decimal = bcdiv($decimal_fourc, 100, 2);
return $final_decimal;
}
}
else
{
break;
}
}