Introducing the Ultimate Dice Roller: Provably Fair Rolls for Your Games!

in Synergy Builders5 days ago

Hey everyone,

Today, I'm excited to share a new tool I've been working on, something a bit different from my usual Hive-specific scripts but definitely useful for a community I also love: tabletop roleplayers! Introducing the Ultimate Dice Roller, now live at:
https://dice.thecrazygm.com

Why Another Dice Roller? Provable Fairness!

We all love the feel of physical "click-clack math rocks," but when playing RPGs online (like over Discord, Roll20, etc.), we often rely on digital rollers. How do you really know they're fair and not just spitting out pre-determined numbers or being influenced in some way?

The goal of the Ultimate Dice Roller is to be provably fair. This means that every roll generates a cryptographic proof that can, in theory, be independently verified by anyone, assuring you that the outcome was truly based on the inputs and a transparent process.

How Does the "Provably Fair" Part Work (Simply Put)?

The system uses a few key pieces of information to generate a roll:

  1. Server Seed: A secret piece of data known by the server.
  2. Client Seed: A piece of data provided or known by your browser/client.
  3. Nonce: A number that starts at 0 and typically increases with each roll made with the same server/client seed pair. This ensures you get a different result even if the seeds stay the same for a bit.

Here’s a simplified rundown of what happens when you roll:

  • Your browser and the server establish a client_seed and a server_seed. (Currently, for this proof-of-concept version, both of these are generated randomly for each interaction to demonstrate the mechanism).
  • These seeds, along with the nonce, are combined. Specifically, a message like client_seed:nonce is created.
  • This message is then cryptographically hashed with the server_seed using a standard algorithm called HMAC-SHA256. This produces a unique, long hexadecimal string (the "proof").
  • This hexadecimal proof string is then used to determine your dice results. For example, a chunk of the hex string is converted to a number, and then a modulo operation gives you the die face (e.g., (number_from_hash % 20) + 1 for a d20).
  • Crucially, after the roll, the tool shows you the server_seed it used, your client_seed, the nonce, the final proof (hash), and of course, your dice results. With all these inputs, anyone can re-run the exact same calculation and verify that the dice results match the given proof.

The provably_fair_roll function in the backend takes these seeds and the nonce, creates the HMAC-SHA256 digest, and then deterministically derives the dice results from that digest.

Future Plans: Hive Integration for True Randomness!

Right now, as a proof of concept, the server_seed and client_seed are generated randomly by the application. The next big step to make this truly and transparently provably fair is to tie the seed generation to an external, unpredictable, and publicly verifiable source. My plan is to integrate this with the Hive blockchain by using hashes from the latest Hive blocks to generate the server_seed (and potentially influence the client_seed generation). This way, the "secret" server seed isn't just generated by my server but is derived from a public, immutable ledger.

Not as Fun as Physical Dice, But Great for Online Play!

I know, I know, it's not quite the same tactile joy as rolling your favorite set of magical lucky dice. But for online games, especially in Discord or other platforms where you need a quick, reliable, and trustworthy dice roll, I think this will be a great utility.

Here's a peek at the interface:

The Ultimate Dice Roller in action!

The tool features quick roll input (like 2d6+3), dice cards for common types, and a roll history. And, of course, there's a page where you can take the details from any roll and verify the proof yourself .

Check it Out!

Give it a whirl at https://dice.thecrazygm.com and let me know what you think! It's still a work in progress, especially with the Hive integration for seeds still to come, but the core provably fair mechanism is there to play with.

As always,
Michael Garcia a.k.a. TheCrazyGM

Sort:  

A long time ago, in STEEM days, @croupierbot basicly did what you are aiming for, but likely in a bit too slow way. In this post from 2017 outlines one of its previous use-cases.

The bot when invoked basicly anounced which not-yet-existing near-future block it was going to us for its randomness, then used the block signature in a repeatable way.

Working on a hash-based signatures project, I had been thinking of improving on this setup to allow for quicker access to randomness, and it is not that hard.

The trick is to:

  • Pick your own secret seed using a decent source of entropy
  • Derive a larger set of random keys using the root seed and an index
  • Use the random keys as private keys in a Winternitz chain setup.
  • Use the resulting Winternitz pubkeys in a merkle tree
  • Publish the merkle root together with a near future block number for the HIVE blockchain.
  • Wait for the block with the given block number to be published and take a sufficiently safe chunk of the signature.
  • For every dice role, create a hash based signature of the signature chunk with the next set of Winternitz chains.
  • Convert the signature to base-6 to emulate dice role and publish the dice roll.
  • Repeat untill all Winternitz chains are used up.
  • Publish your seed.

Now after your seed is published, maybe something like 32 five-dice rolls would become verifyable.

Very cool tool, my friend, and I can see how this would be very useful for the RPG community. I love all your coding creativity. 😁 🙏 💚 ✨ 🤙

Appreciate this, just in time for playing some more games!

!PIMP
!PAKX
!PIZZA

View or trade PAKX tokens.

@ecoinstant, PAKX has voted the post by @thecrazygm. (2/2 calls)

Use !PAKX command if you hold enough balance to call for a @pakx vote on worthy posts! More details available on PAKX Blog.

PIZZA!

$PIZZA slices delivered:
@ecoinstant(4/20) tipped @thecrazygm

Come get MOONed!

Congratulations @thecrazygm! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You distributed more than 31000 upvotes.
Your next target is to reach 32000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP