As I've read, a basic miner does this:
var blockheader = DoGetWorkRPCCall();
var target = ExtractTarget(blockheader);
for(nonce = 0; nonce < 4294967295; nonce++)
{
var attempt = ModifyNonce(blockheader, nonce);
var hash = SHA256(SHA256(attempt));
if (hash < target)
ReportSolution(attempt);
}
1) Are there really multiple solutions? Should that instead read:
if (hash < target)
{
ReportSolution(attempt);
break; }
2)
if(hash < target) - I can't figure out where GPU miners do this. They all seem to add some magic constant to the uper 32 bits, and then check if that == 0. Isn't that just an approximation of "< target" ? Won't that result in some incorrect solutions being reported?
3) From
http://blog.ezyang.com/2011/06/the-cryptography-of-bitcoin/:
the computationally hard problem is essentially a watered-down version of the first-preimage attack on a hash function. Miners are given a set of solution hashes (the hash of all zeros to a target hash), and are required to find a message with particular structure (a chain of blocks plus a nonce) that hashes to one of these hashes. Is this accurate? In the above code, does DoGetWorkRPCCall get a single solution hash? What exactly does "hash of all zeros to a target hash" mean?
Thanks for any help clarifying, this is a great community.