What do bitcoin miners do? Why do they come together in “mining pools”? How do pools verify millions of trillions of hashes per second?
Concretely, what is mining?
Mining is a lottery whose tickets are paid in 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;
- Distribute 21 million bitcoins fairly by rewarding miners who contribute 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 pass data through a SHA-256 algorithm as quickly as possible.
When you enter any data into SHA-256, it will always give you the same output hash. A hash looks like this:
A hash from SHA-256 comes out as 64 numbers and letters. You can moreover have fun with.
Incidentally, if you have played with SHA-256, you have realized that it goes very quickly. Nothing to do with solving a “complex mathematical problem” as we sometimes hear. End of parenthesis.
The data entered is basically the transactions included in the block as well as a nonce. The nonce (short for “number only used once”) is a number that the miner varies to obtain a multitude of different hashes, until the right one is found.
Among the data entered in SHA-256, there is also the hash of the previous block. Hence the name “chain” block.
In short, bitcoin mining comes down to providing a block of data in SHA-256 to produce a hash. That’s all…
But not just any hash!
It has to be a precise hash. As suggested in the diagram, a valid hash is a hash that starts with a certain number of zeros. The greater the number of zeros, the more statistically difficult the hash to generate.
This is called the concept of “difficulty to mine” which is illustrated by the number of zeros necessary at the beginning of a hash for it to be valid.
If a miner finds a satisfactory hash (which starts with 8 zeros for example), the block corresponding to this hash is added to the blockchain. As a reward for his work, the miner receives bitcoins. That 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 that a block be found every 10 minutes on average.
But intuitively, we understand that the hashes will be found faster and faster as new miners join the network.
Thus, to maintain a rate of one block every 10 minutes, Satoshi Nakamoto decided to regularly adjust the difficulty of mining.
In concrete terms, every 2016 blocks, the average time elapsed between each block is calculated. If this average time is greater than 10 minutes, the difficulty increases and vice versa.
Why 10 minutes? We do not know. Perhaps Satoshi Nakamoto wanted the blockchain not to grow too fast so that it could fit in a small hard drive and as many people as possible could participate in the network.
How do miners get their BTC?
Now that the basics are laid, it must be said that miners come together in mining pools.
Few are those who mine solo. Sometimes a solo miner finds a valid hash. This lucky miner then receives 6.25 BTC all to himself. But the vast majority of miners prefer to pool their hashrate to smooth their earnings.
The biggest pools are Foundry USA (27% of the hashrate), AntPool (20%), F2Pool (15%), Binance Pool (11%), ViaBTC (9%), Braiins (previously Slush pool, with 4%), etc here is complete list.
What interests us now is how do pools verify that the hashes generated by miners are legitimate?
It is actually very simple. The pool only has to enter the hash in SHA-256. The hash is valid if it gives exactly the block data provided by the pool (miners do not choose which transactions are integrated into a block).
Very good, but checking each hash consumes as much electricity as it takes to create it… Impossible, because it would absolutely not be profitable for the pools.
Therefore, the pools use a subterfuge.
The selection of hashes sent to the Pool
This is where we come back to the difficulty in mining that we were talking about above. As a reminder, this difficulty means that a hash is valid only if it begins with a suitable number of zeros.
However, statistically, a miner will more often find a hash starting with a single zero than two zeros. It will find even less with three zeros and so on.
Moreover, and still according to the law of probability, after having generated billions of hashes, the miner ends up with constant proportions of hashes starting with a single zero, two zeros, three zeros, etc.
Thus, in order not to drown the pool, miners only provide hashes above what is called the “share difficulty target”.
That is, hashes that are much harder to find than a lambda hash. For example, if a valid hash requires starting with 8 zeros, the pool will ask to receive only hashes starting with a number of zeros between 5 and 8 (arbitrary numbers).
These hashes that are harder to find than average are called “shares”. As soon as a miner produces a share, he sends it to the pool which checks the validity of the hash.
The speed at which a miner sends shares allows the Pool to deduce the hashrate of its client (the miner).
Without this system, pools would have to verify ALL hashes. In other words, all Proof-of-Work.
How are shares calculated?
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 have a higher target difficulty (he will have to send hashes starting with more zeros) than a miner with only one machine. The goal is to have miners submit a share every 2-3 seconds, which is enough to accurately determine a miner’s hashrate.
A hash provided by a miner with 10,000 machines does not earn as many shares as a hash from a miner with a single machine.
For example, let’s say we have a large miner who the pool constrains 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 represent 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 provided by each miner.
Check out our article where we discuss Stratum V2. It is a protocol that allows miners to choose BTC transactions themselves. It will avoid possible censorship by the pools.
Receive a digest of news in the world of cryptocurrencies by subscribing to our new service ofdaily and weekly so you don’t miss any of the essential Tremplin.io!