Author

Topic: Unable to find the correct transaction hash (Read 384 times)

newbie
Activity: 12
Merit: 0
November 23, 2018, 03:55:19 AM
#5
it was cool!
thank you very much!
staff
Activity: 3458
Merit: 6793
Just writing some code
November 21, 2018, 09:55:06 AM
#4
you did not quite understand my question
This transaction has 237 bytes. (along with SegWit data)
double sha256 does not give the same result as on the blockchain.info.
But what needs to be done in such a transaction instead of double sha256 ?

Thanks.

PS
your link, unfortunately, there is no described algorithm how to get a hash
You did not quite understand my answer.

A transaction is a binary format where each byte has a meaning. If you break up the bytes into the fields that they represent, and then remove the byte for the segwit data, concatenate the remaining bytes, and hash that, you will get the transaciton id. This is specified in what I linked; it tells you what fields need to be concatenated and hashed to get the txid.

So with the transaction you provided, it can be broken down as follows:
Code:
01000000 - nVersion
00 - Segwit marker
01 - Segwit flag
01 - Number of inputs
0000000000000000000000000000000000000000000000000000000000000000 - coinbase prevtx (must be all 0's)
ffffffff - coinbase prev index (must be all f's)
45 - length of coinbase script
03b5c207fabe6d6de2bf72f174e206a0b32192a50518322f7c58fd1cc2c2f5ebc60a5ca93e7a12450100000000000000626508006c639309c00100bb91182f736c7573682f - Script
00000000 - nSequence
02 - Number of outputs
8180fb5000000000 - Output value in satoshis
19 - Length of output script
76a9147c154ed1dc59609e3d26abb2df2ea3d587cd8c4188ac - Output script
0000000000000000 - Output value in satoshis
26 - Length of output script
6a24aa21a9ed470198ecd62086bfb66b96ccf86004de9e00899b00de495fff200cbb17ba55c0 - Output script
01 - Number of witness stack items
20 - Length of item on witness stack
0000000000000000000000000000000000000000000000000000000000000000 - coinbase witness stack item (must be all 0's for coinbase)
00000000 - nLocktime

So if you remove the segwit stuff, you get:
Code:
01000000 - nVersion
01 - Number of inputs
0000000000000000000000000000000000000000000000000000000000000000 - coinbase prevtx (must be all 0's)
ffffffff - coinbase prev index (must be all f's)
45 - length of coinbase script
03b5c207fabe6d6de2bf72f174e206a0b32192a50518322f7c58fd1cc2c2f5ebc60a5ca93e7a12450100000000000000626508006c639309c00100bb91182f736c7573682f - Script
00000000 - nSequence
02 - Number of outputs
8180fb5000000000 - Output value in satoshis
19 - Length of output script
76a9147c154ed1dc59609e3d26abb2df2ea3d587cd8c4188ac - Output script
0000000000000000 - Output value in satoshis
26 - Length of output script
6a24aa21a9ed470198ecd62086bfb66b96ccf86004de9e00899b00de495fff200cbb17ba55c0 - Output script
00000000 - nLocktime

Recombining the bytes results in
Code:
01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4503b5c207fabe6d6de2bf72f174e206a0b32192a50518322f7c58fd1cc2c2f5ebc60a5ca93e7a12450100000000000000626508006c639309c00100bb91182f736c7573682f00000000028180fb50000000001976a9147c154ed1dc59609e3d26abb2df2ea3d587cd8c4188ac0000000000000000266a24aa21a9ed470198ecd62086bfb66b96ccf86004de9e00899b00de495fff200cbb17ba55c000000000

When that is hashed, the result is 2e5bdebe7d5a3bda6f173875cae1ffff2d5a6e84257cd9f5cf99f7f31e7741bb which then must be byteswapped because txids are displayed in reverse byte order. So byteswapping this results in a txid of bb41771ef3f799cff5d97c25846e5a2dffffe1ca7538176fda3b5a7dbede5b2e.
newbie
Activity: 12
Merit: 0
November 21, 2018, 06:41:08 AM
#3
you did not quite understand my question
This transaction has 237 bytes. (along with SegWit data)
double sha256 does not give the same result as on the blockchain.info.
But what needs to be done in such a transaction instead of double sha256 ?

Thanks.

PS
your link, unfortunately, there is no described algorithm how to get a hash
staff
Activity: 3458
Merit: 6793
Just writing some code
November 20, 2018, 11:00:41 AM
#2
This transaction is a segwit transaction (all coinbase transactions for blocks containing segwit transactions must also be segwit transactions). So you need to compute the txid as defined in BIP 144.
newbie
Activity: 12
Merit: 0
November 20, 2018, 05:42:58 AM
#1

In the first (coinbase) transaction is 237 bytes.

010000000001010000000000000000000000000000000000000000000000000000000000000000f fffffff4503b5c207fabe6d6de2bf72f174e206a0b32192a50518322f7c58fd1cc2c2f5ebc60a5c a93e7a12450100000000000000626508006c639309c00100bb91182f736c7573682f00000000028 180fb50000000001976a9147c154ed1dc59609e3d26abb2df2ea3d587cd8c4188ac000000000000 0000266a24aa21a9ed470198ecd62086bfb66b96ccf86004de9e00899b00de495fff200cbb17ba5 5c00120000000000000000000000000000000000000000000000000000000000000000000000000

I take sha256 twice from them and get value = 1435ca9c4fd25c012aaff0ed9a608383b5a65ff736ca718a3aec24a55b8d86c1

But in https://www.blockchain.com/en/btc/tx/bb41771ef3f799cff5d97c25846e5a2dffffe1ca7538176fda3b5a7dbede5b2e

i see other value = bb41771ef3f799cff5d97c25846e5a2dffffe1ca7538176fda3b5a7dbede5b2e


At the same time, for all other transactions of this block, hashes are calculated correctly.

What could be the error in my calculation of the hash of this first transaction?
Jump to: