|
| 1 | +:toc: macro |
| 2 | + |
| 3 | += Sortition Pools |
| 4 | + |
| 5 | +https://github.com/keep-network/sortition-pools/actions/workflows/solidity-test.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/sortition-pools/solidity-test.yml?branch=main&event=schedule&label=Solidity%20tests[GitHub Workflow Status]] |
| 6 | + |
| 7 | +Sortition pool is a logarithmic data structure used to store the pool of |
| 8 | +eligible operators weighted by their stakes. In the |
| 9 | +https://threshold.org/[Threshold Network] the stake consists of staked T tokens. |
| 10 | +It allows to select a group of operators based on the provided pseudo-random |
| 11 | +seed. |
| 12 | + |
| 13 | +Each privileged application has its own sortition pool and is responsible for |
| 14 | +maintaining operator weights up-to-date. |
| 15 | + |
| 16 | +== Setup |
| 17 | + |
| 18 | +=== Prerequisites |
| 19 | + |
| 20 | +* clone the repository |
| 21 | +* https://nodejs.org/en/[Node.js] v14.21.2 |
| 22 | +* configure git to use https |
| 23 | + |
| 24 | +[source,sh] |
| 25 | +---- |
| 26 | +git config --global url."https://".insteadOf git:// |
| 27 | +---- |
| 28 | + |
| 29 | +* Python 3.11.1 for `node-gyp`. It is |
| 30 | + https://opensource.com/article/19/5/python-3-default-mac[suggested] to use |
| 31 | + `pyenv` to manage multiple Python versions. |
| 32 | + |
| 33 | +[source,sh] |
| 34 | +---- |
| 35 | +brew install pyenv |
| 36 | +pyenv install 3.11.1 |
| 37 | +---- |
| 38 | + |
| 39 | +=== Build And Test |
| 40 | + |
| 41 | +[source,sh] |
| 42 | +---- |
| 43 | +npm ci |
| 44 | +npm test |
| 45 | +---- |
| 46 | + |
| 47 | +== In-Depth Reading |
| 48 | + |
| 49 | +To familiarize yourself with the sortition pool and it's design, we provide |
| 50 | + |
| 51 | +* link:docs/building-intuition.md[Building Intuition] |
| 52 | +* link:docs/implementation-details.md[Implementation Details] |
| 53 | +* link:docs/rewards.md[Rewards] |
| 54 | + |
| 55 | +link:docs/building-intuition.md[Building Intuition] starts the reader from the |
| 56 | +problem description and an easy-to-understand naive solution, and then works its |
| 57 | +way up to the current design of the sortition pool through a series of |
| 58 | +optimizations. |
| 59 | + |
| 60 | +link:docs/implementation-details.md[Implementation Details] builds off of the |
| 61 | +knowledge in link:docs/building-intuition.md[Building Intuition], and gets into |
| 62 | +the finer points about the data structure, data (de)serialization, how operators |
| 63 | +join/leave the pool, and how it all comes together to select a full group. |
| 64 | + |
| 65 | +link:docs/rewards.md[Rewards] is a deep-dive into how the sortition pool keeps |
| 66 | +track of rewards. It features code explanations and walk-throughs of state |
| 67 | +transitions for common situations. |
| 68 | + |
| 69 | +== Important Facts |
| 70 | + |
| 71 | +* The max number of operators is `2,097,152` |
| 72 | +* The sortition pool is for general purpose group selection. Feel free to use |
| 73 | + or fork it! |
| 74 | +* The sortition pool can be <<optimisic-group-selection,optimistic>>! The |
| 75 | + on-chain code then is only run in the case that the selection submission is |
| 76 | + challenged. |
| 77 | +* The sortition pool tracks rewards! |
| 78 | + |
| 79 | +== Safe Use |
| 80 | + |
| 81 | +Miners and other actors that can predict the selection seed (due to frontrunning |
| 82 | +the beacon or a public cached seed being used) may be able to manipulate |
| 83 | +selection outcomes to some degree by selectively updating the pool. |
| 84 | + |
| 85 | +To mitigate this, applications using sortition pool should lock sortition pool |
| 86 | +state before seed used for the new selection is known and should unlock the pool |
| 87 | +once the selection process is over, keeping in mind potential timeouts and |
| 88 | +result challenges. |
| 89 | + |
| 90 | +[[optimistic-group-selection]] |
| 91 | +== Optimistic Group Selection |
| 92 | + |
| 93 | +When an application (like the |
| 94 | +https://github.com/keep-network/keep-core/tree/main/solidity/random-beacon#group-creation[Random |
| 95 | +Beacon]) needs a new group, sortition is performed off-chain according to the |
| 96 | +same algorithm that would be performed on-chain, and the results are submitted |
| 97 | +on-chain. |
| 98 | + |
| 99 | +Then, we enter a challenge period where anyone can claim that the submitted |
| 100 | +results are inaccurate. If this happens, the on-chain sortition pool runs the |
| 101 | +same group selection with the same seed and validates the results. |
| 102 | + |
| 103 | +If the submission was invalid, the challenger is rewarded and the submitter is |
| 104 | +punished, and we can accept another submission. If the submission was valid, the |
| 105 | +challenger loses out on their gas, and the submitter is unaffected. |
0 commit comments