drand explainer for beginners
A brief primer on what drand is and how it works.
drand is software for running a threshold network that generates publicly verifiable random numbers.
Boy, that's a mouthful.
To the uninitiated, a bunch of questions spring to mind: What on earth is a threshold network? How can random numbers be verified?! Surely they're random? Why would I want my random numbers to be public?
Well, this blog post is the right place to uncover all the mysteries of the above statement. Let's work backwards to build up a picture of what drand is and how it works.
Random numbers
What constitutes a random number?
There are some fancy mathematical definitions, but stated simply: it's a number that cannot be guessed at a rate better than chance.
Suppose we choose a random number in the range 1 and 100 (including 100). If we asked 100 people to guess our number, on average only one of those people would guess the number correctly, even with a fully random selection process.
For cryptographic purposes, it's often important that two people don't select the same random random number - as an example, if two people used the same random number as their Bitcoin private key, they'd be sharing a wallet (and the wallet's funds)!
While this is impossible to prevent, cryptographic schemes use astronomically large number ranges (on the order of the number of atoms in the universe!) to ensure users get unique random numbers if they use proven selection methods.
Public random numbers vs private random numbers
Random numbers are used by everybody daily: connecting to a website over HTTPS creates some random numbers, signing into our bank account may use some random numbers, creating a user account or purchasing an item online will generate a random user or receipt identifier; most of these (like the Bitcoin example above) are private random numbers. If you shared random numbers associated with your bank account publicly, a malicious actor might be able to steal all your money.
Public random numbers are a little bit different. These are numbers we want everybody to see: think lottery numbers, the roll of a dice in a board game, selecting a business to be audited at random or a coin flip for who takes the kick-off in a football match. This is exactly the type of randomness that drand provides - you definitely shouldn't generate your Bitcoin private key using drand (or if you do, please tell us so we can liberate all your Bitcoin!).
Verifiability
In the examples of public randomness we discussed above, humans have come up with a myriad of dances to ensure fairness: lottery numbers are drawn from fancy machines built by companies dedicated to fairness, dice are shared in board games to ensure that a single player isn't using a rigged die, and a trusted third party (the referee) picks the coin and flips it to decide which team takes the kick-off.
None of these solutions are really verifiable and require trusting third parties (e.g. referees, manufacturers), but we've got established procedures around them that increase our assurance that they're fair.
For generating random numbers fast and at scale however, it's a lot more difficult to prove fairness:
- if I trust a third party to generate the random number, how do I know they really chose it randomly?
- if I trust a third party to run a random number generator I have audited, how do I know they're running the code they say they are?
- if I run some code to generate a random number, how do I know the code is really statistically random (and bug free!)?
Human intuition can play tricks on us when it comes to randomness. If you were to look at the following binary numbers, which do you think is the most random?
1111111111111111
0000000000000000
1001011010001001
At first glance the first two seem far too uniform to be random, but from a random selection of values from 0000000000000000
to 1111111111111111
(inclusive), they are all equally likely to occur!
How then can we verify a randomly selected number was really randomly selected? It seems impossible. However in drand, we exploit some base cryptographic principles to make this possible. To fully understand it though, we will have to do a little background work.