I have spend two weeks now searching the internet for a worked calculation concerning the formulation of the block header to be hashed, but I can't find anything that addresses the WHOLE puzzle, so I thought I'd ask for help here. I am working on some code for BTC mining on a CPU. Before you get all up in arms about this, I have a fleet of S21 ASIC miners. I know a CPU can't compare, but this is an academic exercise.
I've got my code to communicate to the pool and submit fake or stale shares just to prove that I am able to log in and start mining properly. I'm at the point where I want to fiddle with nonce, etcetera, to find some real shares. I'm on a Ryzen CPU, so I might possible have enough horse power if I'm lucky to bump into a share before my block expires. But that's not the point ... I want to prove that I fully understand the process by being able to write code to do this.
I managed to get as far as finding an "almost" fully worked example, and tested my code to confirm that I got the same (good) hash as the author did, however I had to manually feed the value for the Merkle root into my code, since there was not enough information in the resource to know how the root was calculated. I know how is SHOULD be calculated, but without this missing information I cannot confirm my understanding. I do have captured traffic from my S21's to test with, but I've never been able to get a hash value that made sense. i.e. no leading or even trailing zeros on it - it always starts (and ends) with a non-zero hex digit. So I temporarily put my captured traffic aside and spent two weeks searching for a fully worked example to confirm that I was doing everything correctly.
As I said, I got as far as finding a source that gave the 80 byte block to be hashed, along with a detailed explanation of most of the bit fields it contained. It works fine, but the portion of the 80 bytes that contains the Merkel root does not have enough information for me to test that my code builds the root correctly. The worked example shows all the transaction hashes in the Merkel Branch, but I also require coinbase1 and coinbase2 along with Extranonce1 in order to include that in the hashing process to build the Merkel root. The example does not include these elements ... I forget just now, but MAYBE the source included an example Extranonce1 in there someplace, but it doesn't matter without coinbase1 and coinbase2, and those are definitely not present.
Now I found many sources that include an actual worked example of JUST this portion, i.e. everything needed find the doubleHash of (coinbase1 + Extranonce + coinbase2), but these examples do not include the rest of what is needed to actually build the 80 byte block header and hash it. So there is no way to verify that it has been done correctly or that an nonce even exists that would correspond to finding a share. I am looking for a single, fully worked example showing all the steps that includes what the block is supposed to hash to. This is the only way I can confirm my code. Once I can prove my code works, I should be able to plug in my captured S21 data and calculate the hash which had better have a lot of zeros on one side (or the other side).
Can anyone point me such an example online or even give me some fields that work so I can get my code? I need all the components that make up the block header including the nonce, and I also need to know what it is supposed to hash to. Can anyone help?
-gt-