create account

Magic Dice Tech Talk - Provably fair and transparent by magicdice

View this thread on: hive.blogpeakd.comecency.com
· @magicdice · (edited)
$0.44
Magic Dice Tech Talk - Provably fair and transparent
<html>
<p>https://cdn.steemitimages.com/DQmardXbmhqGedq6vtJStwsxwgm7XvAy6DeSxpJXRhDieXa/magic-dice-header.png</p>
<p>Magic Dice is a provably fair and transparent dice game built on the Steem blockchain. If you haven't tried it yet, go to https://magic-dice.com and give it a try.
In this post we want to explain the tech behind the game. This post is rather technical. If you just want some general information about the game, go to the <a href="https://steemit.com/steemit/@magicdice/introducing-magic-dice-provably-fair-and-transparent-dice-game-on-steem">introduction post</a>.</p>

<br>
<br>
https://cdn.steemitimages.com/DQmep5e2bwNT9bK2KVhfEvx2hcZcXWQQ9XUnJsjbUdFq49s/seperator.png
<br>
<br>
<h1>Random Numbers</h1>

<p>Random numbers for Magic Dice are generated by the use of two seeds: Server seed and client seed. Every player can choose his own client seed. The server seed is generated on the server, hashed and posted to the Steem blockchain. Since the server seed hash was published before every dice roll, there is no way for us to alter the outcome without the verification failing.<br>

<p>
The hash is a SHA256 hash which can be created and verified with following script:
</p>
<p>
<code>const hash = crypto.createHash('sha256').update(serverSeed).digest('hex'); </code>
</p>

<br>
<br>
https://cdn.steemitimages.com/DQmep5e2bwNT9bK2KVhfEvx2hcZcXWQQ9XUnJsjbUdFq49s/seperator.png
<br>
<br>
<h1>Seed/Hash Publishing</h1>
<p>The following image shows how seeds and seed hashes are published:<br>

<p>
https://cdn.steemitimages.com/DQmbn9K62pvXJHV4pTdpg7MgeJcdryvy7dSNBXdo53BPniu/seed_publish.png
</p>

<p>
A new seed and seed hash (Seed 1/SeedHash 1) are generated on the server. SeedHash1 is posted to the blockchain. After n blocks (n is 20 atm), a new seed and seed hash (Seed 2/SeedHash 2) are generated. The new seed hash is posted to the blockchain. On the next block, the old seed is published. A seed/seed hash is valid after the block it was published until a new seed/seed hash is published (Including the block where the new seed hash was published). 
</p>
<p>
In this example Seed1 is valid from Block 2 - Block 21. The seed is generated and the seed hash published before the bets take place. That means that it can be proven that all server seeds were generated before any user placed a bet. After a seed was published, all bets placed earlier can be verified. At the moment that means that a dice roll can be verified after max. 20 blocks or around 1 minute. In the future we might reduce that time to make it possible to verify dice rolls earlier.</p>

<p>
You can see on https://steemd.com/@magicdice how the seeds/hashes are published via custom_json:
</p>

<p>
https://cdn.steemitimages.com/DQmb4wxM7Mnq88r1K3L6nbz2N2jGSM6qujGxH4crTZzGwZP/steemd_seed.png
</p>


<br>
<br>
https://cdn.steemitimages.com/DQmep5e2bwNT9bK2KVhfEvx2hcZcXWQQ9XUnJsjbUdFq49s/seperator.png
<br>
<br>
<h1>Dice Roll Script</h1>
<p>Dice rolls are calculated with following script:
</p>

<p>
<code>let cryptoHmac = crypto.createHmac('sha256', serverSeed); <br>
let resultSeed = cryptoHmac.update(`${clientSeed}-${blockNumber}`).digest('hex'); <br> 
let resultNumber = parseInt(resultSeed.substr(0, 10), 16); <br>
let diceRoll = (resultNumber % 100) + 1; <br>
</code>
</p>

<p>
Additionally to the client seed, the block number acts as nonce. To create the result seed, the server seed, client seed and block number are used and hashed with HMAC SHA256. The first 10 characters of the result seed hex are used and parsed to integer. The final dice roll is then calculated from the result number via % 100 + 1.</p>

<br>
<br>
https://cdn.steemitimages.com/DQmep5e2bwNT9bK2KVhfEvx2hcZcXWQQ9XUnJsjbUdFq49s/seperator.png
<br>
<br>
<h1>Verify Dice Roll</h1>
<p>Every dice roll can be verified on https://magic-dice.com/verify. Enter the bet Id that's included in every transaction. Note that dice rolls can only be verified after the server seed has been published. The page includes a script that can be copied and executed on an online Node.js editor like <a href="https://repl.it/languages/nodejs">Repl.it</a>. The script includes the whole calculation of the dice roll and all necessary values.</p>

<p>
<center>https://cdn.steemitimages.com/DQmXqTFBe8SoK8sn7XNTKmpTqG8roFRwHWCtHtqaHJEKGMm/verify_roll.png</center>
</p>

<br>
<br>
https://cdn.steemitimages.com/DQmep5e2bwNT9bK2KVhfEvx2hcZcXWQQ9XUnJsjbUdFq49s/seperator.png
<br>
<br>
<h1>Report</h1>
<p>We have uploaded a report script for Magic Dice on Github - <a href="https://github.com/magic-dice/magic-dice-report">Magic Dice Report</a>. This script allows to verify all dice rolls for a certain range of blocks. Additionally it shows how many bets were placed, total payout, highest payout, ... We plan to include an option to create a report for Steemit as well. We are going  to create daily transparency reports and encourage other users to do the same.<br>
<br>
</p>

<p>
If you have any questions, just contact us on Discord or leave a comment.<br>
</p>
<br>
<center>
<a href="https://discord.gg/h8pR2tc">
<img src="https://cdn.steemitimages.com/DQmRXfbAaCFXHEJUHP3KA1bau9iC2sF77YTn2Y5xNJit66F/8dd5c907f2a0eecb73dc6a4776fc9a25878ebcdd.png"></a>
</center>

</p>
</html>
👍  , , , , , , , , , , , , , , , , , ,
👎  , , , , , , ,
properties (23)
authormagicdice
permlinkmagic-dice-tech-talk-provably-fair-and-transparent
categorysteemit
json_metadata{"tags":["steemit","steem","cryptocurrency","news","money"],"image":["https://cdn.steemitimages.com/DQmardXbmhqGedq6vtJStwsxwgm7XvAy6DeSxpJXRhDieXa/magic-dice-header.png","https://cdn.steemitimages.com/DQmep5e2bwNT9bK2KVhfEvx2hcZcXWQQ9XUnJsjbUdFq49s/seperator.png","https://cdn.steemitimages.com/DQmbn9K62pvXJHV4pTdpg7MgeJcdryvy7dSNBXdo53BPniu/seed_publish.png","https://cdn.steemitimages.com/DQmb4wxM7Mnq88r1K3L6nbz2N2jGSM6qujGxH4crTZzGwZP/steemd_seed.png","https://cdn.steemitimages.com/DQmXqTFBe8SoK8sn7XNTKmpTqG8roFRwHWCtHtqaHJEKGMm/verify_roll.png","https://cdn.steemitimages.com/DQmRXfbAaCFXHEJUHP3KA1bau9iC2sF77YTn2Y5xNJit66F/8dd5c907f2a0eecb73dc6a4776fc9a25878ebcdd.png"],"links":["https://magic-dice.com","https://steemit.com/steemit/@magicdice/introducing-magic-dice-provably-fair-and-transparent-dice-game-on-steem","https://steemd.com/@magicdice","https://magic-dice.com/verify","https://repl.it/languages/nodejs","https://github.com/magic-dice/magic-dice-report","https://discord.gg/h8pR2tc"],"app":"steemit/0.1","format":"html"}
created2018-11-26 14:39:18
last_update2018-11-26 14:56:42
depth0
children1
last_payout2018-12-03 14:39:18
cashout_time1969-12-31 23:59:59
total_payout_value0.334 HBD
curator_payout_value0.109 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,232
author_reputation22,890,191,383,200
root_title"Magic Dice Tech Talk - Provably fair and transparent"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id75,937,763
net_rshares712,949,414,279
author_curate_reward""
vote details (27)
@apirone.com ·
If you want to sell this file for Bitcoins, use https://SatoshiDisk.com/
Don't need to create account or pass KYC. Upload, Share, Profit!
properties (22)
authorapirone.com
permlinkpu0rao
categorysteemit
json_metadata{"tags":["steemit"],"links":["https://SatoshiDisk.com/"],"app":"steemit/0.1"}
created2019-07-02 14:37:39
last_update2019-07-02 14:37:39
depth1
children0
last_payout2019-07-09 14:37:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length137
author_reputation1,313,061,658
root_title"Magic Dice Tech Talk - Provably fair and transparent"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id87,675,092
net_rshares0