What Is Cryptocurrency Mining? Mining difficulty adjustment

Join Uniluanch to find out “What Is Cryptocurrency Mining? How does mining work? Mining difficulty adjustment” in blockchain through the article below.

Cryptocurrency mining refers to the process of verifying and validating blockchain transactions. It’s also the process that creates new units of cryptocurrencies. The work done by miners requires intensive computational resources, but it’s what keeps a blockchain network secure. Honest and successful miners are rewarded for their work with newly created cryptocurrencies plus transaction fees.

Introduction Cryptocurrency Mining

Mining is the process in which cryptocurrency transactions between users are verified and added to the blockchain public ledger. The mining operations are also responsible for introducing new coins into the existing circulating supply.

Mining is one of the key elements that allow the Bitcoin blockchain to work as a distributed ledger. All transactions are recorded in a peer-to-peer network without the need for a central authority. In this article, we will discuss mining as it happens on the Bitcoin network, but the process is similar in altcoins that adopt the same mining mechanism.

Related: What is Byzantine Fault Tolerance (BFT) Explained in Blockchain?

How does mining work?

As new blockchain transactions are made, they are sent to a pool called a memory pool. The job of a miner is to verify the validity of these pending transactions and organize them into blocks. You can think of a block as a page of the blockchain ledger, in which several transactions are recorded (along with other data).

More specifically, a mining node is responsible for collecting unconfirmed transactions from the memory pool and assembling them into a candidate block. After that, the miner will try to convert this candidate block into a valid, confirmed block. But to do so, they need to find a solution for a complex mathematical problem. This requires a lot of computational resources, but every successfully mined block will give the miner a block reward, consisting of newly created cryptocurrencies plus transaction fees. Let’s take a closer look at the mining process.

Step 1 – Hashing transactions

The first step of mining a block is to take pending transactions from the memory pool and submit them, one by one, through a hash function. Every time we submit a piece of data through a hash function, we will generate an output of fixed size called a hash. In the context of mining, the hash of each transaction consists of a string of numbers and letters that works as an identifier. The transaction hash represents all the information contained within that transaction.

Apart from hashing and listing each transaction individually, the miner also adds a custom transaction, in which they send themselves the block reward. This transaction is referred to as the coinbase transaction and is what creates brand new coins. In most cases, the coinbase transaction is the first to be recorded in a new block, followed by all the pending transactions that they want to validate.

Step 2 – Creating a Merkle Tree

After every transaction is hashed, the hashes are then organized into something called a Merkle Tree. Also known as a hash tree, the Merkle Tree is formed by organizing the transaction hashes into pairs and then hashing them. The new hash outputs are then organized into pairs and hashed once again, and the process is repeated until a single hash is created. This last hash is also called a root hash (or Merkle root) and is basically the hash that represents all the previous hashes that were used to generate it.

Step 3 – Finding a valid block header (block hash)

A block header works as an identifier for each individual block, meaning that each block has a unique hash. When creating a new block, miners combine the hash of the previous block with the root hash of their candidate block to generate a new block hash. But apart from these two elements, they also need to add an arbitrary number called nonce.

Finding a valid block header (block hash)

So, when trying to validate their candidate block, a miner needs to combine the root hash, the previous block’s hash, and a nonce and submit them all through a hash function. Their goal is to create a hash that is considered valid.

The root hash and the previous block’s hash can’t be changed, so miners need to change the nonce value several times until a valid hash is found.

In order to be considered valid, the output (block hash) must be less than a certain target value, which is determined by the protocol. In Bitcoin mining, the block hash must start with a certain number of zeros. This is what we call mining difficulty.

Step 4 – Broadcasting the mined block

As we’ve just seen, miners need to hash the block header over and over again, with different nonce values. They repeat this work until they find a valid block hash. The miner that found it will then broadcast his block to the network. All other nodes will check if the block and its hash are valid and, if so, add the new block into their copy of the blockchain.

At this point, the candidate block becomes a confirmed block, and all miners move on to mining the next one. All miners that couldn’t find a valid hash on time discard their candidate block, and the mining race starts over.

Mining difficulty adjustment

The mining difficulty is regularly adjusted by the protocol, ensuring that the rate at which new blocks are created remains constant. This is what makes the issuance of new coins steady and predictable. The difficulty adjusts in proportion to the amount of computational power (hash rate) devoted to the network.

As such, every time new miners join the network and competition increases, the hashing difficulty will rise, preventing the average block time from decreasing. In contrast, if many miners decide to leave the network, the hashing difficulty will go down, making it less difficult to mine a new block. These adjustments keep the block time constant, regardless of the total hashing power of the network.

What if two blocks are mined at the same time?

It sometimes happens that two miners broadcast a valid block at the same time and the network ends up with two competing blocks. Miners then start to mine the next block based on the block they received first. This causes the network to split (temporarily) into two different versions of the blockchain.

The competition between these blocks will continue until the next block is mined, on top of either one of the competing blocks. When a new block is mined, whichever block that came before it will be considered the winner. The block that gets abandoned is called an orphan block or a stale block, leading all miners that picked this block to switch back to mining the chain of the winner block.

Can all cryptocurrencies be mined?

Bitcoin is the most popular and well-established example of a mineable cryptocurrency, but not all cryptocurrencies are mineable. Bitcoin mining is based on a consensus algorithm called Proof of Work (PoW).

Proof of Work (PoW)

Proof of Work (PoW) is the original blockchain consensus mechanism created by Satoshi Nakamoto. It was introduced in the Bitcoin whitepaper, back in 2008. In a nutshell, PoW determines how a blockchain network reaches consensus across all the distributed participants without third-party intermediaries. It does this by requiring significant computing power to disincentivize bad actors.

As we’ve seen, transactions on a PoW network are verified by miners. In order to win the right to mine the next block, miners compete by solving complex cryptographic puzzles with specialized mining hardware. The first miner to find a valid solution can then broadcast their block of transactions to the blockchain, and receive the block reward.

The amount of crypto in a block reward varies across different blockchains. For example, on the Bitcoin blockchain, miners can get 6.25 BTC in block reward as of December 2021. The amount of BTC in a block reward decreases by half every 210,000 blocks (approximately every four years) due to its halving mechanism.

What Is Cryptocurrency Mining?
What Is Cryptocurrency Mining?

Different cryptocurrency mining methods

There is no single method for mining cryptocurrencies. The equipment and process changes as new hardware and consensus algorithms emerge. Typically, miners use specialized computer units to solve the complicated cryptographic equations. Let’s take a look at how some of the most common mining methods work.

CPU mining

Central Processing Unit (CPU) mining involves using a computer’s CPU to perform the hash functions required by PoW. In the early days of Bitcoin, the cost and barrier to entry for mining was low. The difficulty of mining could be handled by a regular CPU, so anyone could try to mine BTC and other cryptocurrencies.

However, as more people began to mine and the network’s hashrate increased, profitable mining became more and more difficult. On top of that, the rise of specialized mining hardware with greater computational power eventually made CPU mining nearly impossible. Today, CPU mining is no longer a viable option, as all miners use specialized hardware.

GPU mining

Graphics Processing Units (GPU) are designed for processing a wide range of applications in parallel. While they’re typically used for video games or rendering graphics, they can also be used for mining.

GPUs are relatively cheap and more flexible than the popular ASIC mining hardware. Some altcoins can be mined with GPUs, but the efficiency depends on the mining difficulty and algorithm.

ASIC mining

An Application-Specific Integrated Circuit (ASIC) is designed to serve a single specific purpose. In crypto, It refers to specialized hardware developed for mining. ASIC mining is highly efficient but expensive.

Mining is a competition. To mine profitably, you need competitive mining hardware. As ASIC miners are at the cutting-edge of mining technology, the cost of a unit is much higher than CPUs or GPUs. Also, continuous advancements in ASIC technology quickly render older ASIC models unprofitable, meaning that they often need to be replaced. This makes ASIC mining one of the most expensive ways to mine, even without including electricity costs.

Mining pools

As a block reward is granted to the first successful miner, the probability of finding the correct hash is extremely small. Miners with a small percentage of the mining power stand a very small chance of discovering the next block on their own. Mining pools offer a solution to this problem.

Mining pools are groups of miners who pool their resources (hash power) to increase the probability of winning block rewards. When the pool successfully finds a block, miners will split the reward equally among everyone in the pool, according to the amount of work contributed.

Mining pools can benefit individual miners in terms of hardware and electricity costs, but their domination in mining raises concerns for a 51% attack on the network.

Closing thoughts

Cryptocurrency mining is a crucial part of Bitcoin and other PoW blockchains. It’s one of the things that keep the network secure and the issuance of new coins steady. Mining has certain benefits and drawbacks, the most obvious being the potential earnings you get from the block rewards. However, mining profits can be affected by a number of factors, including electricity costs and market prices. There is no guarantee that you will make profits, so before you jump into crypto mining, you should DYOR and evaluate all potential risks.

Source: Binance.com