Coinflip provably fair
Coinflip uses a provably fair system in which the public seed is not known until after a coinflip game has started. The result for each round is generated using the SHA-256 hash of 3 separate inputs
1 - The "private seed" is a securely random value, generated when a round is created. The SHA-256 hash of the private seed is displayed to all players immediately after a round is created. Players can check that the private seed revealed after the coinflip result is made known matches this SHA-256 hash.
2 - The "public seed" is the ID of an EOS block, which is to be generated after a round is joined by a opponent. When a round is joined, our system chooses a block number on the EOS blockchain that will be generated in the near future. The ID of this block is what will be used as the public seed. This way, neither the players nor our system know what data will be used to generate the coinflip result until after both players have committed their bets.
3 - Round id
Players can validate any past coinflip by using the code below:
- $game_id = 2820;
- $private_seed = "5a5e6a3494cf9572b6dc5dd6aee4263b6eec8b8f331e29c426d03f9ab6ade17f";
- $public_seed = "076c26818441622607ad1bffbf5f02a90eaadb020532bda9a9d60aedfb217528";
- $hash = hash("sha256", $private_seed . '-' . $public_seed . '-' . $game_id);
- $flip = hexdec(substr($hash, 0, 8)) % 2 + 1;
- echo "Server seed hash: " . $private_seed . "\n";
- echo "Result: " . ($flip == 1 ? 'RED' : 'BLACK');
You can execute PHP code straight from your web browser with tools like PHP Tester. Simply copy-paste the code into the window and replace the private_sedd and game_id values for your own. Execute the code to verify the roll.