0
Transaction #59500 has 045c670f1c02c919 as its coinbase. Transaction 1 is 6653ad77d695752cff9fe63bbb5702a53807be534c537251d53de06aac5ca093. Transaction 2 is 72e8781092c01e9eb1c21ba33d52ad6abc42f3807601bcd8b8074d583446346e.
Double SHA256 of Coinbase
import hashlib
header_hex = ("045c670f1c02c919")
header_bin = header_hex.decode('hex')
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
hash.encode('hex_codec')
'6eafdb5c504ed7e70536d70c666503f4435205f367f21d2960ff2262ca2acf0b'
hash[::-1].encode('hex_codec')
'0bcf2aca6222ff60291df267f3055243f40365660cd73605e7d74e505cdbaf6e'
Double SHA256 of Transaction 1
header_hex = ("6653ad77d695752cff9fe63bbb5702a53807be534c537251d53de06aac5ca093")
header_bin = header_hex.decode('hex')
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
hash.encode('hex_codec')
'b2e28ac8528477c0c3c7978ee29479ae9ca1aed9cb2e58e6b910f17142f6c53d'
hash[::-1].encode('hex_codec')
'3dc5f64271f110b9e6582ecbd9aea19cae7994e28e97c7c3c0778452c88ae2b2'
Would I then combine the double hash of the coinbase with the double hash of transaction 1? Like so:
("0bcf2aca6222ff60291df267f3055243f40365660cd73605e7d74e505cdbaf6e" + "3dc5f64271f110b9e6582ecbd9aea19cae7994e28e97c7c3c0778452c88ae2b2) and then double hash that?
The double hash of the coinbase and transaction 1 is d77fefa4fd82afdf1780f84dae5dc30be2f3b53bc8db2c40db6d17687324dc48
Double SHA256 of Transaction 2
header_hex = ("72e8781092c01e9eb1c21ba33d52ad6abc42f3807601bcd8b8074d583446346e")
header_bin = header_hex.decode('hex')
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
hash.encode('hex_codec')
'c9f7032f5df64761e74ad4bc7cb653db8c78aed331926382ca37ec3b8d8625a9'
hash[::-1].encode('hex_codec')
'a925868d3bec37ca82639231d3ae788cdb53b67cbcd44ae76147f65d2f03f7c9'
Would I then hash a925868d3bec37ca82639231d3ae788cdb53b67cbcd44ae76147f65d2f03f7c9 with itself?
header_hex = ("a925868d3bec37ca82639231d3ae788cdb53b67cbcd44ae76147f65d2f03f7c9" + "a925868d3bec37ca82639231d3ae788cdb53b67cbcd44ae76147f65d2f03f7c9")
header_bin = header_hex.decode('hex')
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
hash.encode('hex_codec')
'4075e4ac60dd8a52ed3eb69520ad71d660c8c2bcbf4073c87fd633a276cb2921'
hash[::-1].encode('hex_codec')
'2129cb76a233d67fc87340bfbcc2c860d671ad2095b63eed528add60ace47540'
Lastly when I try to combine that hash of the coinbase and transaction 1 with the hash of transaction 2 with itself...
''d77fefa4fd82afdf1780f84dae5dc30be2f3b53bc8db2c40db6d17687324dc48' + ''2129cb76a233d67fc87340bfbcc2c860d671ad2095b63eed528add60ace47540"
I got this 012853eb35789c270fc72dc11b4b9e24710f6f02793344860bdcad7f25e771e1 when the merkle root is :
ff682ef66cd1b56213fd4db9462fb138f6d8c16d706d41969a7eacc819528038
What did I do wrong?
You can get the hexstring for the transaction by using a block explorer with their raw tx API. For example, using blockcypher, you can get the raw coinbase transaction with the link https://api.blockcypher.com/v1/btc/main/txs/72e8781092c01e9eb1c21ba33d52ad6abc42f3807601bcd8b8074d583446346e?limit=50&includeHex=true. The
– Andrew Chow – 2018-07-07T06:26:21.680hexfield is the raw transaciton. However, you don't need this because you have the txid of the coinbase from the block explorer, so you can just use that.Thank you Andrew! So if I was given the transaction ID of 72e8781092c01e9eb1c21ba33d52ad6abc42f3807601bcd8b8074d583446346e. How would I go about byteswapping this? When you say byte string is that the same as binary? – Ben Stolman – 2018-07-07T06:46:31.913
Yes, a bytestring is the same as binary. Byteswapping a hex string means that ever two characters (representing one byte) is swapped with the two characters in the same position at the end of the string. So byteswapping that txid gives you
6e344634584d07b8d8bc017680f342bc6aad523da31bc2b19e1ec0921078e872– Andrew Chow – 2018-07-07T07:35:56.587I'm sorry I keep asking questions I just want to get this right. How would I derive the coinbase transaction from the raw data under hex? If transaction 1 is the coinbase transaction I would byteswap that which would give me 93a05cac6ae03dd55172534c53be0738a50257bb3be69fff3c7595d677ad5366. Transaction 2 is the one that you byteswapped which is 6e344634584d07b8d8bc017680f342bc6aad523da31bc2b19e1ec0921078e872. So then do I just combine them 93a05cac6ae03dd55172534c53be0738a50257bb3be69fff3c7595d677ad53666e344634584d07b8d8bc017680f342bc6aad523da31bc2b19e1ec0921078e872 and double hash them? – Ben Stolman – 2018-07-07T19:07:02.400
Yes, that is correct. – Andrew Chow – 2018-07-07T19:28:02.827
I think I'm somehow concatenating them incorrectly in the terminal. I was trying with a different one. "13a3595f2610c8e4d727130daade66c772fdec4bd2463d773fd0f85c20ced32d" "f6ae335dc2d2aecb6a255ebd03caaf6820e6c0534531051066810080e0d822c8" gives "59545fd8dfdd821ca7accecab0655d77437f5bba5aaa5ea8c042a26bc9ae514b". I get this... 'e4dc2114f6e4b087b4683555ae764e99e3f623e1ed44e1213ba34b96a2fb9cb5' – Ben Stolman – 2018-07-08T00:58:43.040
Actually, you have mistranscribed something. The full thing concatenated that you should be hashing is
93a05cac6ae03dd55172534c53be0738a50257bb3be69fff2c7595d677ad53666e344634584d07b8d8bc017680f342bc6aad523da31bc2b19e1ec0921078e872which has one character different from what you are hashing. The resulting hash will be the byteswapped version of what block explorers tell you is the merkle root. – Andrew Chow – 2018-07-08T02:07:25.933Andrew thank you so much I was banging my head against the table. – Ben Stolman – 2018-07-08T02:16:43.357