In the previous article, I briefed about bitcoin and a little bit about bitcoin mining. In this, we will see how mining of bitcoin is done, what are the hardware, software and other essentials used in bitcoin mining.
What is bitcoin mining?
So far, we know that mining involves solving a cryptographic puzzle. After solving this puzzle, the block is added to blockchain. Few bitcoins are given to miner as reward for mining the block. We also mentioned that there are only 21 million bitcoins available and speculation is that last bitcoin will be mined only by year 2140. This is because, the reward for mining bitcoins half for every 210,000 blocks added to the blockchain. Around 14 million bitcoins have been mined by the end of 2017 and the rate of mining bitcoins will reduce as new blocks are added.
Now we will look on what consists of a block. A block contains data and block header. Data is the set of verified transactions which a miner picked to create a block. Block header is the place the security of the block is implemented. A block header has 6 fields in it.
- Previous Hash
- Merkle Root
- Difficulty Target
We will look into each in the following sections.
Version is the block version number which indicates the software version. Every software version has its own set of consensus and validation rules. Every full nodes need to follow these rules to stay in a general agreement with other nodes. Full nodes are those nodes in a network that validate transactions and blocks. Version field in block header is 4 bytes wide in size.
Time stamp is the time when the miner started encrypting the header. If the time stamp is two hours in future from the full nodes clock, the full nodes will not accept the block for verification. Time stamp field is also 4 bytes wide.
As the name suggests, this is the SHA256 encrypted hash of previous block. Inclusion of this in the header ensures that modification of previous blocks cannot be done without modifying the header of this block. If data in any block is changed, its hash also changes. Thus the header of the next block will also be changed and so will be the hash of next block and so on. This is what makes blockchain more secure. Previous hash is 32 bytes wide (256 bits)
We know that block contains list of hashes of all transactions. Merkle Root hash is nothing but the SHA256 hash of all these hashes. That is, it is hash of hashes. Merkle Root has ensures that the transactions in the block is not altered. This is an additional security feature of blockchain. Merkle Root hash is 32 byte wide.
If you have noticed, so far we have not come across any puzzle. Difficulty target is the main ingredient in the puzzle.We need to know what is difficulty before diving into difficulty target. We know that miners compete with each other to solve the puzzle. Difficulty is the measure of difficulty in finding hash of the block. Difficulty ensures that blocks are created in a certain rate. This gives every miner a fair chance to solve the puzzle and create a block. Roughly in every 10 minutes a block is created in bitcoin.
Bitcoin has a difficulty target globally. Every miner should find a hash which is less than this target. This is the job of a miner. Find the hash of the block which is less than difficulty target. (But hey, didn’t you mentioned earlier that unique data has unique hash. So to change hash, you need to change the data. Does this means altering the data?) If this popped into your mind, then you are right. A portion of the block header is changed to achieve hash lower than difficulty target. But that part is not the transactions. But, the other section in the block, Nonce. And yes, difficulty target is also 32 bytes wide.
So, you know by now, that nonce value changes. But how? Nonce value is incremented from 0 to 232 till a hash less than or equal to difficulty target is achieved. But, what if difficulty target is not achieved? After this, time stamp is updated and the process is repeated. Also, difficulty target changes for every 2016 blocks.
We discussed about the data and the block header. We got an idea about the puzzle and what miner does. At the inception of bitcoin, gaming PCs were used to mine bitcoins. Then GPUs were used to mine. And lately, ASIC (Application specific Integrated Circuits) chips are used for mining. These chips are made specifically for mining and are super fast. Latest ASIC miner by bitmain, Antminer S9 has an approximate hash rate of 14TH/s, which is 14,000,000,000,000 hashes per second. (INSANE!)
The image shown below is an inside view of bitcoin mining farm which uses several of these on a massive scale. Advantage of having this large scale farm is the speed at which blocks are mined.These chips are comparatively power hungry devices and eat a large chunk of electricity for operation. Proper cooling is also needed for proper functioning of the device. It is estimated that bitcoin mining requires 30.14TWh a year. It is more than the energy consumption of total population in Ireland. In short, bitcoin mining is not so profitable in small scale if electricity price is high in your country.
How to mine bitcoin?
So far we learned the inside process and now will look how can one mine bitcoin in real world. All you need is a bitcoin wallet, a hardware and a mining software. This is a beginner level mining requirements and doesn’t cover complex mining techniques and equipment. So basically, what you will be doing is, running a mining program on your PC with dedicated hardware which will validate transactions in bitcoin network and receiving bitcoins as transaction fees.
A bitcoin wallet is where public keys are stored. In order to buy, sell or mine bitcoin. You need to have a public key and a private key. Bitcoin wallet or client software will manage all the keys. There are many companies that have wallets and all you need is to signup with these wallets. Some of the popular bitcoin wallets are coinbase, electrum, and Mycelium. Out of which coinbase is the easiest one for starters, as it does all the work for you.Bitcoin wallet is another detailed topic which will be covered in next article. There are 7 types of wallets for storing bitcoins. Cold wallets and Hot wallet, Desktop wallets, Mobile wallets, Online web wallets, Physical wallets, Bitcoin Clients and Hardware Wallets. Each will be detailed in the next article and also, which to choose will be dicussed.
You can purchase a bitcoin miner from amazon or can use GPU from a gaming PC. Using a GPU will be less efficient as they are not build for mining. Also using your GPU for an extended period of time can cause damage to the GPU. Replacement of these will be costly as GPUs are not cheap. Mining hardware like antminer is also not cheap but energy efficient than GPUs.
One of the popular mining software is NiceHash Miner which can be also run on windows machines. Download the software and run the software. The software will ask the bitcoin address to which bitcoins are to be transferred. This is provided by the bitcoin wallet. There is one thing to keep in mind that, software like these take a small portion of the bitcoins as service charge.
So the big question is, Should you be a miner?
Well, it depends! There are several factors to keep in mind before setting up mine for bitcoin or any other crypto-currencies. You need to calculate whether value of bitcoin that you are mining is profitable after deducting electricity bill and hardware cost. Small scale bitcoin miner may get from 0.00001 – 0.0015 bitcoins per day. This is a speculative range depending on the uptime of the system and speed of hashing and can change from person to person. You can calculate an estimate of bitcoin earning using any hardware using this link.
Even though the price of bitcoin is increasing day by day, the future is uncertain and the price is highly volatile. There are many who speculate that bitcoin is a bubble and can burst someday. It can be true, because bitcoin possess all the qualities of a bubble. There is no guarantee in anything as bitcoin is in its beginning phase and true value of bitcoin is uncertain for now. Mining of bitcoin is as risky as investing in bitcoin. So it will a personal choice of one whether or not to be a miner or not. It is advisable to research deep before starting a bitcoin mine as there are plenty of ponzi schemes related to mining and earning through bitcoins.