1

I am currently trying to validate a blocks hash against its target in python3:

This is a block in the Blockcypher testnet, and I am using this formula from the Bitcoin Wiki.

block_hash = '000055f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1'
bits = '520159231'

target = hex(int(bits) * (2**(8 * (0x1b - 3))))
hash_ = hex(int(block_hash, 16))
print(target, hash_)
>>> 0x1f00ffff000000000000000000000000000000000000000000000000 0x55f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1

if not target >= hash_:
    print('False)
else:
    print('True')
>>> False

Point is, that target is less than blockhash. But this should not be the case. Can anyone help me?

Thank You for Your time.

5

If you convert the difficulty bits to hex you will get: 0x1F00FFFF

Coefficient = 0x00FFFF

Exponent = 1F = 31

Target = Coefficient * 2**( 8 * ( exponent-3 ) )

Target = 0xFFFF with 31 - 3 = 28 trailing NULL (0x00) bytes

Target: 0x0000FFFF00000000000000000000000000000000000000000000000000000000

Your Hash: 0x000055f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1

So your POW fulfils the target. Just to be sure, you might want to check endianness during your conversions between int/literal/hex types.

  • 1
    Nice edit @KappaDev! – James C. Dec 12 '18 at 7:10
  • I didn't understand the concept of the compact format. I just assumed that 0x1b was constant. Thank You. – SimonSchuler Dec 13 '18 at 11:29
  • 1
    👍👍glad it worked out – James C. Dec 13 '18 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.