List of common misconceptions about mining pool.

And how it actually works.

What is a mining pool?

You have probably heard about bitcoin miners. Some people with powerful computers or a specialized dedicated equipment solve cryptographic puzzles to ensure that Bitcoin is secure. By doing this, miners who are lucky and able to solve puzzles faster than others get rewarded with lots of money. Because many people are competing for this reward, even with expensive computers it takes months or sometimes years to get lucky for an individual participant. To make income more predictable miners are united in the groups which are called mining pools.

How does it work?

Do you ever think about how mining pools work? It sounds very simple — the miners just connect to the same network,mine bitcoins or whatever cryptocurrency together and distribute the profit. Sounds simple, right? But how does the mining pool actually work?

I was very surprised that almost none of the people I spoke with could correctly answer this question. And not only the regular crypto users but CTOs of blockchain companies with years of experience. This doesn’t make them less qualified in their area of expertise or not as smart, but rather shows that a mining pool works in a very tricky way and people are usually wrong about its principle of work.

In this article, I’ll show my learning curve of how I thought mining pool works, why I was wrong, and how it actually works.

Basic concept

The concept is simple. You might expect that a miner connects to the network and starts to mine. In other words, they start to check as many hashes of blocks as possible on behalf of the mining pool.

I.e. reward address is Bitcoin address which belongs to the pool and not a particular miner. When the block is mined the reward is distributed according to the contribution of each of the participants. That’s great. But how do you measure the contribution?

Well, it’s simple — you just measure the hashpower of mining! But how do you measure this hashpower? You can simply send these mined blocks to the server and the server will calculate how many to did you sent. Right?

Wrong! The problem with this approach is that you have to send so many blocks to the “server” that it would quickly exceed your output bandwidth of the network. Because there are lots of miners and everyone follows the same algorithms likely the input bandwidth of the server pool will be exceeded in a couple of million times as well. Besides, it takes less time to verify an individual block than to send it over the network. So, what’s the point?

Trust no one

Well, you might be lead to believe that you can do it only once when you first join the mining pool. Measure the number of blocks you can generate for a minute and after that, you can begin to mine with that particular mining power. The problem with this approach is that you begin to go against the first rule of cryptocurrency: trust no one!

For instance, a malicious miner can just borrow mining power from someone else to prove that it has over 9000 of Terrahash/sec (unit of measurement of the mining power) and after that continue to mine on single raspberry pi but get rewarded as a big Chinese mining farm. With this considered, we can see that this also will not work. We have to continuously prove the real effort of mining without trusting to anyone.

Can the pool-server of each participant? For example, the server will send a particular puzzle to solve and will remember your hash power to reward you based on how quickly you are able to solve it. This certainly should work, right? Wrong! Even if a malicious miner was able to solve this crypto puzzle fast enough to prove that it possesses the particular mining power, nothing prevents it from actually mining the block for his own Bitcoin address and sharing it from a different IP address as soon as he locates the block.

For the mining pool, this would look like some random miner on the internet was lucky enough to mine this block and it has nothing to do with the malicious miner.

So, it has to be a method of not just continuously proving the hash power (i.e. the ability to mine on behalf of the pool) but also proof that work had been actually done on behalf of the pool.

Amazing properties of the Proof of Work

And here we can actually use properties of Proof of Work. If you see it in details, the cryptographic puzzle which miners solve works in a relatively simple way. And it had nothing to do with sudoku as many people like to depicture it. In reality, the block looks like this

Each miner constructs such block and takes the hash of it. Hash works in an interesting way: if you change just a single bit of the block — the resulting hash will change completely. So the goal of the miner is to change something in the block, usually nonce and order of transactions that the resulting hash has a certain amount of leading zeros in the binary representation. If the hash has a sufficient amount of zeros — the puzzle considered solved and block can be sent over the network and every bitcoin node will treat as the legit block on the blockchain.

The only currently known way to find a block which will have a hash with leading zeros is a brute force. I.e. randomly change something in the block and check the hash. It means resulting hash will be unpredictable and miner have to generate random blocks until it will find “beautiful” hash. Because they appeared essentially randomly you would expect that block with one leading zero in the birthday format would appear 50% of times: half of the block start with 1 and a half with 0. Block with 2 leading zero appears every ¼ times: there would be about the same amount of blocks which starts from 11…, 10…, 01…, 00…, The generalization of this observation: to find a hash with n leading zeros you have to try 1 / 2^n blocks on average. Because the price of Bitcoin is volatile and the number of miners who try to solve it changes dynamically, the number of zeros adjusted time to time to have about 1 mined block for every 10 minutes. This amount of zeros called mining difficulty.

Mining shares

It has a very interesting side effect. To find a block with n leading zeros, you would expect to find twice as much blocks with n-1 zero, four times as much with n-2 leading zeros etc. So, even if it would take a long time for an individual miner to find a lucky block, you can totally proof that you had tried hard by showing blocks on behalf of the pool with a lower difficulty. I.e. blocks with hash with less leading zeros. Such blocks which have pool address for the reward but with lower difficulty called shares.

So the actual algorithm of the mining pool is the following: every miner who joins the network is mining blocks on behalf on the pool and sends proof of work has been done by sending blocks with fewer zeros than necessary. So, probabilistically speaking, because of this one miner eventually will find the winner block and everyone will have profit.

No cheaters

Can malicious miner cheat? Let say it sends shares to proof the work but then the right block is found the malicious miner don’t send the block on behalf on the pool and send it over different IP address on behalf on itself?

Turns out no, it can’t. Because to find the share it has to keep pool address as the block reward address, and as soon as the winning block founded, it will have pool address as well. To change it (remember, the single bit of block changes hash completely) miner have to redo all the work which doesn’t make economic sense.

Other challenges

This is just basically challenging of Proof of Work mining pools. There’s another very big challenge related to reward distribution. Particularly, because one block is mined once per 10 minutes, even a big mining pools should wait hours to get lucky and mine one block. Because it may take a long time, miners who just joined the pool have to essentially sponsor the losers who already tried to mine who weren’t lucky. Why don’t just kick them out? Or join another pool with less debt? If anyone is interested, I can explain pool reward strategies in another article.

if you have any questions feel free to ask it in the comments on by (twitter.com/lebed2045).

I hope this article explained to you something you didn’t know before, so please consider share or claps if you find it useful. I’ve spent several hours to write it for you (proof of work) and your like will be a reward. Thanks.

Special thanks to Vasily Fomin and Drew Valek for proofreading. Originally posted on http://reliable.cash