Skip to content

Instantly share code, notes, and snippets.

@gakonst
Last active September 8, 2022 23:57
Show Gist options
  • Save gakonst/f7756debc09a75ce6c54eb526be14e52 to your computer and use it in GitHub Desktop.
Save gakonst/f7756debc09a75ce6c54eb526be14e52 to your computer and use it in GitHub Desktop.
Probability of a malicious validator controlling majority of a 6125-size committee
import math
def choose(n, k): return math.factorial(n) // math.factorial(k) // math.factorial(n-k)
def prob(n, k, p): return math.exp(math.log(p) * k + math.log(1-p) * (n-k) + math.log(choose(n, k)))
def probge(n, k, p): return sum([prob(n, i, p) for i in range(k, n+1)])
committee = 6125
half = committee / 2
for p in [0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51]:
print(probge(committee, half, p))
@Donabbaskid
Copy link

Screenshot_2021-07-20-22-20-19-75

@Donabbaskid
Copy link

Don

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment