Guest User

Untitled

a guest
Nov 4th, 2013
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. from random import random
  3.  
  4. # btc_el33t.py 0.2
  5. # Dan Kaminsky, [email protected]
  6.  
  7. # simple numerical sim of @el33th4xor Bitcoin attack
  8. # No conclusions should be drawn, except that it's
  9. # _really_ sensitive to whether you can always win
  10. # the race with the public pool.
  11.  
  12. # BUGFIX:  Previous version allowed both pub and priv
  13. #          to win same round
  14.  
  15. pubpool = 0.66666
  16. privpool = 0.33333
  17. chance_of_losing_race = 0
  18. prev  = 0
  19. r =0
  20. pubbtc = 0
  21. privbtc = 0
  22.  
  23. # honest
  24. if 0:
  25.   while r<10000:
  26.     print r, pubbtc, privbtc
  27.     if random() < privpool:
  28.         privbtc += 1
  29.         r+=1
  30.     if random() < pubpool:
  31.         pubbtc  += 1
  32.         r+=1
  33.  
  34. # dishonest
  35. if 1:
  36.   while r<10000:
  37.     print r, pubbtc, privbtc, prev
  38.     if random() < privpool:
  39.         prev += 1
  40.         r+=1
  41.     if random() < pubpool:
  42.         if prev==0:
  43.             pubbtc  += 1
  44.         if prev>0:
  45.             if random() > chance_of_losing_race:
  46.                 privbtc += 1
  47.             else:
  48.                 pubbtc  += 1
  49.             prev-=1
  50.         r+=1
Advertisement
Add Comment
Please, Sign In to add comment