-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoisson_distro.py
More file actions
40 lines (31 loc) · 1.13 KB
/
poisson_distro.py
File metadata and controls
40 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import math
# Nakamoto's C Poisson Distribution logic re-written in python
def attackerSuccessProbability(q, z):
p = 1.0 - q
Lambda = z * (q / p)
sum = 1.0
i, k = 0, 0
for k in range(z+1):
poisson = math.exp(-Lambda)
for i in range(1, k+1):
poisson *= (Lambda / i)
sum -= poisson * (1 - pow(q/p, z-k))
return float(sum)
def attackerSuccessProbabilityRevised(q, z):
p = 1.0 - q
Lambda = z * (q / p)
sum = 1.0
i, k = 0, 0
for k in range((z+1)+1):
poisson = math.exp(-Lambda)
for i in range(1, k+1):
poisson *= (Lambda / i)
sum -= poisson * (1 - pow(q/p, (z+1)-k))
return float(sum)
if __name__ == "__main__":
qInput = float(input("q value (attacker mining power): "))
zInput = int(input("z value (block deficit): "))
attackerSuccess = attackerSuccessProbability(qInput, zInput)
print(f"Attacker Success Probability to catch-up: {attackerSuccess:10f}")
attackerOvertake = attackerSuccessProbabilityRevised(qInput, zInput)
print(f"Attacker Success Probability to overtake: {attackerOvertake:10f}")