Bitcoin Forum
July 30, 2024, 04:51:14 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin header help...  (Read 86 times)
ck3po (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
January 10, 2024, 02:21:39 AM
 #1

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.
pooya87
Legendary
*
Offline Offline

Activity: 3528
Merit: 10723



View Profile
January 10, 2024, 04:22:11 AM
 #2

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

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
ck3po (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
January 19, 2024, 06:16:07 PM
 #3

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