Over the past few weeks a number of our users have asked how PoolTogether selects winners. We’ve touched on the topic before in the article Inside PoolTogether v2.0, but we’ll elaborate in more detail here.

There are two main components to random winner selection:

The source of entropy: where we get the “randomness” from. The winner selection algorithm: how we use the randomness to select a user fairly.

Note: if you don’t understand some the open and committed terminology you may want to scan Inside PoolTogether v2.0 for some insight.

Source of Entropy

In PoolTogether v2.0 the pool administrators provide the random number. It’s provided like so:

The admin generates a secret random number before the prize is opened. The admin opens the prize; new deposits will be eligible to win. When opening the prize the admin also includes a fingerprint of the random number. This fingerprint uniquely identifies the number without revealing it. The admin commits the prize; locking in the deposits that will be eligible to win. The admin awards the prize: in order to award the prize the admin must “reveal” the secret random number. The smart contract ensures that the revealed random number matches the committed fingerprint. The smart contract uses the random number to select a winner.

As you may note, the random number selection is centralized. We’ve published this limitation of PoolTogether previously in PoolTogether v2.0: Audit Disclosures. We have several research areas we are pursuing to address this. The next version of PoolTogether will be much improved! Stay tuned.

Winner Selection

Let’s dig deeper into step 5 above: where the smart contract uses the random number to select a winner. How does this work?

The key property we want to hold is that a users chance to win is proportional to the size of their deposit. To accomplish this, we treat the random number as a token index.

Let’s imagine that two users have deposited a total of 1,000 tokens. Alice has deposited 800 tokens, and Bob has deposited 200 tokens. Let’s visualize the total supply of tokens as a segmented block:

Alice and Bob’s shares of 1000 tokens

Out of the total deposit of 1000 tokens Alice has 800 and Bob has 200.

The smart contract reframes these deposits: Alice has the first 800 tokens and Bob has the last 200 tokens. So in a sense, Alice owns tokens 1–800 and Bob owns the tokens 801–1000. The smart contract cleverly structures the deposits such that users own certain ranges of tokens.

Now that we’re seeing deposits as “ranges” of tokens out of the total supply, we can treat the random number like an index into the total supply.

If the random number is 513, who is the winner? Let’s see:

Token 513 is owned by Alice

Since Alice owns token 513, she is the winner!

What if the random number is 842?

Token 842 is owned by Bob

Then Bob wins!

As we can see, Alice owns 800 tokens out of the 1000, so she has an 80% chance of winning. Bob owns 200 out of the 1000, so he has a 20% chance of winning. In this way, the chance a user is selected is proportional to their deposit.

Summary

We hope this helps illuminate our algorithm for non-technical users. If you have any more questions, feel free to reach out on Discord or Telegram.

If you’d like to get your hands dirty, feel free to try our Winner Simulator. It’s a command line application that lets you simulate many winner selections against any one of our Pools.

Telegram: https://t.me/pooltogether

Twitter: @PoolTogether_

Github: pooltogether

Discord: https://discord.gg/hxPhPDW