Mining helps to secure cryptocurrency networks by making it more difficult for attackers to manipulate the blockchain. When proposing a new block, a miner must solve a computationally demanding mathematical challenge and provide proof of work (PoW)—proof they have solved the challenge. Cryptocurrencies that rely on mining are often called PoW cryptocurrencies.
Mining was a key innovation that made early cryptocurrencies possible. Although developers have created alternatives to mining and PoW algorithms in recent years, crypto mining remains a central aspect of Bitcoin and numerous other cryptocurrencies.
In this article, we explore:
Why crypto miners mine.
How mining secures and synchronizes a distributed, decentralized currency.
The crypto mining process.
Alternatives to mining, including staking and proof-of-stake algorithms.
What Motivates Crypto Miners?
Miners mine because they are rewarded cryptocurrency for helping a crypto network validate transactions and add new blocks to its blockchain. The reward varies over time and between cryptocurrencies, but Bitcoin (BTC) is a useful example. At the time of writing, a miner who successfully adds a block to the Bitcoin blockchain receives a 6.25 BTC block reward and fees for the transactions included in the block.
The block reward is made up of new bitcoins created when the block is accepted by the network. On the Bitcoin network, all coins have been created as block rewards for mining. The only exception is the first bitcoins created in the first block, the genesis block.
The number of bitcoins in the block reward goes down over time. In 2009 when the first coins were mined, the Bitcoin block reward was 50 BTC. The reward halves for every 210,000 blocks added, which takes about four years. In 2012, the reward halved to 25 BTC, in 2016 to 12.5, and in 2020 to 6.25. Eventually, when the number of bitcoins reaches the predetermined maximum of 21 million, the block reward will drop to zero, and no more coins will be mined. However, miners will continue to receive transaction fees for validating blocks.
Other cryptocurrencies that use mining and PoW have similar reward systems, but the reward, the mining process, the format of blocks and transactions, and other details may differ.
From the miner’s perspective, the reward is the point of mining. But from the cryptocurrency network’s perspective, the reward is just an incentive. It exists to motivate miners to do what really matters to the blockchain: validating transactions and proposing new blocks.
What Is The Point of Crypto Mining?
Cryptocurrencies are based on decentralized, peer-to-peer networks that use a blockchain distributed ledger to store transaction data. There is no central authority to check the validity of transactions and approve them for the official record. Instead, cryptocurrencies need a decentralized way to validate transactions and add them to the blockchain.
A PoW cryptocurrency network is made up of many independent nodes. Some of those nodes are miners, and their job is to collect transactions from the network, validate them to prevent double-spending and other fraudulent activity, package them into a block, and distribute the block to the network. Other nodes then validate the new block, add it to their blockchain, and share it with more nodes. Eventually, the blockchain with the new block added becomes the canonical version.
The above explanation misses one detail. A valid block must also contain a PoW demonstrating the miner has done a certain amount of computational work. We’ll explain the PoW challenge in the next section, but you might wonder why it’s necessary at all. It’s important to understand that a PoW mechanism isn’t processing information useful to the cryptocurrency’s operation. The computation’s results are irrelevant, provided they prove work has been done. So why force miners to prove they have done the work?
Making it hard to create a legitimate block also makes it hard to create a fraudulent block. There are many reasons a bad actor might want to cheat the system. They might want to spend the same coins twice or award themselves coins they haven’t earned. If proposing blocks were free, a malicious individual could set up lots of miners to create and validate their preferred blocks, gaining an outsized influence over the network. This type of malicious behavior is called a Sybil attack.
A PoW mechanism makes it unfeasibly expensive—so expensive it’s technically and financially impossible on a large network like Bitcoin—to subvert the network in this way. A block without a PoW cannot be valid; every other node would reject it immediately. So an attacker would have to provide a PoW for every block they create with their malicious nodes. Additionally, if an attacker wanted to change an earlier block in the blockchain, they would have to replicate all the computational work done from the block’s addition to the present time. In both cases, the cost would be astronomical.
In summary, crypto mining is the process by which cryptocurrencies validate transactions and add new blocks to the blockchain. The PoW mechanism disincentives disruptive and fraudulent behavior by making it prohibitively expensive.
The Crypto Mining Process Explained
We’ve seen why crypto miners mine, but what is involved in mining? We’ll use Bitcoin as a case study again because it’s the oldest and arguably the most influential cryptocurrency. Most PoW cryptocurrencies work similarly, although the details may differ.
What Do Crypto Miners Do?
A cryptocurrency mining node is a computer connected to other nodes in the currency’s network. It runs the network’s client software and may also be connected to custom hardware that specializes in solving the PoW challenge. A miner carries out the following jobs.
Accepting transactions from the network. [Text Wrapping Break]Other nodes on the network broadcast transactions, which the mining node listens for. It validates each transaction by verifying they are correctly signed, aren’t attempting to double spend, are formatted properly, and so on.
Downloading the blockchain. [Text Wrapping Break]A mining node maintains an up-to-date copy of the blockchain, which it downloads from other nodes. It also downloads and verifies new blocks as they are broadcast.
Creating new blocks. [Text Wrapping Break]To begin mining, a node takes the transactions it has collected and validated and groups them into a new block. The miner works on a specific block. At the time of writing, there are 771,452 blocks on the Bitcoin blockchain, also known as the block height, so miners are currently working on the 771,453rd block.
Finding a PoW solution. [Text Wrapping Break]Before the block is valid, the miner must find a solution to the PoW challenge. There is no guarantee that it will be successful before another miner finds a solution and shares a valid block with the network.
Broadcasting the new valid block to the network. [Text Wrapping Break]Once it finds a PoW solution, the miner has a valid block it can pass on to other nodes for validation and inclusion in the blockchain. Other nodes will not accept the block if they have already received a valid block from a different miner with the same block height, so it’s not certain that our miner’s block will be accepted.
Receiving the blockchain reward. [Text Wrapping Break]Once the new block is widely accepted, the miner benefits from the blockchain reward.
While the miner works through this process, it listens for valid blocks from other miners. If it receives block number 771,453, it validates it, adds it to the end of its blockchain, and abandons work on that block. It has been gathering new transactions in the meantime, so it immediately starts work on the next block. A new block is added to the Bitcoin blockchain every ten minutes or so.
The Anatomy of a Blockchain Block
A blockchain block is a chunk of data in a specific format. Most importantly, it includes validated transactions. The number of transactions may vary, provided they don’t make the block bigger than the blockchain’s maximum block size. In addition to the transactions it has collected, the miner adds another transaction to the block in the first position. This is the coinbase transaction, which creates the block reward and sends it and the transaction fees to the miner’s blockchain address.
The block also includes a block header containing metadata, such as:
A cryptographic hash pointing to the previous block.
The time the block was created.
A data field known as the nonce.
A target number for the PoW algorithm.
A Merkle root.
Note: The following assumes you have a basic understanding of cryptographic hash functions. If you need a refresher, look at the Cryptographic Hash section in What is a Blockchain and How Does It Work?
The nonce field and the Merkle root play a part in the PoW process. The nonce field isn’t especially interesting; it’s just a data field into which the miner can put a number. The Merkle root is more intriguing. When a miner creates a block, it also creates a Merkle tree, a binary hash tree used to make sure transactions haven’t been changed or reordered, among other uses.
To visualize a Merkle tree, imagine a list of transactions. The miner generates a cryptographic hash of each one. It then combines adjacent hashes and creates a new cryptographic hash of the combined pairs, resulting in half as many as in the previous step. It repeats this operation until it has a single hash, the Merkle root.
Any change in the transactions will produce a different Merkle root. When a node wants to verify a transaction hasn’t been altered, it can take a subset of the hash tree (known as a Merkle proof) and carry out a few hashing operations, producing a new Merkle root. It can compare the new root to the Merkle root in the block header. If a transaction has been altered, the Merkle roots won’t match.
Merkle trees are useful for verifying block contents, ensuring block data hasn’t been tampered with, and reducing the block header size—only the root needs to be included for verification. They also play a role in mining, as we’ll see in the next section.
Proof of Work in More Detail
The point of a PoW mechanism is to ensure every new block represents time and work carried out by the miner. This could be achieved in many ways, but Bitcoin and other cryptocurrencies use cryptographic hash functions. Simply put, the miner is given a number, and it has to generate a hash of the block header smaller than that number.
A hash function takes a chunk of data and outputs a number. The number is always the same length, and small differences in the input produce large differences in the output. For example, if you use “Bittrex” as the input to the SHA256 hashing algorithm, it will produce the following hash (represented in hexadecimal).
If you used a block header as input, it would produce a different number of the same length. If you changed a transaction in the block, the output would be different again (because you would also have to update the Merkle tree and therefore the Merkle root field).
Different inputs create a different output.
Different inputs cannot create the same output.
The same input always creates the same output.
Now for the most important point: there’s no way to reverse the hashing process. You can’t start with a hash and work your way back to the input.
When a miner is given the task of finding a hash lower than a particular number, it can’t pick a low number and then figure out which data would produce it. It has to make changes to the block header, hash it, and see whether the hash is lower than the target. It must keep doing so until the output is suitably low.
This is where the nonce comes in. One way to change the block header is to alter the data in the nonce field—the other fields are fixed. Remember, a small change in the hash function input produces a large and unpredictable change in the hash output. Miners typically increment through every available value in the nonce field until they find one that produces a hash lower than the target. How many values is that? Bitcoin has a 32-bit nonce, so the biggest number it can fit is 2³² or 4,294,967,296 values.
However, the miner will often try every one of those values without generating a suitable hash. It has to find something else to change, and the usual candidate is a nonce field in the coinbase transaction, the transaction created by the miner for its reward. When the coinbase transaction changes, the Merkle tree has to be recalculated, resulting in a different Merkle root in the block header. Then, the miner can iterate through the four billion header nonce values once again. If it still doesn’t find a suitable hash, it can tweak the coinbase nonce again, recalculate the Merkle tree, and repeat the whole process as many times as it takes.
A miner might end up carrying out many trillions of hashing operations before it finds a suitable hash to make its block valid and that demands serious computing power. It’s worth remembering that many miners are competing to add blocks at the same time, and they’re all going through the same process. The total number of hashes calculated across the entire Bitcoin network is staggeringly large. The precise number is unknowable, but a safe estimate is in the region of at least 1019 hashes per second. In more easily understood terms, that’s ten quintillion or ten million trillion hashes per second.
How do cryptocurrencies decide which number is the target for their PoW process? Earlier, we said new blocks are added about every ten minutes to the Bitcoin blockchain. That’s not accidental. PoW difficulty increases over time to ensure it takes about ten minutes.
How is the difficulty increased? By reducing the target number. If the target number is high, it’s easier to find a lower hash; it would require fewer hashing operations. So, over time, the number is lowered so that building a valid block takes approximately the same amount of time, even though there are more miners using more sophisticated equipment.
Crypto Mining Alternatives
Crypto mining is an elegant consensus mechanism for building distributed cryptocurrencies, but it also consumes massive computing resources and, therefore, huge amounts of power. It’s estimated that Bitcoin alone consumes 110 Terawatt Hours per year. That’s about 0.55% of the world’s global energy production, as much as a small country.
Proof of Stake (PoS) is an increasingly popular low-energy alternative used by Ethereum and many other cryptocurrencies. In PoS, instead of carrying out work, nodes stake a quantity of cryptocurrency as collateral. Nodes are rewarded if they propose valid blocks and stand to lose their collateral if they misbehave, so they are motivated to propose and validate new blocks properly. You can learn more about PoS in What is Crypto Staking and How Does It Work?
How to Buy PoW Cryptocurrencies
If mining seems like a lot of work, it’s good to know that trading cryptocurrencies is much easier. Bittrex makes creating an account and beginning to trade as straightforward as possible.
Complete your profile.
Verify your identity. Identity verification protects our platform and users from fraud and ensures we comply with Know-Your-Customer (KYC) regulations.
Deposit funds. You can deposit dollars via a wire transfer or deposit cryptocurrencies from your wallet.
The post appeared first on Bittrex.com - The Next Generation Crypto-Currency Exchange.