[ad_1]
Copied below is a short python script that walks through the verification, using input values for block 505400 from the blockchain.com block explorer:
import json
import hashlib
block={}
#inputs values (from https://www.blockchain.com/explorer/blocks/btc/505400)
block['blocknumber']=505400
block['version']='20000000'
block['hashPrevBlock']='00000000000000000022a664b3ff1e4f85140eddeebd0efcbe6a543d45c4135f'
block['hashMerkleRoot']='a3defcaa713d267eacab786c4cc9c0df895d8ac02066df6c84c7aec437ae17ae'
block['time']=1516561306
block['bits']=394155916
block['nonce']=2816816696
#prepare values
block['versionprepared']=bytes.fromhex(block['version'])[::-1].hex()
block['hashPrevBlockprepared']=bytes.fromhex(block['hashPrevBlock'])[::-1].hex()
block['hashMerkleRootprepared']=bytes.fromhex(block['hashMerkleRoot'])[::-1].hex()
block['timeprepared']=int(block['time']).to_bytes(4, byteorder="little").hex()
block['bitsprepared']=int(block['bits']).to_bytes(4, byteorder="little").hex()
block['nonceprepared']=int(block['nonce']).to_bytes(4, byteorder="little").hex()
#concatentate prepared values to create input to double sha256 hash function
block['hashinput']=block['versionprepared'] + block['hashPrevBlockprepared'] + block['hashMerkleRootprepared'] + block['timeprepared'] + block['bitsprepared'] + block['nonceprepared']
#double sha256 hash
block['hashoutcomputed']=(hashlib.sha256(hashlib.sha256(bytes.fromhex(block['hashinput'])).digest()).digest())[::-1].hex()
#print results
print(json.dumps(block, indent=4))
The double sha256 hash computed is:
00000000000000000023b89dd18f6be5a6c03a71cd864ccbdf024683114b9ce3
As expected, this result has 18 leading zeroes (as required to meet the difficulty requirement for this block), and matches the hash for block 505400 according to the block explorer.
[ad_2]
Source link