Bitcoin Mining – How Does It Really Work?
What do Bitcoin miners do? Why do they come together in “mining pools”? How do pools verify millions of trillions of hashes per second?
Specifically, what is mining?
Mining is a lottery whose tickets are paid with electrons and at the end of which new transaction blocks are added to the Bitcoin blockchain. It has two main objectives:
- Add transactions to the Blockchain;
- Fairly distribute 21 million bitcoins by rewarding miners who provide electricity to secure the network.
Miners use ASICs (Application Specific Integrated Circuits). These are integrated circuits designed specifically to perform a specific task. This task is simply to transfer data as quickly as possible through the SHA-256 algorithm.
Whenever you input any data into SHA-256, it will always give the same output hash. The hash looks like this:
A hash from SHA-256 comes out as 64 numbers and letters. You can have fun with it too.
By the way, if you’ve played with SHA-256, you’ve realized that it goes very fast. It has nothing to do with solving a “complex mathematical problem” as we sometimes hear. End of bracket.
The input data is mainly block input transactions and one-time transactions. A nonce (short for “number used only once”) is a number that a miner changes to produce many different hashes until the correct one is found.
Among the data included in SHA-256 is the hash of the previous block. Hence the name “chain” block.
In short, bitcoin mining comes to provide a block of data in SHA-256 to generate a hash. That’s all…
But not just any hash!
This must be an exact hash. As suggested in the diagram, a valid hash is a hash that starts with a certain number of zeros. The higher the number of zeros, the harder it is statistically to create a hash.
This is called the concept of “mining difficulty”, which is described by the number of zeroes needed at the beginning of a hash for it to be valid.
If the miner finds a satisfactory hash (for example, starting with 8 zeros), the block corresponding to this hash is added to the blockchain. As a reward for his work, the miner receives bitcoins. This is currently 6.25 BTC per block.
Now let’s come to the concept of “difficulty adjustment”. To understand this, we must first clarify that the Bitcoin protocol requires a block to be found every 10 minutes on average.
But intuitively, we understand that hashes will be found faster and faster as new miners join the network.
So, in order to maintain a block rate of every 10 minutes, Satoshi Nakamoto decided to regularly adjust the difficulty of mining.
In concrete terms, the average time between each block is calculated from every 2016 blocks. If this average time is more than 10 minutes, the difficulty increases and vice versa.
Why 10 minutes? We don’t know. Perhaps Satoshi Nakamoto wanted the blockchain to grow so fast that it could fit on a small hard drive and have as many people participating in the network as possible.
How do miners get their BTC?
Now that the foundations have been laid, it’s safe to say that miners come together in mining pools.
There are few lone miners. Sometimes a solo miner finds a valid hash. This lucky miner then gets himself 6.25 BTC. But the vast majority of miners prefer to combine their hashrates to smooth out their earnings.
The largest pools are Foundry USA (27% of hashrate), AntPool (20%), F2Pool (15%), Binance Pool (11%), ViaBTC (9%), Brains (formerly Slush pool, 4%), etc. Here is the full list.
Now we are wondering how the pools verify that the hashes generated by the miners are legitimate.
It’s actually very simple. The pool should only include a hash in SHA-256. A hash is valid if it provides exactly the block data provided by the pool (miners do not choose which transactions are integrated into the block).
Very good, but verifying each hash consumes as much electricity as it takes to generate it… Impossible, because it wouldn’t be completely cost-effective for pools.
Therefore, pools use a trick.
Selection of hashes sent to the pool
This brings us back to the difficulty in mining we talked about above. Recall that this difficulty means that a hash is valid only if it starts with the appropriate number of zeros.
However, statistically, a miner will more often find a hash that starts with one zero than two zeros. It will find less with three zeros and so on.
Moreover, according to the law of probability, after generating billions of hashes, the miner will have a single zero, two zeros, three zeros, etc. starting with and ending with fixed ratio hashes.
So, in order not to overwhelm the pool, miners only provide hashes above the so-called “shared difficulty target”.
That is, hashes that are harder to find than lambda hashes. For example, if a valid hash requires 8 to start with zeros, the pool will only ask to receive hashes that start with a number of zeros between 5 and 8 (arbitrary numbers).
These hashes, which are more difficult to find than average, are called “stakes”. As soon as a miner produces a stake, it sends it to a pool that verifies the validity of the hash.
The speed at which a miner sends shares allows the Pool to derive the hashrate of its client (the miner).
Without this system, pools would have to check ALL hashes. In other words, all Proof-of-Work.
Of course, there is no single target difficulty for all miners in a pool. The type of hash a miner must contribute to the pool is based on their hashrate.
For example, a miner with 10,000 machines will face a higher target difficulty (will have to send more zero-starting hashes) than a miner with only one machine. The goal is for miners to submit a stake every 2-3 seconds, which is enough to accurately determine a miner’s hashrate.
A hash submitted by a miner with 10,000 machines does not earn as much share as a hash from a miner with one machine.
For example, let’s say we have a large miner whose pool is limited to a target difficulty of 10,000 and a smaller miner with a target difficulty of 100. Both miners will submit a hash every 2-3 seconds on average, but this hash will be representative. 10,000 shares for the largest miner and only 100 shares for the smallest.
In short, pools distribute rewards based on shares that are proportional to the hashrate submitted by each miner.
Check out our article where we discuss the Stratum V2. It is a protocol that allows miners to self-select BTC transactions. This will avoid possible censorship by pools.
Get news from the world of cryptocurrencies by subscribing to our new service.daily and weekly so you don’t miss any of the main Cointribune!
A journalist reports on the Bitcoin revolution. My papers deal with bitcoin from geopolitical, economic and libertarian perspectives.