Bitcoin Forum
May 14, 2024, 12:52:34 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Genesis hash again  (Read 351 times)
Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
March 13, 2018, 02:12:06 PM
 #1

We know:

Code:
phrase = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";

nonce = 2083236893;

time = 1231006505;

pubkey = 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f;

What we need to do with it, to get:


Code:
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

Huh

Thank you!
1715647954
Hero Member
*
Offline Offline

Posts: 1715647954

View Profile Personal Message (Offline)

Ignore
1715647954
Reply with quote  #2

1715647954
Report to moderator
In order to get the maximum amount of activity points possible, you just need to post once per day on average. Skipping days is OK as long as you maintain the average.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715647954
Hero Member
*
Offline Offline

Posts: 1715647954

View Profile Personal Message (Offline)

Ignore
1715647954
Reply with quote  #2

1715647954
Report to moderator
1715647954
Hero Member
*
Offline Offline

Posts: 1715647954

View Profile Personal Message (Offline)

Ignore
1715647954
Reply with quote  #2

1715647954
Report to moderator
1715647954
Hero Member
*
Offline Offline

Posts: 1715647954

View Profile Personal Message (Offline)

Ignore
1715647954
Reply with quote  #2

1715647954
Report to moderator
Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
March 13, 2018, 02:17:09 PM
 #2

...and how to get this:

Code:
merklehash = 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b;

?

I want to understand please  Smiley
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6637


Just writing some code


View Profile WWW
March 13, 2018, 02:58:05 PM
Merited by ABCbits (4)
 #3

Just knowing those 5 things is not enough to construct the block header. Furthermore, knowing the merkle root means that there is no need to know the phrase or the pubkey; those are part of the coinbase transaction which is part of the merkle root.

In addition to the nonce, time, and merkle root, you also need the nBits, the block version number, and the previous block hash. For the genesis block, it is version one, nbits of 0x1d00ffff, and previous block hash of 0000000000000000000000000000000000000000000000000000000000000000. Following the format for the block header, you get a block header of 0100000000000000000000000000000000000000000000000000000000000000000000003ba3edf d7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b 7c. This is then hashed with SHA256d to get 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 which is the block hash. It is interpreted as a little endian 256 bit integer, and displayed as a big endian 256 bit integer so you get 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f. Note that the hash is always in little endian byte ordering when used in other block headers.

Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
March 13, 2018, 06:49:56 PM
 #4

Following the format for the block header, you get a block header of 0100000000000000000000000000000000000000000000000000000000000000000000003ba3edf d7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b 7c. This is then hashed with SHA256d to get 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 which is the block hash.

Yes, now I know to get block header Smiley

But if I try to get sha256 hash of

Code:
0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c

I get a

Code:
67991e515cf93949369ff472bba7fd07686e8587dc877149e5a25019609285fb

in first round and

Code:
60616d82edc531210fefdc05fe24d7bcbac31a72d3f3e5e44efbb59a318dc0d1

in second round.

I try on PHP function hash() and with online-converter for ex http://www.xorbin.com/tools/sha256-hash-calculator

What is wrong?
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
March 13, 2018, 08:08:37 PM
Merited by ABCbits (2)
 #5

What is wrong?

You are confusing hex data with ascii data.

The hexadecimal value 0x0E is a single byte number.  It can also be represented in binary as 0b00001110, or in octal as 0o16 in decimal as 14. This is how the block header data is represented and how it is handled when hashing.

The string of characters '0' 'x' '0' and 'E' ("0x0E") is represented as 4 bytes of ascii encoded data. Representing those 4 bytes in hexadecimal you get:
0x30783045
This is how your "online-converter" is representing data and how it is handling it when hashing.

If you calculate the SHA256 hash of the single data byte 0x0E you will NOT get the same result as if you calculate the SHA256 hash of the 4 bytes of data 0x30783045 (The ASCII representation of "0x0E").

When you enter 0x0E into your "online-converter" it assumes you are typing a sentence such as "The quick brown fox jumps over the lazy dog", so it converts each character to a byte of data based on its ASCII representation, then it calculates the SHA256 hash of that data.

When bitcoin calculates the hash of the header data it just hashes the raw bytes of data. It doesn't convert that data into a hex representation, then then that hex representation into a string, and then that string back into new hex data using ASCII encoding (which is what you are doing when you enter the string of characters into the "online-converter"). Therefore, it doesn't get the same has value that you are getting.

Perhaps try this online calculator using the "enter as hex" functionality:
http://extranet.cryptomathic.com/hashcalc/index

NOTE:  EVEN USING THE CORRECT TYPE OF DATA REPRESENTATION (hex data, ascii data, etc) IT IS STILL IMPORTANT THAT YOU GET THE ENDIANESS CORRECT.  IF YOU FAIL TO DO THAT, THEN YOU STILL WONT GET THE CORRECT VALUE.
Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
March 13, 2018, 09:16:02 PM
 #6

What is wrong?

You are confusing hex data with ascii data.

The hexadecimal value 0x0E is a single byte number.  It can also be represented in binary as 0b00001110, or in octal as 0o16 in decimal as 14. This is how the block header data is represented and how it is handled when hashing.

The string of characters '0' 'x' '0' and 'E' ("0x0E") is represented as 4 bytes of ascii encoded data. Representing those 4 bytes in hexadecimal you get:
0x30783045
This is how your "online-converter" is representing data and how it is handling it when hashing.

If you calculate the SHA256 hash of the single data byte 0x0E you will NOT get the same result as if you calculate the SHA256 hash of the 4 bytes of data 0x30783045 (The ASCII representation of "0x0E").

When you enter 0x0E into your "online-converter" it assumes you are typing a sentence such as "The quick brown fox jumps over the lazy dog", so it converts each character to a byte of data based on its ASCII representation, then it calculates the SHA256 hash of that data.

When bitcoin calculates the hash of the header data it just hashes the raw bytes of data. It doesn't convert that data into a hex representation, then then that hex representation into a string, and then that string back into new hex data using ASCII encoding (which is what you are doing when you enter the string of characters into the "online-converter"). Therefore, it doesn't get the same has value that you are getting.

Perhaps try this online calculator using the "enter as hex" functionality:
http://extranet.cryptomathic.com/hashcalc/index

NOTE:  EVEN USING THE CORRECT TYPE OF DATA REPRESENTATION (hex data, ascii data, etc) IT IS STILL IMPORTANT THAT YOU GET THE ENDIANESS CORRECT.  IF YOU FAIL TO DO THAT, THEN YOU STILL WONT GET THE CORRECT VALUE.


DannyHamilton, that is great! And http://extranet.cryptomathic.com/hashcalc/index is working! Thank you!

The question about genesis-hash is cleared.

achow101, thank you!

But I have two another questions:

1. How can I get a Merkle root hash?

2. Why is it necessary to generate a "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"? :-) We are create a genesis-hash without to use it Smiley
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6637


Just writing some code


View Profile WWW
March 13, 2018, 09:50:39 PM
Merited by ABCbits (2)
 #7

1. How can I get a Merkle root hash?
By constructing the coinbase transaction of the genesis block and hashing it. Because the genesis block only contains one transaction (the coinbase transaction), the merkle root hash will be the same as the hash of the coinbase transaction.

To construct the coinbase transaction, you will need more information, such as the transaction version number, any other data that is going into the coinbase script, and the output value. The pubkey will be used in the output script.

2. Why is it necessary to generate a "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"? :-) We are create a genesis-hash without to use it Smiley
Because it is necessary in order to generate the coinbase transaction whose hash is the merkle root.

Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
March 14, 2018, 01:10:53 PM
 #8

1. How can I get a Merkle root hash?
By constructing the coinbase transaction of the genesis block and hashing it. Because the genesis block only contains one transaction (the coinbase transaction), the merkle root hash will be the same as the hash of the coinbase transaction.

To construct the coinbase transaction, you will need more information, such as the transaction version number, any other data that is going into the coinbase script, and the output value. The pubkey will be used in the output script.

I watched the manual - did not quite understand Sad

Merkle root hash - is the double sha256 from a sequence of hexadecimal numbers, right?

And how exactly is this sequence constructed?

For example, genesis-hash is the (in pseudo-code):

Code:
sha256(sha256(version+previousblockheader+hash+merkleroothash+time+nBits+nonce))

than convert hash from little endian to big endian - voila! Smiley

It's very easy to understand. Thank you - you explained.

And how about Merkle root hash? How can I get coinbase for genesis-block?



DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
March 14, 2018, 02:21:15 PM
Last edit: March 19, 2018, 12:23:23 PM by DannyHamilton
Merited by ABCbits (2)
 #9

For example, genesis-hash is the (in pseudo-code):

Code:
sha256(sha256(version+previousblockheader+hash+merkleroothash+time+nBits+nonce))

than convert hash from little endian to big endian - voila! Smiley

It's very easy to understand. Thank you - you explained.

And how about Merkle root hash?

Code:
SHA256d(coinbaseTransaction)

voila!

It's very easy to understand.

achow101 already explained:

1. How can I get a Merkle root hash?
By constructing the coinbase transaction of the genesis block and hashing it.

How can I get coinbase for genesis-block?

To avoid confusion, please be aware that many people use the term "generation transaction" instead of "coinbase transaction".  In Bitcoin, these two phrases mean the exact same thing.  So, if you read anything about a bitcoin generation transaction, then it is talking about the same thing as a bitcoin coinbase transaction.

The Bitcoin genesis block coinbase transaction is as follows:
Code:
0x01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000

Look closely and you'll see that includes the following values:
Code:
5468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73

If you convert those hex values to ASCII characters, you'll get the following:
The Times 03/Jan/2009 Chancellor on brink of second bailout for banks

To better understand the contents of a bitcoin transaction, you can read this:
https://en.bitcoin.it/wiki/Transaction

I'll start at the beginning and break that transaction into some of the larger components in order for you to follow along (I'll leave it to you to break them down to their sub-components if you want to:

  • 01000000 (4 byte version number in little-endian byte order)
  • 01 (1 byte indication of the number of inputs in the transaction)
  • 0000000000000000000000000000000000000000000000000000000000000000 (32 byte hash of input transaction, since coinbase transactions don't have an input, this is always 32 bytes of 0)
  • ffffffff (4 byte index of the specific output being spent from the input transaction, since coinbase transactions don't have an input this value is being used as a place-holder)
  • 4d (1 byte indication of the length of the input script, hex 4d is decimal 77 so the input script will be 77 bytes long)
  • 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f7 2206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73 (77 byte input script)
  • ffffffff (4 byte sequence number)
  • 01 (1 byte indication of the number of outputs in the transaction)
  • 00f2052a01000000 (8 byte output value in little-endian byte order, little-endian hex 00f2052a01000000 is 5000000000 so this is a 50 BTC output)
  • 43 (1 byte indication of the length of the output script, hex 43 is decimal 65 so the output script will be 65 bytes long)
  • 4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4ce f38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac (65 byte output script)
  • 00000000 (4 byte lock time)
J-N
Member
**
Offline Offline

Activity: 100
Merit: 13


View Profile
March 16, 2018, 02:13:08 AM
 #10

2. Why is it necessary to generate a "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"? :-) We are create a genesis-hash without to use it Smiley
It is not necessary. This sentence is just a part of the input script of the coinbase transaction which is not used in the genesis block in fact. You can use any text in this field.
Coin-1
Legendary
*
Offline Offline

Activity: 2450
Merit: 2190



View Profile
March 17, 2018, 06:36:31 AM
Last edit: March 17, 2018, 07:01:07 AM by Coin-1
Merited by DannyHamilton (5), ABCbits (2)
 #11

For example, genesis-hash is the (in pseudo-code):

Code:
sha256(sha256(version+previousblockheader+hash+merkleroothash+time+nBits+nonce))

than convert hash from little endian to big endian - voila! Smiley

It's very easy to understand. Thank you - you explained.

And how about Merkle root hash?

Code:
SHA256(coinbaseTransaction)

voila!

It's very easy to understand.
No. To calculate a root merkle hash, you would use the double SHA256 here:
SHA256(SHA256(coinbaseTransaction))

Take a look at the block #1 of Bitcoin:
https://blockchain.info/block/00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048

This is its coinbase transaction in HEX format:
https://blockchain.info/tx/0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098?format=hex

If you will calculate SHA256 against this HEX string, you will get the intermediate hash:
1e120c45180578688c4aa403b2e1e30320baede01c402078cce5d42ca1446ca6

Then you need to calculate SHA256 against this intermediate hash. You will get the merkle root hash in the big endian format:
982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e

This is a merkle root hash in the little endian format:
0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098
Many Coins (OP)
Member
**
Offline Offline

Activity: 266
Merit: 11

Lord Shiva


View Profile
March 19, 2018, 09:11:29 AM
 #12


I'll start at the beginning and break that transaction into some of the larger components in order for you to follow along (I'll leave it to you to break them down to their sub-components if you want to:

  • 01000000 (4 byte version number in little-endian byte order)
  • 01 (1 byte indication of the number of inputs in the transaction)
  • 0000000000000000000000000000000000000000000000000000000000000000 (32 byte hash of input transaction, since coinbase transactions don't have an input, this is always 32 bytes of 0)
  • ffffffff (4 byte index of the specific output being spent from the input transaction, since coinbase transactions don't have an input this value is being used as a place-holder)
  • 4d (1 byte indication of the length of the input script, hex 4d is decimal 77 so the input script will be 77 bytes long)
  • 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f7 2206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73 (77 byte input script)
  • ffffffff (4 byte sequence number)
  • 01 (1 byte indication of the number of outputs in the transaction)
  • 00f2052a01000000 (8 byte output value in little-endian byte order, little-endian hex 00f2052a01000000 is 5000000000 so this is a 50 BTC output)
  • 43 (1 byte indication of the length of the output script, hex 43 is decimal 65 so the output script will be 65 bytes long)
  • 4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4ce f38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac (65 byte output script)
  • 00000000 (4 byte lock time)

You are the best!

Thank you!
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!