Bitcoin Forum
April 30, 2024, 11:40:15 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Two questions about hashing the block header.  (Read 978 times)
tobasco (OP)
Member
**
Offline Offline

Activity: 61
Merit: 12


View Profile WWW
January 14, 2015, 11:16:42 AM
 #1

Hi there,

I'm looking at the block header information on this page: https://en.bitcoin.it/wiki/Block_hashing_algorithm

It covers the following block header fields:

Version
hashPrevBlock
hashMerkleRoot
Time
Bits
Nonce


1. Are these the exact field names used in the protocol, or are these just descriptive names for the purposes of the article?

2. A question about the Bits field.

When hashing the block header in the example PHP code at the bottom of the bitcoin wiki page, the value used for Bits is 440711666.

However, when looking at the block information (http://blockexplorer.com/b/125552), the value they have displayed for Bits is Difficulty?: 244 112.487774 ("Bits"?: 1a44b9f2)

How do I convert the difficulty/bits information displayed on blockexplorer to 440711666?

1714477215
Hero Member
*
Offline Offline

Posts: 1714477215

View Profile Personal Message (Offline)

Ignore
1714477215
Reply with quote  #2

1714477215
Report to moderator
Bitcoin addresses contain a checksum, so it is very unlikely that mistyping an address will cause you to lose money.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714477215
Hero Member
*
Offline Offline

Posts: 1714477215

View Profile Personal Message (Offline)

Ignore
1714477215
Reply with quote  #2

1714477215
Report to moderator
1714477215
Hero Member
*
Offline Offline

Posts: 1714477215

View Profile Personal Message (Offline)

Ignore
1714477215
Reply with quote  #2

1714477215
Report to moderator
1714477215
Hero Member
*
Offline Offline

Posts: 1714477215

View Profile Personal Message (Offline)

Ignore
1714477215
Reply with quote  #2

1714477215
Report to moderator
ncsupanda
Legendary
*
Offline Offline

Activity: 1628
Merit: 1012



View Profile
January 14, 2015, 11:29:07 AM
 #2

Hi there,

I'm looking at the block header information on this page: https://en.bitcoin.it/wiki/Block_hashing_algorithm

It covers the following block header fields:

Version
hashPrevBlock
hashMerkleRoot
Time
Bits
Nonce


1. Are these the exact field names used in the protocol, or are these just descriptive names for the purposes of the article?

2. A question about the Bits field.

When hashing the block header in the example PHP code at the bottom of the bitcoin wiki page, the value used for Bits is 440711666.

However, when looking at the block information (http://blockexplorer.com/b/125552), the value they have displayed for Bits is Difficulty?: 244 112.487774 ("Bits"?: 1a44b9f2)

How do I convert the difficulty/bits information displayed on blockexplorer to 440711666?

Take a look at the source code - the first question answers itself.

https://github.com/bitcoin/bitcoin
dabura667
Sr. Member
****
Offline Offline

Activity: 475
Merit: 252


View Profile
January 14, 2015, 11:43:18 AM
 #3

1. Are these the exact field names used in the protocol, or are these just descriptive names for the purposes of the article?

2. A question about the Bits field.

1. What do you mean "used in the protocol"? Do you mean what is the name of the containers in the source code?

2. https://en.bitcoin.it/wiki/Difficulty#How_is_difficulty_stored_in_blocks.3F

Once you figure out how to calculate the msb with the remaining 3 bytes at this link, you'll figure it out.

My Tip Address:
1DXcHTJS2DJ3xDoxw22wCt11FeAsgfzdBU
tobasco (OP)
Member
**
Offline Offline

Activity: 61
Merit: 12


View Profile WWW
January 14, 2015, 11:57:54 AM
 #4

1. What do you mean "used in the protocol"? Do you mean what is the name of the containers in the source code?

Yes. Sorry my terminology is poor.

I was able to find (I think) that hashMerkleRoot is a block header field name from this file: https://github.com/bitcoin/bitcoin/blob/master/src/merkleblock.cpp

However I must confess that I am noob to the source. Can you point me in the direction of where I might find the code for the hashing the block header (and thus the field/container names)?

ncsupanda
Legendary
*
Offline Offline

Activity: 1628
Merit: 1012



View Profile
January 14, 2015, 12:00:10 PM
 #5

1. What do you mean "used in the protocol"? Do you mean what is the name of the containers in the source code?

Yes. Sorry my terminology is poor.

I was able to find (I think) that hashMerkleRoot is a block header field name from this file: https://github.com/bitcoin/bitcoin/blob/master/src/merkleblock.cpp

However I must confess that I am noob to the source. Can you point me in the direction of where I might find the code for the hashing the block header (and thus the field/container names)?

By "hashing the block header" are you referring to hashing the contents of the merkleblock.cpp file?
tobasco (OP)
Member
**
Offline Offline

Activity: 61
Merit: 12


View Profile WWW
January 14, 2015, 12:21:42 PM
Last edit: January 14, 2015, 12:33:19 PM by tobasco
 #6

By "hashing the block header" are you referring to hashing the contents of the merkleblock.cpp file?

I do not understand the structure of the code well enough to answer your question accurately. Although I'd say that "hashing the contents of the merkleblock.cpp file" is an inaccurate evaluation of what I'm looking to achieve.

To try and clarify, what I believe I am now looking for are the file(s) that performs this:

"When mining bitcoin, the hashcash algorithm repeatedly hashes the block header while incrementing the counter & extraNonce fields."
 - https://en.bitcoin.it/wiki/Block_hashing_algorithm

Note that finding the block header field names (container names?) in the source code is still my primary goal.

tobasco (OP)
Member
**
Offline Offline

Activity: 61
Merit: 12


View Profile WWW
January 14, 2015, 02:02:03 PM
 #7

Okay, so f2b9441a is the Little-endian of 440711666.

Where does 440711666 come from?

https://en.bitcoin.it/wiki/Block_hashing_algorithm (PHP script at the bottom)

ncsupanda
Legendary
*
Offline Offline

Activity: 1628
Merit: 1012



View Profile
January 14, 2015, 02:07:25 PM
 #8

Okay, so f2b9441a is the Little-endian of 440711666.

Where does 440711666 come from?

https://en.bitcoin.it/wiki/Block_hashing_algorithm (PHP script at the bottom)

Current target difficulty.
tobasco (OP)
Member
**
Offline Offline

Activity: 61
Merit: 12


View Profile WWW
January 14, 2015, 02:12:36 PM
 #9

I see, thank you.

So how does 244 112.487774 = 440711666?

http://blockexplorer.com/b/125552

grau
Hero Member
*****
Offline Offline

Activity: 836
Merit: 1021


bits of proof


View Profile WWW
January 14, 2015, 05:53:01 PM
 #10

Below explanation using Matematica. I am sure you figure what the operations mean even if you do not use it regularly.

Code:
In[15]:= minTarget = 
 FromDigits["ffff", 16]*2^(8*FromDigits["1d", 16] - 3)

Out[15]= 56538243354614949726192090679290607878297928311398285361572003125835857920

In[16]:= target =
 FromDigits["44b9f2", 16]*2^(8*FromDigits["1a", 16] - 3)

Out[16]= 231607337543830564817752779584294829436484108612716418234853202329600

In[19]:= minTarget/target

Out[19]= 36649828352/150135

In[20]:= N[36649828352/150135]

Out[20]= 244112.
doof
Hero Member
*****
Offline Offline

Activity: 765
Merit: 503


View Profile WWW
January 16, 2015, 12:47:54 AM
 #11

I did a c# example too

https://bitcointalk.org/index.php?topic=888078.msg9791851#msg9791851
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!