Cryptocurrency mining is the process of producing new coins and distributing them to the circulation. Moreover, it is also validating and verifying transactions. The work done by miners involves a huge computational power to keep the chain secure. Successful miners receive rewards for their hard work from newly created coins and transaction fees.
Why is mining important and what is double-spending
Miners are responsible for creating new coins and keeping blockchain secure. They validate new transactions which after that are added to the chain. Decentralization in blockchain could allow fraudsters to spend cryptocurrencies more than once if no one validated transactions. Mining reduces the chances to make double-spending happen.
Double-spending is the risk that the same unit of cryptocurrency might be sent more than once. When a block is created, it receives a hash - an encrypted number that contains information about the block like timestamp, information about the previous block, and transaction data. To create a hash, Bitcoin uses a security protocol called SHA-256.
Once the block is created and added to the chain, there is no possibility to come back to it and change or delete it. It is saved forever in the particular blockchain. If somebody wanted to do a double-spending attack, he would have to mine a block that outpaces the creation of the real one. What is more, they would have to add it to the chain before it caught up. The network would recognize it as the newest block, a miner who has done the attack could give himself back any cryptocurrency they had.
A blockchain minimizes the risk of a double-spending attack, it is too fast for accepting the modified block. The network of bitcoin is verified by thousands of computers all around the world that agree on one version of each block. Even if a suspicious block was created, the network would reject it.
The most harmful attack on the blockchain is called a 51% attack. That can occur if a miner has more than 50% computational power of the whole network that validates and verifies transactions. If someone controls a majority of the cryptocurrency mining, he would be able to control transactions, and awards for block mining. That kind of attack is possible but not feasible. Actually, it is not profitable to do that, because of the costs of mining equipment and electricity. So, it is better to be a fair miner.
Using simple words, a hash is an encrypted ID of a block or transaction, the input (block data) may have any length, but the output (hash) has always a fixed length. No matter how much data or file size is involved, the hash will always be the same size. There is no probability that two different datasets will reach the same hash value. Even a slight difference changes that. Moreover, a hash is a one-way encryption, it is not possible to derive the original items hashed from the hash value. Can you make potatoes out of mashed potatoes? Each block hash contains a hash of the previous block, a list of transactions, and nonce which is the number defining the difficulty of mining the block. Bitcoin uses the Secure Hashing Algorithm (SHA-256). For instance, hash for the word “Bitcoin” is: b4056df6691f8dc72e56302ddad345d65fead3ead9299609a826e2344eb63aa4, but for “bitcoin” it is: 6b88c087247aa2f07ee1c5956b8e1a9f4c7f892a70e324f1bb3d161e05ca107b.
You can create a hash for any data here.
How are blocks created and what is a merkle tree?
A miner node collects transactions and adds them to the memory pool to verify, validate and assemble them into the block. First of all, each transaction in the memory pool must be hashed. Before that, a node adds a transaction where they send themselves a mining reward, it is called a Coinbase transaction, that’s usually the first transaction of the block. When all transactions are hashed, they are organized into a merkle tree. Hashes of transactions are linked in pairs, and hashed again until the top of the tree is reached, called a root hash. Using simple words, until there are no pairs left. Then, the hash of the previous block, root hash, and nonce are placed into the block’s header which is hashed and is the block's identifier. The block header hash must start with a certain number of zeros. So, miners are looking for the nonce which is a number that miners need to create a correct hash. When a valid hash is found, a block can be broadcasted to the network.
What happens if miners broadcast two blocks at the same time?
Miners are looking for the next block based on the first they received. Then, the competition between the two blocks starts. When the next block is mined, the block that came before it is added to the chain. The block which lost the competition is called an orphan block. The miners of this block will go back and change that to the winner block.
What are mining pools?
As we already know, the first successful miner receives a reward for his hard work. However, miners with a small percentage of mining power have relatively lower chances to mine a block. Mining pools are a solution to this. Mining pools are groups of miners that combine their power to increase the probability of mining a block. When they successfully find a block, miners will split the reward among all members, according to the amount of work.
Proof of Work
Proof of Work (PoW) is a consensus mechanism introduced in 2008 by Satoshi Nakamoto. You can read more about Satoshi and Bitcoin’s creation in the article What is bitcoin? PoW is used in for example Bitcoin and Ethereum blockchain. PoW describes how miners reach consensus in the blockchain without any third party. As we mentioned earlier, miners compete by solving complex mathematical puzzles. The first miner to find a correct solution and broadcast the block to the chain is rewarded a certain number of coins.
Proof of Stake
Proof of Stake (PoS) is a consensus mechanism introduced in 2011 as an alternative to Proof of Work. PoS does not require using computing power as it is in PoW, so it reduces the demand for energy. Binance Coin, Solana, Cardano, and many more blockchains work on Proof of Stake. Both mechanisms have the same goal - to validate and verify transactions, to create a block and to secure the network. However, PoS has a completely different way of that process. There are no miners. The whole process relies on your holdings rather than the computing power. Participants (anyway sometimes called miners) must lock a certain number of coins in the smart contract. This is called staking. The more funds you stake, the more chances for rewards you have.
What is Bitcoin halving?
Halving is the situation in the bitcoin blockchain when rewards for creating a block halve. That occurs every 210,000 blocks, so roughly every 4 years. When bitcoin was created in 2008, the reward was equal to 50 BTC, since 2012 it was 25 BTC, 4 years later miners were earning 12 BTC for a mined block, and now they do 6.25 BTC. The same in the following years, by 2024, the reward will be 3.125 BTC and so on… The last bitcoin will be mined in 2140 when the reward will be equal to 0.00000001 BTC, what would be a reward then if there are no more bitcoins to mine? Nowadays, rewards for mining are not only from creating the block, but also transaction fees. After all the bitcoins are mined, miners will earn them from transaction fees only.
Mining is a process that cryptocurrencies would not exist without. It keeps the network secure and verifies each transaction. The most obvious benefit of mining is receiving a block reward. However, it can be affected by various factors like costs of electricity and mining equipment, so it is possible not to make profits from mining.