Hi
i have problem (or misunderstanding with sha256 hashing of block header)
i use this code
import hashlib, struct
ver = 2
prev_block = "000000000000000117c80378b8da0e33559b5997f2ad55e2f7d18ec1975b9717"
mrkl_root = "871714dcbae6c8193a2bb9b2a69fe1c0440399f38d94b3a0f1b447275a29978a"
time_ = 0x53058b35 # 2014-02-20 04:57:25
bits = 0x19015f53
# https://en.bitcoin.it/wiki/Difficulty
exp = bits >> 24
mant = bits & 0xffffff
target_hexstr = '%064x' % (mant * (1<<(8*(exp - 3))))
target_str = target_hexstr.decode('hex')
nonce = 0
while nonce < 0x100000000:
header = ( struct.pack("<L", ver) + prev_block.decode('hex')[::-1] +
mrkl_root.decode('hex')[::-1] + struct.pack("<LLL", time_, bits, nonce))
hash = hashlib.sha256(hashlib.sha256(header).digest()).digest()
print nonce, hash[::-1].encode('hex')
if hash[::-1] < target_str:
print 'success'
break
nonce += 1
and it is here online
https://repl.it/Pkpso as you can see it works perfectly and solve that block but when i trace it line by line (when it reaches correct nonce that is 856192328 0x33087548)
first it make this block header
0200000017975b97c18ed1f7e255adf297599b55330edab87803c81701000000000000008a97295a2747b4f1a0b3948df3990344c0e19fa6b2b92b3a19c8e6badc141787358b0553535f011948750833
and then hash it with sha256 that output is
e6d91555891f9c0d0313625ff8cbfecc917063ade047c2eaf73e7a28862b127c
and then again hash
0000000000000000e067a478024addfecdc93628978aa52d91fabd4292982a50
it is solved
but when i hash the header block with some sha256 online hasher like
http://www.xorbin.com/tools/sha256-hash-calculatorthe output is
1a4ad61b28b74f4ce89b589ed862ac204019c3297b6431529d141f8b82fb56ea
and again
a071333e34ecdca0c9f7d7f7d42192ebb6cc3e3e47a4b20a02108246a5bd8e1c
and you can see it is incorrect!
what is wrong whit it?