Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- # score1 is the number of blocks mined by the attacker
- # score2 is the amount of blocks mined by the network
- # p is the probability of mining (set to 1 here)
- # compute_power is the computation power of the attacker
- # confirmation_level is amount of blocks needed for a transaction to be considered confirmed
- # let_go is when the attacker give up
- def test2(p, compute_power, confirmation_level, let_go):
- score1 = score2 = 0
- while True:
- if random.random() <= compute_power:
- # Just for clarity
- if random.random() <= p:
- score1 += 1
- else:
- # Just for clarity
- if random.random() <= p:
- score2 += 1
- if (score1 >= score2) and (score2 >= confirmation_level):
- return True, score1, score2
- if score2 >= score1 + let_go:
- return False, score1, score2
- def metatest(amount = 100):
- counter = 0
- for i in xrange(amount):
- if test2(1, 0.3, 6, 90)[0]:
- counter += 1
- return counter/float(amount) # , counter
- # OUTPUT:
- # >>> metatest()
- # 0.15
- # >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement