Pages:
Author

Topic: How is the transaction hash determined? - page 2. (Read 3315 times)

copper member
Activity: 1498
Merit: 1528
No I dont escrow anymore.
April 30, 2015, 04:20:08 AM
#5
Understand a bit. So.. can I say that no one can predict what the hash is going to be?

Not predict, but a certain hash might be forced similar to how mining is brute forcing a certain hash.

-> https://bitcointalksearch.org/topic/what-the-average-user-needs-to-know-about-transaction-mutability-460944
hero member
Activity: 518
Merit: 501
Error 404: there seems to be nothing here.
April 30, 2015, 04:15:33 AM
#4
Understand a bit. So.. can I say that no one can predict what the hash is going to be?

Noone can! There are many bitcoin casino whose bet results depend upon the transaction hash! If they could be predicted, those casinos would loose a lot of Bitcoins Smiley
legendary
Activity: 1484
Merit: 1001
Personal Text Space Not For Sale
April 30, 2015, 04:10:16 AM
#3
Understand a bit. So.. can I say that no one can predict what the hash is going to be?
hero member
Activity: 672
Merit: 508
LOTEO
April 29, 2015, 05:17:10 AM
#2
I would like to know how transaction hash is determined.

For example, https://blockchain.info/tx/278090c755aa016483ab3a9e6bffe1d2dfbf5b53edb7099b9946bc9dfe59f217. How does the network generate the underlined text? I searched Google but there is no answer - there was one in 2012. The explanation is way too complicated for me to understand.

I'm doing this on top of my head with a little help from the web, so may have some mistake, but these are the steps:

1. Transactions are encoded as (some data bytes):
- a 32 bit 'nVersion'
- a list of input transactions, vin
- a list of output transactions, vout
- a 32 bit 'nLockTime'

2. string all those together end to end  (some data bytes as a string or block of text)
3. Taking the sha256 hash of this
4. Taking the sha256 hash of this (again)

You can combine step 3 and 4, sha256(sha256(input)).  You do not have to know all the details of sha256 but you should learn the principles of hashing. Smiley

Then you have the transaction hash. Bitcoin uses the endian encoding, bytewise reversed.
Example with Genesis block:

Step 1)
Code:
   nVersion: 01000000
    inputs
        count: 01
        1st input:
            prevout_hash: 0000000000000000000000000000000000000000000000000000000000000000
            prevout_n: ffffffff
            scriptSig: 4d:04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73
            sequence: ffffffff
    outputs
        count: 01
        1st output:
            value: 00f2052a01000000 (hex(50*10^8) is 0000012a05f200, and bitcoin puts the bytes in reverse order)
            scriptPubKey: 43:4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac
    nLockTime: 00000000

Step 2)
Code:
01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000

Step 3+4) (double sha256)
Code:
4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b

Have a look at pybitcoin tools https://github.com/vbuterin/pybitcointools, you can easily create transaction hashes with that.


legendary
Activity: 1484
Merit: 1001
Personal Text Space Not For Sale
April 29, 2015, 04:11:21 AM
#1
I would like to know how transaction hash is determined.

For example, https://blockchain.info/tx/278090c755aa016483ab3a9e6bffe1d2dfbf5b53edb7099b9946bc9dfe59f217. How does the network generate the underlined text? I searched Google but there is no answer - there was one in 2012. The explanation is way too complicated for me to understand.
Pages:
Jump to: