SHOW:
|
|
- or go back to the newest paste.
| 1 | #!/usr/bin/python | |
| 2 | from random import random | |
| 3 | ||
| 4 | - | # btc_el33t.py |
| 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 | - | else: |
| 27 | + | |
| 28 | - | if random() < pubpool: |
| 28 | + | |
| 29 | r+=1 | |
| 30 | - | r+=1 |
| 30 | + | |
| 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 | - | r+=1 |
| 47 | + | |
| 48 | pubbtc += 1 | |
| 49 | prev-=1 | |
| 50 | r+=1 |