Bitcoin Forum
May 23, 2024, 06:59:43 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Why is the block header 80 bytes, not 128 bytes (= two SHA-256 blocks)?  (Read 1029 times)
This is a self-moderated topic. If you do not want to be moderated by the person who started this topic, create a new topic.
Geremia (OP)
Sr. Member
****
Offline Offline

Activity: 505
Merit: 251


View Profile WWW
June 14, 2015, 12:50:42 AM
Last edit: June 14, 2015, 02:15:54 AM by Geremia
 #1

According to the Bitcoin Developer Reference, the block header is 80 bytes total:

BYTES   NAME
4       version
32      previous block header hash
32      merkle root hash
4       time
4       nonce


As I understand it, the midstate (1st SHA block) contains 64 bytes of the block header (which fields in particular I do not know, but I do know it doesn't contain the nonce), and the 2nd SHA block contains the rest, only 80-64 = 16 bytes. Does this mean the 2nd SHA block is padded with 64 - 16 = 48 bytes? If so, why not make the nonce field, for example, 48 - 4 = 42 bytes larger (i.e., 52 bytes instead of 4 bytes)?

That way, extranonce doesn't have to be in the generation transaction, thereby speeding up hashing, no?

(cf. the related Bitcoin StacxExchange question)

BTC tip jar | my BTC wiki, BTC StackExchange | Tox ID: 65C3E8810738AD9D175234808FCB317A1103632903436203D45411AE97C03F54C34861AB6663
Join Kraken. | The best, free book on Bitcoin: Mastering Bitcoin
Nos cum prole pia benedicat Virgo Maria.
lemipawa
Legendary
*
Offline Offline

Activity: 1708
Merit: 1003


View Profile
June 14, 2015, 02:49:13 AM
 #2

As I understand it, the midstate (1st SHA block) contains 64 bytes of the block header (which fields in particular I do not know, but I do know it doesn't contain the nonce), and the 2nd SHA block contains the rest, only 80-64 = 16 bytes. Does this mean the 2nd SHA block is padded with 64 - 16 = 48 bytes? If so, why not make the nonce field, for example, 48 - 4 = 42 bytes larger (i.e., 52 bytes instead of 4 bytes)?
Neither is a block and neither is padded. The midstate is hashed and contains 64 bytes of the header. These 64 bytes are things that will not change for the current block that is being mined. The remaining 16 bytes of the header is the stuff that will change such as the nonce. I don't know the specifics, but the midstate and the remaining 16 bytes are combined and hashed to produce the full 80 byte header. Once this is done, the header and the data is sent back to the pool or node to broadcast.
Geremia (OP)
Sr. Member
****
Offline Offline

Activity: 505
Merit: 251


View Profile WWW
June 14, 2015, 04:01:13 AM
 #3

Neither is a block and neither is padded.
Sorry for the confusion, but "blocks" is ambiguous, hence my using qualifiers: "SHA-256 blocks" ≠ "Bitcoin blocks."

See this post, which says "block header is 80 bytes, which is padded to 128 bytes, and split into two 64-byte parts."

BTC tip jar | my BTC wiki, BTC StackExchange | Tox ID: 65C3E8810738AD9D175234808FCB317A1103632903436203D45411AE97C03F54C34861AB6663
Join Kraken. | The best, free book on Bitcoin: Mastering Bitcoin
Nos cum prole pia benedicat Virgo Maria.
johoe
Full Member
***
Offline Offline

Activity: 217
Merit: 241


View Profile
June 14, 2015, 06:19:54 PM
 #4

Neither is a block and neither is padded.
Sorry for the confusion, but "blocks" is ambiguous, hence my using qualifiers: "SHA-256 blocks" ≠ "Bitcoin blocks."

See this post, which says "block header is 80 bytes, which is padded to 128 bytes, and split into two 64-byte parts."

The padding is only done internally by the SHA-256 algorithm, which works in 64 byte blocks.   In every other aspect the block header is only 80 bytes: it is stored as 80 bytes, it is transferred as 80 bytes etc.  Putting an extra nonce at the end of the block header would be a hard fork that would even affect SPV clients and the advantage would not merit the risk involved with a hard fork.

Note also that SHA-256 adds 9 bytes padding at the end so everything longer than 121 byte would require three blocks to hash.

Donations to 1CF62UFWXiKqFUmgQMUby9DpEW5LXjypU3
Geremia (OP)
Sr. Member
****
Offline Offline

Activity: 505
Merit: 251


View Profile WWW
June 16, 2015, 12:21:24 AM
 #5

the midstate (1st SHA block) contains 64 bytes of the block header (which fields in particular I do not know, but I do know it doesn't contain the nonce)
Mining Simulator (GitHub source) really helped me understand this.

BTC tip jar | my BTC wiki, BTC StackExchange | Tox ID: 65C3E8810738AD9D175234808FCB317A1103632903436203D45411AE97C03F54C34861AB6663
Join Kraken. | The best, free book on Bitcoin: Mastering Bitcoin
Nos cum prole pia benedicat Virgo Maria.
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!