Added slasher v2 sim

This commit is contained in:
Vitalik Buterin 2014-10-29 07:16:25 -04:00
parent e5163616d1
commit b767b94fbe
1 changed files with 23 additions and 0 deletions

23
slasher_v2_sim.py Normal file
View File

@ -0,0 +1,23 @@
NUMSIGNERS = 15
ATTACKER_SHARE = 0.495
CHANCE_OF_SUCCESS = 0.049
SCORE_DIFFERENTIAL = 10
ATTACKER_VOTE = 0.95
import random
def sim():
d = -SCORE_DIFFERENTIAL * 15
while d < 0 and d > -(SCORE_DIFFERENTIAL * 15)-1000:
if random.random() < ATTACKER_SHARE:
for i in range(NUMSIGNERS):
if random.random() < ATTACKER_SHARE:
d += ATTACKER_VOTE
else:
d += min(CHANCE_OF_SUCCESS, 0.95)
else:
for i in range(NUMSIGNERS):
if random.random() < ATTACKER_SHARE:
pass
else:
d -= min(1 - CHANCE_OF_SUCCESS, 0.95)
return 1 if d >= 0 else 0