Bitcoin Forum
April 23, 2024, 12:23:20 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Unable to find the correct transaction hash  (Read 367 times)
jaruvido (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
November 20, 2018, 10: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?
1713875000
Hero Member
*
Offline Offline

Posts: 1713875000

View Profile Personal Message (Offline)

Ignore
1713875000
Reply with quote  #2

1713875000
Report to moderator
Even if you use Bitcoin through Tor, the way transactions are handled by the network makes anonymity difficult to achieve. Do not expect your transactions to be anonymous unless you really know what you're doing.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713875000
Hero Member
*
Offline Offline

Posts: 1713875000

View Profile Personal Message (Offline)

Ignore
1713875000
Reply with quote  #2

1713875000
Report to moderator
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3374
Merit: 6531


Just writing some code


View Profile WWW
November 20, 2018, 04:00:41 PM
Merited by bob123 (1)
 #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.

jaruvido (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
November 21, 2018, 11: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
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3374
Merit: 6531


Just writing some code


View Profile WWW
November 21, 2018, 02:55:06 PM
Merited by o_e_l_e_o (2), arulbero (2), ABCbits (1), AdolfinWolf (1), bones261 (1), bob123 (1)
 #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.

jaruvido (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
November 23, 2018, 08:55:19 AM
 #5

it was cool!
thank you very much!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!