Bitcoin Mining – Creating a Tamper-Proof Cryptographic Fortress in Cyberspace

Bitcoin Mining

Gold mining and Bitcoin mining can be compared in that both involve extracting a valuable resource through specialized equipment and processes. While gold miners are digging for gold, bitcoin miners are digging for a very specific alphanumeric data string for which in turn they are rewarded with bitcoins.

The mining processes differ substantially from each other, and even though the incentive to mine is the reward of something valuable, the purpose of bitcoin mining goes far beyond the compensation of miners. Bitcoin mining is essential for securing the integrity of the entire bitcoin network.

Bitcoin Mining Incentives – Fueling a Trustless and Decentralized Network

Bitcoin mining is the process of verifying and adding transactions to the public ledger, known as the blockchain. The Bitcoin mining process is done by specialized computers called ASIC’s (Application-Specific Integrated Circuit) that try to solve a difficult yet feasible computational math problem. Once they are successful at that, they get to create a new block that is added to the blockchain and are rewarded with bitcoins for their efforts.

When bitcoin came into existence in 2009, miners were rewarded with 50 bitcoins per mined block. Approximately every 4 years the reward is halved. Today in 2023, the reward is at 6.25 bitcoins per validated block. In addition to the block reward, miners receive the transaction fees of the transactions that were settled with the new block.

The bitcoin mining rewards is halvening every 4 years.

Each new block contains a record of the most recent transactions and approximately every 10 minutes a new block is added to the blockchain. The entire blockchain record is stored on thousands of computers (nodes) all over the world, and once a new block is added, it is permanent and immutable. One little data change in the blockchain would be immediately detected and rejected by the network.

Bitcoin’s decentralized and trustless network, where transactions are verified and validated through mining, eliminates the need for intermediaries and parties to know and trust each other.

Bitcoin mining participants compete against each other, but can also collaborate in mining pools where they share their computing power and yield. It is in the best interest of all bitcoin miners to follow the protocol and validate the transactions honestly because no miner can improve his situation by deviating from the protocol and attempting fraud. In game theory, this is called the Nash equilibrium where the players involved do not improve their situation by changing their strategy.

Additionally, the Bitcoin protocol includes the consensus mechanism proof of work, which makes it difficult and costly for a miner to cheat and create invalid blocks.

Proof of Work – The Foundation of Bitcoin Mining

Since anyone can participate in Bitcoin mining, and trust is not required between network participants, a consensus mechanism is needed to regulate who can add the next block to the blockchain and receive rewards.

Satoshi Nakamoto’s solution to this problem was the implementation of proof of work, which requires miners to solve a cryptographic puzzle by finding a specific alphanumeric data string called a hash. This hash permanently links a new block to the existing blockchain and records the latest bitcoin transactions.

The proof of work mechanism ensures that miners must expend a significant amount of computing power and electricity to find the hash, which incurs significant costs. This process, combined with the competitive nature of mining, provides a robust, decentralized, and secure way to maintain and validate the blockchain.

Demystifying Hash Functions – Essential Algorithms for Bitcoin Mining

Since hash functions are an integral part of bitcoin mining, we have to understand how they work in order to understand bitcoin mining. Hash functions or hashes are very complex algorithms that turn any input of data into a fixed-length alphanumeric code.

One crucial characteristic of hash functions is that they are deterministic one-way functions that are irreversible by design. 

Deterministic means that whenever you input the exact same data, you will always get the exact same hash as an output. They are irreversible one-way functions, as they can only be calculated in one direction from input data to the hash. It is impossible to reverse the calculation and find out what the input data was by means of the hash. In contrast, encryption is a two-way function as it can be decrypted at a later point in time. 

There are a variety of hash types, but for bitcoin mining, the hash function SHA256 is used. SHA256 creates a 256 bits long hash for whatever data input:

Example: The data input “j” creates a 256 bits-long hash.

A SHA256 hash 1
Example The data input “j” creates a 256 bits-long hash.

Even minor variations in your input data result in entirely different hashes. Hence, hashes do not allow any conclusions to be drawn about similarities in the data input.

Example: “How are you today” and “How are you today?”

A SHA256 hash 2
Example: “How are you today”
A SHA256 hash 3
Example: “How are you today?”

Even if you input the data of an entire library, the resulting alphanumeric hash will still be only 256 bits long.

A SHA256 hash 4
Inputting an entire library’s data still results in a 256-bit alphanumeric hash.

You can play around with hash functions yourself here.

Bitcoin Mining Essentials – Block Formation, Mempool Transactions, and Cryptographic Challenges

So, now that we understand how hashes work, let’s examine their use in Bitcoin mining where the goal of the miner is to create a new block and link it to the existing blockchain.

A block is basically a dataset consisting mainly of transaction data. Bitcoin miners gather the transaction data from the mempool. A mempool (short for “memory pool”) is a data structure that each node on the Bitcoin network maintains to store all the unconfirmed transactions that it has received. It is the waiting room for an unconfirmed transaction until a miner chooses to include them in the next block. 

A block also contains a block header with important meta-data such as a magic number, block size limit, block header version, previous block hash, Merkle root, timestamp, the difficulty target (nBits), and nonce. Since the previous block hash, Merkle root, difficulty target, and nonce are particularly relevant for mining, let’s briefly explain their function.

  • Previous block hash: This is the hash of the previous block in the blockchain. In order to add a new block to the blockchain, miners must include the previous block hash in the current block header. This creates a cryptographic link between the new block and the previous block, which helps to ensure the security and immutability of the blockchain.
  • Merkle root: The Merkle root is a hash of all the transactions in the block. In order to mine a new block, miners must include a valid Merkle root in the block header. The Merkle root links the transactions and the block header and ensures that all the transactions in the block are valid and have not been tampered with.
  • Difficulty target: The difficulty target is a measure of how difficult it is to find a valid hash for the block. In order to mine a new block, miners must find a hash that is below the difficulty target. The difficulty target is adjusted every 2016 Blocks (around 2 weeks) to maintain a consistent block production rate. The adjustment is based on the overall network hashrate.
  • Nonce: The nonce is a random number that miners can adjust in order to try to find a valid hash for the block. 

After completing a block, the entire dataset undergoes a SHA256 hash function, generating a hash that is supposed to be placed in the header of the next block, creating a cryptographic link. However, to be acceptable, the hash’s value must be below a certain threshold (difficulty target), which translates into a hash that needs to have a certain number of leading zeros.

the difficulty target in bitcoin mining requires a hash to have leading zeros

Since hashes are deterministic, and the same dataset always results in the same hash, it is the nonce that introduces the variability to create new hashes. By changing the nonce value and hashing the dataset again, a new hash is generated. The 32-bit nonce, however, allows for approximately 4 billion iterations, when sextillions of calculations may be needed.

The limitations of the nonce are compensated by also changing the order of the transaction data, changing the timestamp, or adding an extra nonce. The latter is a random number added to the coinbase transaction, the first transaction in the block that distributes the mining rewards to the miners. Together, these variables allow for enough variations to find a hash that meets the requirements of the difficulty level.

Relentless Hashing aka Bitcoin Mining

The hashrate is the measure of computational power used in mining, expressed in hashes per second. A higher hashrate increases the chances of successfully mining a block. An increasing hashrate is counterbalanced with an increasing difficulty level to maintain the approximate time of 10 minutes to mine a block.

Overall the hashrate has increased substantially over time. In 2023, Bitcoin miners on average are producing hundreds of quintillions of hashes (ExaHashes) per second. On March 25, 2023, the hashrate reached an all-time high of 414.33 ExaHashes per second at block 782.408. With this hashrate, it would take an average of 248.598 ZettaHashes (ZH) or 248.598 sextillion hashes to mine a block, assuming an average mining time of 10 minutes.

The calculation is as follows: Hashes per block = 414.33 EH/s * 600 seconds per block → Hashes per block = 248,598 EH. Since 1 ZettaHash (ZH) equals 1,000 ExaHashes (EH) and 1 sextillion equals 1,000 quintillions, 248,598 EH translates to 248.598 ZH or 248,598,000,000,000,000,000,000 hashes.

You don’t need to be a math whiz to understand that we’re talking about a mind-bogglingly large number of computations here.

a list of values to represent the hashrate per second.

Building an Ever-Growing Protective Wall of Cryptographic Security

As we know hashes are deterministic and cryptographically interlink all blocks in the blockchain. This means that even a tiny change in one block will result in a different hash, rendering all subsequent blocks and their hashes invalid.

One data change in one block, breaks the link of all subsequent blocks in the bitcoin blockchain

So, manipulating a transaction in the past would require recalculating not only the block with the transaction but also all subsequent blocks and their hashes. This is an extremely computationally intensive task that would require a gigantic amount of energy, and even with the hypothetical advent of future quantum computers, such an alteration would still not be accepted by the network.

In the Bitcoin mining process, in order for a block to be added to the blockchain, it must meet certain requirements, including proof of work and adherence to consensus rules, which are enforced by the network’s nodes.

Any block that does not meet these requirements will be rejected by the network, and any changes to the blockchain must be accepted by the majority of the network’s nodes in order to be considered valid.

Therefore, even if someone were able to alter a transaction and recalculate the entire blockchain, the new version of the blockchain would not be recognized by the network unless it was able to gain majority acceptance among the nodes. This makes it extremely difficult, if not impossible, to modify transactions that have already been confirmed and recorded in the blockchain.

In summary, Bitcoin mining creates an anchor in the physical world by requiring miners to convert real-world energy into computational power. This process follows the laws of physics and creates a highly secure and tamper-proof cryptographic fortress in cyberspace that becomes increasingly difficult to penetrate as bitcoin mining continues.