0

I'm going to screw up a lot of the terminology here. I'm trying to understand the Bitcoin algortihm and wanted to use this JS miner -- https://github.com/howardchung/jsminer . Specifically, I'm trying to understand how to build the data that someone attempts to hash. They attempt to do this in the JS miner by the following

    var header = version + prevhash + merkle_root + ntime + nbits + '00000000' + '000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000';
    curr_block.data = header;

I'm following most of this, using the Bitcoin wiki as a reference, but what I can't figure out at all is what are these last two numerical constants -- '00000000' and the bigger one beginning with "0000008". I have seen these come up in other examples but I can't figure out why these are needed or if these are hard-coded values in the JS miner that shouldn't be there in real life. Any help is appreciated.

0

The first 00000000 is for the nonce. The nonce is changed in order to get a different block header without reselecting transactions. It is what is used primarily for finding a valid block hash.

The long string of bytes beginning with 0000008 is SHA-256 padding. It is not actually part of the block header and whatever is doing the SHA-256 hashing should figure out and append this padding for you. It is part of the pre-processing step for SHA-256.

  • Yeah I pulled this fragment out of the section of the code where they're doing that pre-processing. Since the string beginning with "0000008" is padding, can it be anything? Does it have to be that specific sequence? – Dave Mar 13 '18 at 0:45
  • Yes. The padding is fixed and must be the same for all blocks. It should really be calculated dynamically by the SHA-256 function instead of something that you are hard coding. – Andrew Chow Mar 13 '18 at 1:47
  • To clarify your "Yes", do you mean "Yes it can be anything" or "yes it must be that specific sequence"? – Dave Mar 13 '18 at 13:51
  • Yes, it must be that specific sequence. – Andrew Chow Mar 13 '18 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.