Posted on July 20, 2018 at 05:00 PM
In the previous blog, we have described about what a miner is, what does a miner do, and why do we need mining. Building on these points, in this blog we'll see what does a Blockchain look like, what does Proof-of-Work and mining difficulty mean, and how can you start mining for yourself.
Input – 123456
Hash - 8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
If we change the input, even by a small margin,
Input – 123457
Hash - 54b688a517f7654563a6c64d945a3670880a4c602ec67a065bbebbcd2b22edd5
The Hash of the previous block.
The Index of that block in the blockchain, which is nothing but the block number.
The Timestamp of when the block was generated.
The actual Data in the block, i.e. data of all the transactions in the block.
The Nonce is the solution to the Proof-of-Work problem.
And the Hash of the block.
The Proof-of-Work involves scanning for a value that when hashed, the hash begins with a number of zeros. The miner finds the Proof-of-Work by incrementing the Nonce in the block until a value is found that gives the block’s hash the required zero bits.
After the CPU work is spent to make it satisfy the proof-of-work, the data in the block cannot be changed without finding the new Nonce that will satisfy the hash’s required zero bits.
Do note that the hash of the previous block is used as the input parameter to calculate the hash of the new block. Thus if anyone tries to tamper with the blockchain. i.e. to change the transaction data in a block no. say 100, the hash of that 100th block will change, which in turn will change the hash of the 101st block, because the hash of 100th block is used to calculate the hash of 101st block. And so on, the hashes of all the consequent blocks will change. To modify a block in blockchain, an attacker would have to redo the proof-of-work of that block and all the blocks after it and then compete with the current network.
As the size of the blockchain increases, it becomes more and more difficult for an attacker to tamper with the old blocks, as the work to change the block would include redoing the proof-of-work for all the blocks after it.
The mining difficulty is the measure of how difficult it is to find the Proof-of-Work.
It is the number of zeros required in the beginning of the hash to make it acceptable to be added to the blockchain. So the greater this number, the more and more difficult it gets to generate a new block.
At any given instance, the mining difficulty of the Bitcoin system is set in such a way that a new block will take approximately 10 minutes to generate with the help of all the miners currently active in the Bitcoin’s network.
The Mining difficulty is a dynamic parameter, i.e. it is recalculated every 2016 blocks, depending upon the current network mining power.
As more miners join, the rate of block creation will go up. As rate goes up, the difficulty rises to compensate which will push the rate of block creation back down.
The Mining Difficulty and Proof-of-Work designs go hand in hand to ensure that the blockchain stays tamper proof and secure.
To start mining, you need:
Mining hardware: CPUs, GPUs as well as ASIC Cards are used as the hardware for mining. These do the actual calculation of hashes. Though practically speaking, as mining Bitcoins is becoming more and more difficult due to the increasing interest of people in joining the network for mining, it is not advisable to mine using a CPU or a GPU nowadays to make a substantial profit. ASIC cards are designed for the sole purpose of mining, and are much more powerful than the regular CPUs and GPUs.
Mining software: A software program such as GUIMiner, CGMiner, etc. keeps track of the transactions occurring in the network bundles them into a block and feeds them to the SHA256 function to calculate their hashes, which is done by the CPU, GPU or ASIC Card. It works hand in hand with the Bitcoin wallet to keep the track of Bitcoins earned through mining.
A wallet: A wallet consists of a private key and a public key. The public key is used to accept the Bitcoins. In the case of a miner, it is used to accept the Bitcoins as a mining reward as well as the transaction fees included in the transactions. On the other hand, the private key is used to send the Bitcoins to someone. A wallet is generally stored in your computer, or on Web apps. But to maintain utmost safety, hardware wallets can also be used. A hardware wallet is nothing but a physical device, which stores the private and public key, and can be plugged into a computer via a USB port.
Optionally a miner can also join a pool to mine with other miners. This increases the chances of getting the mining rewards, as a large number of miners are mining at the same time. Any reward won is distributed in the pool to make sure everyone gets its share of the pie.