Most people mine bitcoin by launching a software on their PC or buying a special miner, both of which abstract out the nitty-gritty of how the mining process work. I am curious however about some potential issues with the nitty-gritty of the mining process. Feel free to skip to my question if you already know how it works:
As far as I know, this is how it works:
Given a string of hex values that is 1024 bit (or 256 hex values, or 128 bytes), let's say
0x000000020597ba1f0cd423b2a3abb0259a54ee5f783077a4ad45fb6200000218000000008348d1339e6797e2b15e9a3f2fb7da08768e99f02727e4227e02903e43a42b31511553101a051f3c00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000
And a 256 bit (or 64 hex values, or 32 bytes) value known as the target
0x00000000FFFF0000000000000000000000000000000000000000000000000000
We first byteswap each 32-bit chunk, so we end up with
0x020000001fba9705b223d40c25b0aba35fee549aa477307862fb45ad180200000000000033d14883e297679e3f9a5eb108dab72ff0998e7622e427273e90027e312ba443105315513c1f051a00000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280
We read the last 64 bits (or 16 hex values or 8 bytes)
0x0000000000000280
Which equals to 640 bits, or 80 bytes.
So we grab the first 640 bits (or 160 hex values, or 80 bytes) of byte-swapped string of hex values
0x020000001fba9705b223d40c25b0aba35fee549aa477307862fb45ad180200000000000033d14883e297679e3f9a5eb108dab72ff0998e7622e427273e90027e312ba443105315513c1f051a00000000
We do not change the first 608 bits, but we keep on changing the last 32 bits (or also known as the nonce value) and put the new string of hex values into the SHA256 function
#scroll to right to see the last 8 bits incrementing
new_hash = SHA256('0x020000001fba9705b223d40c25b0aba35fee549aa477307862fb45ad180200000000000033d14883e297679e3f9a5eb108dab72ff0998e7622e427273e90027e312ba443105315513c1f051a00000000')
new_hash = SHA256('0x020000001fba9705b223d40c25b0aba35fee549aa477307862fb45ad180200000000000033d14883e297679e3f9a5eb108dab72ff0998e7622e427273e90027e312ba443105315513c1f051a00000001')
new_hash = SHA256('0x020000001fba9705b223d40c25b0aba35fee549aa477307862fb45ad180200000000000033d14883e297679e3f9a5eb108dab72ff0998e7622e427273e90027e312ba443105315513c1f051a00000002')
# .. so on
If we find a new_hash that is lower or equal to the target,
# one of the new_hash is
new_hash = 0x00000000fffe0000000000000000000000000000000000000000000000000000
# which is is lower than target
then we have successfully found a nonce value (the 32 bits that we are changing) that satisfies the requirement, so we can submit it and earn a share, which I understand is a small chunk of reward to the miner when the actual full requirements are satisfied.
Where I read this: https://en.bitcoin.it/wiki/Getwork
Skip down to here if you already know how bitcoin mining works under the hood. When I learn about this, however, I have 3 questions about it:
To be able to get a value lower than that target randomly, there will be a 1 in 4295032833 (4.3 billion) chance of succeeding.
The nonce value which we can change is 32 bit or 4294967296.
So the expected value of getting it right after trying every nonce value is (4294967296/4295032833), or basically 1.
But that is the expected value, there will be cases where every nonce value is tried and we still do not get to the target.
Question 1. How does software like NiceHash miner or other mining tools handle situations like this under the hood?
Here is another issue, it is going to take computers some time to try out every nonce value because there are 4 billion of them. Question 2: Is there a time limit to how long a miner can take to guess and check before the given work is no longer "accepted"?
And here is my 3rd one, the given target is not exactly sufficient in mining a full block, attaining it will instead earn miners a share. The system is implemented like this so that miners can share their reward proportional to the amount of computation they have performed.
Question 3: How much, usually, is each share reward is in US dollars? I am guessing it varies from pool to pool, but what would the financial value usually be at?
Also if there is something wrong with my own re-articulation of how bitcoin mining works, please let me know as well.