Created
April 1, 2018 18:56
-
-
Save pawlos/e92cbce83b367aa90ea867f894492154 to your computer and use it in GitHub Desktop.
Creating a fake Spycoin chain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
import hashlib | |
import struct | |
import itertools | |
#functions from original file | |
def verify_block(hash, block_num): | |
# Difficulty history: | |
# We increased difficulty starting from block 52, have to match "Spy". | |
# We increased difficulty starting from block 138, have to match "SpyCoinXoXo". | |
if block_num < 52: | |
return hash.startswith("Sp") | |
if block_num < 138: | |
return hash.startswith("Spy") | |
return hash.startswith("SpyCoinXoXo") | |
def block_hash(block): | |
step1 = hashlib.md5(block).digest() | |
step2 = hashlib.md5(step1).digest() | |
return step2 | |
def find_bytes(block, block_num): | |
found = None | |
#print block_hash(tr) | |
for k in range(1,10): | |
if found is not None: | |
break | |
print 'Testing ',k | |
for i in itertools.product(range(255), repeat=k): | |
b = block + (''.join(map(chr,i))) | |
h = block_hash(b) | |
if verify_block(h, block_num): | |
found = (''.join(map(chr,i)),h) | |
break | |
return found | |
#construct new spycoin block | |
current = open('current_blockchain','rb').read() | |
current = bytearray(current) | |
newone = current[0:0x64+1] | |
def add_funds(src, amount): | |
secret = struct.pack("8s","Secret20") | |
#add transffers | |
transfer = bytearray() | |
transfer.append(0x03) #type | |
transfer += src.decode('hex') #from | |
transfer += secret #to | |
transfer += struct.pack("I", amount) #amount | |
return transfer | |
tr = bytearray() | |
tr += add_funds("626973686f700000", 98830) | |
tr += add_funds("6b61790000000000", 91400) | |
tr += add_funds("627269736f747700", 142487) | |
tr += add_funds("6167656e74393900", 90210) | |
tr += add_funds("646f6e706564726f", 45032) | |
tr += add_funds("6e61746173686100", 500000-98830-91400-142487-90210-45032) | |
block_num = 1 | |
#print block_hash(tr) | |
confirm = current[0x65:0x65+0x12] | |
found = find_bytes(confirm[1:]+tr, block_num) | |
block_num += 1 | |
#print 'Found: ',found | |
tr += found[0] | |
confirm[0] = 0x11+len(tr) | |
hash = found[1] | |
newone += confirm | |
newone += tr | |
while len(newone) < len(current): | |
print 'Newone size: ',len(newone), 'Current: ', len(current) | |
filler = bytearray() | |
filler += '\xff' #size | |
filler += '\x02'+hash | |
filler += '\x00' | |
filler += '\xff'*230 | |
found = find_bytes(filler[1:], block_num) | |
filler += found[0] | |
filler[0] = len(filler)-1 | |
block_num += 1 | |
hash = found[1] | |
newone += filler | |
open('new_one','wb').write(newone) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment