Skip to content

Instantly share code, notes, and snippets.

@veox
Last active March 21, 2017 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veox/f6d6bd971ae75c659d1b164f386eb7c4 to your computer and use it in GitHub Desktop.
Save veox/f6d6bd971ae75c659d1b164f386eb7c4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import matplotlib.pyplot as plot
# time "steps", e.g. months
n = 50
# hashing power pre-attack: using "honest miners" as base unit
x0 = 0
y0 = 1
# part of honest mining power that the attacker "buys into"
P = [0.01, 0.02, 0.05, 0.1]
# rate of increase (1 == no change)
h = 1.05
R = [h * r for r in [1.05, 1.1, 1.25]]
def expgen(start, rate):
current = start
while True:
(yield current)
current = current * rate
return
ygen = expgen(y0, h)
ygen.send(None)
Y = [y0, *[ygen.send(None) for _ in range(n)]]
for p in P:
x1 = y0*p
for i, r in enumerate(R):
xgen = expgen(x1, r)
xgen.send(None)
X = [0, x1, *[xgen.send(None) for _ in range(n-1)]]
l = 'X, ' + 'r == ' + str(round(r, 3)) + ', p == ' + str(p) + ', a == ' + str(round(r/h, 3))
plot.plot(X, marker = str(i+1), markersize = 10, label = l)
# PLOT
plot.plot(Y, marker = 'o', label = 'Y, ' + 'h == ' + str(h))
plot.xlabel('n (time period)')
plot.ylabel('Xn and Yn (hashing power)')
plot.ylim((0, 15))
plot.legend()
plot.grid()
plot.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment