Why is Target < Blockhash?

1

0

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.

SimonSchuler

Posted 2018-12-11T11:26:26.443

Reputation: 25

1

That's because that target is represented in compact format: https://bitcoin.org/en/developer-reference#target-nbits

JBaczuk 2018-12-11T14:46:21.030

Answers

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.

James C.

Posted 2018-12-11T11:26:26.443

Reputation: 2 183

1Nice edit @KappaDev!James C. 2018-12-12T07:10:26.937

I didn't understand the concept of the compact format. I just assumed that 0x1b was constant. Thank You.SimonSchuler 2018-12-13T11:29:11.757

1glad it worked outJames C. 2018-12-13T11:33:28.120