# Stored variables:
#
# Last known block
# 10: version
# 11: hashPrevBlock
# 12: hashMerkleRoot
# 13: time
# 14: bits
# 15: nonce
# 16: blockHash / lastKnownBlock
# 17: score
#

def shared():
    TWO_POW_24 = 2 ^ 24

def init():
    self.storage[16] = 0x00000000000000000cfdd50d917943949fa708829ab70108c98cdb9f7d62339d

def code():
    return(-1)

def storeBlockHeader(version, hashPrevBlock, hashMerkleRoot, time, bits, nonce):
    exp = bits / TWO_POW_24
    mant = bits & 0xffffff
    target = mant * slt(1, (8*(exp - 3)))

# shift left
def slt(n, x):
    return(n * 2^x)

@@ -520,16 +520,275 @@
 - 3)))%0A%0A
+def flipBytes(n):%0A    numByte = 32%0A    mask = 0xff%0A%0A    result = 0%0A    i = 0%0A    while i %3C numByte:%0A        b = n & mask%0A        b /= 2%5E(i*8)%0A        b *= 2%5E((numByte-i-1)*8)%0A        mask *= 256%0A        result = result %7C b%0A        i += 1%0A%0A    return(result)%0A%0A
 # shift 

add flipBytes