1

According to all internet sources i have found, the hash/ID of a transaction is the result of the double_sha256 algorithm that takes all raw data of the transaction. I tried to calculate it in Python but get incorrect results in recent blocks. Here ist my test script for block #745778: https://www.blockchain.com/btc/block/745778

import hashlib def d_SHA256(hex_string): return hashlib.sha256(hashlib.sha256(bytes.fromhex(hex_string)).digest()).digest() # https://www.blockchain.com/btc/tx/aa7f5b5f200feac9364ec40b4a5c0cb5c291f846422dec373a71cf30c55ce856 coinbase_hash = 'aa7f5b5f200feac9364ec40b4a5c0cb5c291f846422dec373a71cf30c55ce856' # https://blockchain.info/rawtx/aa7f5b5f200feac9364ec40b4a5c0cb5c291f846422dec373a71cf30c55ce856?format=hex coinbase_data = '010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff640332610b2cfabe6d6ddcb8d8f2a2ddf5191d8191cfa7aa4fd9d85c529f2ce8ed4363c1a8942f14810b10000000f09f909f092f4632506f6f6c2f6500000000000000000000000000000000000000000000000000000000000000000000000500540000000000000004b1bbbb26000000001976a914c825a1ecf2a6830c4401620c3a16f1995057c2ab88ac0000000000000000266a24aa21a9edd02fc86dcb2b66db1a5add17b3660e4046f50cde03199425f0944c7becb6546a0000000000000000266a2448617468e62698d5bdd57572ff76305ed48933e8b787a67df4319ade7d798df03c706edf00000000000000002c6a4c2952534b424c4f434b3a3c622bf845a23d0ee4927d14fe0455d8e30af6e68e7e3620aa1af6270044738b01200000000000000000000000000000000000000000000000000000000000000000730b053f' tmp_coinbase_hash = d_SHA256(coinbase_data) # big-endian in bytes my_coinbase_hash = tmp_coinbase_hash[::-1].hex() # litte-endian in hex print('coinb_hash:', coinbase_hash) print('my_cb_hash:', my_coinbase_hash) 
coinb_hash: aa7f5b5f200feac9364ec40b4a5c0cb5c291f846422dec373a71cf30c55ce856 my_cb_hash: b33db7a32051e9cf9f73bcbcfb2f6f454c8baa9317738f2c8a703593dd01bf44 

I don't get what I do wrong. Did the protocol change? Because it works for older blocks but not for recent mined blocks and I can't find any information on this issue.

1 Answer 1

0

I don't get what I do wrong.

That coinbase transaction has a segwit output.

I think you need to exclude the witness data. You need a transaction-id that is compatible with the transaction-id that would be produced by non-segwit nodes. Those non-segwit nodes receive a copy of the transaction that has the segwit data edited out (to avoid freaking them out).


Probably relevant?

Definition of txid remains unchanged: the double SHA256 of the traditional serialization format:

[nVersion][txins][txouts][nLockTime] 

A new wtxid is defined: the double SHA256 of the new serialization with witness data:

[nVersion][marker][flag][txins][txouts][witness][nLockTime] 

I think you have calculated the wtxid not the txid.

1
  • Yes you are right. When i call bitcoin-cli decoderawtransaction... It shows ID and HASH of the transaction which are different: <br/>txid": "aa7f5b5f200feac9364ec40b4a5c0cb5c291f846422dec373a71cf30c55ce856", <br/>"hash": "b33db7a32051e9cf9f73bcbcfb2f6f454c8baa9317738f2c8a703593dd01bf44", Commented Jul 21, 2022 at 16:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.