Skip to content

Commit b5a49b6

Browse files
authored
Merge branch 'main' into node16
2 parents 28f70f1 + bebaeb6 commit b5a49b6

File tree

5 files changed

+171
-69
lines changed

5 files changed

+171
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
build/
33
cache/
44
.vscode
5+
.envrc

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10.9

CONTRIBUTING.adoc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
= Keep Contribution Guide
2+
3+
🎉 Thanks for taking the time to contribute! 🎉 Contributions are welcome from
4+
anyone, and even the smallest of fixes is appreciated!
5+
6+
The following is a set of guidelines for contributing to Keep and its packages.
7+
These are mostly guidelines, not rules. Use your best judgment, and feel free to
8+
propose changes to this document in a pull request.
9+
10+
== Getting started
11+
12+
1. Fork
13+
https://github.com/keep-network/sortition-pools[`keep-network/sortition-pools`]
14+
2. Clone your fork
15+
3. Follow the
16+
link:README.md#Setup[installation & build steps] in the README.
17+
4. Set up the <<Development Tooling>>.
18+
5. Open a PR against the `main` branch and describe the change you are intending
19+
to undertake in the PR description.
20+
21+
Before marking the PR as ready for review, make sure:
22+
23+
* It passes the linter checks (`npm run lint` and `npm run lint:fix`).
24+
* It passes the https://github.com/keep-network/sortition-pools/actions[continuous
25+
integration tests].
26+
* Your changes have sufficient test coverage (e.g regression tests have
27+
been added for bug fixes, unit tests for new features).
28+
29+
== Development Tooling
30+
31+
Commits
32+
https://help.github.com/en/articles/about-commit-signature-verification[must
33+
be signed].
34+
35+
=== Continuous Integration
36+
37+
Keep uses https://github.com/keep-network/sortition-pools/actions[Github
38+
Actions] for continuous integration. All jobs must be green to merge a PR.
39+
40+
=== Pre-commit
41+
42+
Pre-commit is a tool to install hooks that check code before commits are made.
43+
It can be helpful to install this, to automatically run linter checks and avoid
44+
pushing code that will not be accepted. Follow the
45+
https://pre-commit.com/[installation instructions here], and then run
46+
`pre-commit install` to install the hooks.
47+
48+
=== Linting
49+
50+
Linters and formatters for Solidity, JavaScript, and Go code are set up and run
51+
automatically as part of pre-commit hooks. These are checked again in CI builds
52+
to ensure they have been run and are passing.
53+
54+
To run the linters and formatters manually, use the following commands:
55+
* `npm run lint` - checks files against linting rules.
56+
* `npm run lint:fix` - checks files against linting rules and fixes any
57+
issues that can be fixed automatically.
58+
59+
If you want to change a rule, or add a custom rule, to the JavaScript or
60+
Solidity linting, please propose these changes to our
61+
https://github.com/keep-network/solium-config-keep[solium-config-keep],
62+
https://github.com/keep-network/eslint-config-keep[eslint-config-keep], or
63+
https://github.com/keep-network/prettier-config-keep[prettier-config-keep]
64+
packages. All other packages have them as a dependency.

README.adoc

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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.

README.md

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)