One of these is an LTC transaction hash and the other is an LTC block hash, do you know which is which?
d10853446ae391085f224885bd568ad717d663212d263d3b6b1e71229e818c5f
e2e10f43f0a2773accf2c4fb73c19fea5bd6ba8a90a19c7e5b7c5145e1b5550f
In BTC, block-hashes start with a bunch of 0s and thus are easily distinguishable*. I thought that this was just a display issue with LTC and that LTC block hashes could be easily converted to big-endian value. Then I read the code and was disappointed to find that you cannot take a conventionally used LTC block hash and calculate the scrypt hash to display in big-endian notation (the one with a lot of leading 0s) without also having the Version, hashPrevBlock, hashMerkleRoot, Time, Bits, Nonce.
Here’s what the code looks like in python2 (HT the LTC wiki page) for the 100,000th block:
>>> import hashlib
>>> header_hex = ("01000000" + "ae178934851bfa0e83ccb6a3fc4bfddff3641e104b6c4680c31509074e699be2" + "bd672d8d2199ef37a59678f92443083e3b85edef8b45c71759371f823bab59a9" + "7126614f" + "44d5001d" + "45920180")
>>> header_bin = header_hex.decode('hex')
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
>>> hash.encode('hex_codec')
'60ce4639bf63532b27e8f8b036b9846f5d2ae18556289f80e38b85a5df4910e1'
>>> hash[::-1].encode('hex_codec')
'e11049dfa5858be3809f285685e12a5d6f84b936b0f8e8272b5363bf3946ce60'
>>> import scrypt
>>> pow_hash = scrypt.hash(header_bin, header_bin, 1024, 1, 1, 32)
>>> pow_hash[::-1].encode('hex_codec')
'000000003b4ba52ab765631e20a04b88cd27f0b66d3509fb2da7781fae6d7901'
I’ve translated that to python3 for those of you using the latest and greatest:
>>> import hashlib
>>> from binascii import unhexlify, hexlify
>>> header_hex = ("01000000" + "ae178934851bfa0e83ccb6a3fc4bfddff3641e104b6c4680c31509074e699be2" + "bd672d8d2199ef37a59678f92443083e3b85edef8b45c71759371f823bab59a9" + "7126614f" + "44d5001d" + "45920180")
>>> header_bin = unhexlify(header_hex)
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
>>> hash = hexlify(hash)
>>> hash
b'60ce4639bf63532b27e8f8b036b9846f5d2ae18556289f80e38b85a5df4910e1'
>>> hexlify(unhexlify(hash)[::-1])
b'e11049dfa5858be3809f285685e12a5d6f84b936b0f8e8272b5363bf3946ce60'
>>> import scrypt
>>> pow_hash = scrypt.hash(header_bin, header_bin, 1024, 1, 1, 32)
>>> hexlify(pow_hash[::-1])
b'000000003b4ba52ab765631e20a04b88cd27f0b66d3509fb2da7781fae6d7901'
Why does this matter? If I look at this BTC value (000000000017ea289e5b5addd09f0df37f3daffefbb3d9483fae4fa88ff0fd29
), I know it’s a block hash. I don’t have to look it up in two separate databases to see if it’s a transaction or a block hash. When dealing with money, less confusion is always a good thing. Bad implementation choice, litecoin!
*It is possible (though extremely rare) for a transaction to start with a bunch of 0s.