Bitcoin Forum

Bitcoin => Bitcoin Discussion => Topic started by: ck3po on January 10, 2024, 02:21:39 AM



Title: Bitcoin header help...
Post by: ck3po on January 10, 2024, 02:21:39 AM
So... I was going through the CPUMiner code (... YES, I know CPU mining is dead, I'm just using this code as an educational way to learn how BTC blocks and transactions are assembled) and was wondering about these two lines:

   work->data[20] = 0x80000000;
   work->data[31] = 0x00000280;

in the block header setup. Any idea why these values are important to set? From reading the BTC specs, I thought the header padding from +20 onwards was all supposed to be 0's..?

So confused newbie to the bowels of BTC... any help appreciated, thanks.


Title: Re: Bitcoin header help...
Post by: pooya87 on January 10, 2024, 04:22:11 AM
This looks like SHA256 related values.
The first one 0x80 is the SHA-2 specific padding used at the end of the message (1 followed by m 0)[1].
The second one (0x0280) is the message length in bits added at the end of the final [SHA2] block. We have an 80-byte header so 80 byte message * 8 = 640 bits or 0x0280

[1] https://datatracker.ietf.org/doc/html/rfc6234#section-4


Title: Re: Bitcoin header help...
Post by: ck3po on January 19, 2024, 06:16:07 PM
Brilliant, thank you. I had no clue these were SHA256 prefix/suffix-related. I really appreciate it, thanks!

This looks like SHA256 related values.
The first one 0x80 is the SHA-2 specific padding used at the end of the message (1 followed by m 0)[1].
The second one (0x0280) is the message length in bits added at the end of the final [SHA2] block. We have an 80-byte header so 80 byte message * 8 = 640 bits or 0x0280

[1] https://datatracker.ietf.org/doc/html/rfc6234#section-4