© 2024 Kishan Kumar. All rights reserved.

What does Hashrate mean in the Bitcoin Network?

Hashrate is a measure of the computing power of a network that uses the Proof-of-Work (PoW) consensus mechanism, such as Bitcoin.

Jun 18, 2023


Note: This article was last updated on April 03, 2024.

If you are active on Twitter, you often see tweets like the Bitcoin network is at its all-time high Hashrate. A tweet like this:

These numbers are stupendously large. At the time of writing, the hashrate is 391.96 EH/s or 391,958,260,757,078,500,000 H/s.

These numbers will only make sense if you know what hashrate is and what it means in the context of the Bitcoin network. In this article, I'll explain it using examples so that by the end of this article, you'll be able to make sense of it.

If I ask you what 5 * 5 is, and you take 1 sec to answer me, you can solve one math problem per second. Does that make sense?

What if I gave you the following mathematical problems, and how long did it take you to answer me?

  • 23 * 7, 2.5s
  • 5 * 5, 1s
  • 1 * 9, 0.5s
  • 4 * 40, 1s
  • 13 * 15, 5s
Total questions asked = 5
Total time taken = 10s (2.5 + 1 + 0.5 + 1 + 5)

Suppose someone asks me how many mathematics problems you solved in 1 second. Using the Unitary method, we'll come up with 5 / 10 = 0.5 maths/sec.

Please keep this analogy in mind. This will help us understand the hashrate. Now let's explain what a hashrate is:

Hashrate is a measure of the computing power of a network that uses the Proof-of-Work (PoW) consensus mechanism, such as Bitcoin. It indicates how many times per second the miners can attempt to solve a mathematical puzzle that validates transactions and creates new blocks.

Now using our analogy, consider yourself a miner and the puzzle as the mathematical problem I gave you. We do not measure it as maths/sec because that'll be hilarious.

Hashrate is usually measured in hashes per second (H/s) or multiples of it, such as kilohashes per second (KH/s), megahashes per second (MH/s), gigahashes per second (GH/s), terahashes per second (TH/s), petahashes per second (PH/s), and exahashes per second (EH/s). We'll soon understand why one is using the term hash.

Hell yeah. To the Moon.

Does an increase in hashrate makes the network secure?

The higher the hashrate, the more secure and efficient the network is. A high hashrate means that more miners are competing to solve the puzzle, making it harder for anyone to attack or manipulate the network by creating a long chain of blocks that overrides the existing one. To do so, an attacker would need to have more than 50% of the network's total hashrate, which is very unlikely and expensive.Therefore, a higher hashrate means higher trust and confidence in the network. It also means the network can process more transactions faster and with lower fees.

Hashrates aren't constant; they fluctuate depending on various factors, such as the number and performance of miners, the puzzle's difficulty, the price and profitability of the cryptocurrency, and external events such as regulations, hacks, or forks.

When the hashrate increases, this means more miners are joining the network or upgrading their equipment. This makes the network more secure and faster but also increases the puzzle's difficulty, which requires more energy and resources from the miners. When the hashrate decreases, it means that some miners are leaving the network or reducing their activity. This makes the network less secure and slower but also decreases the puzzle's difficulty, making it easier and cheaper for the remaining miners to mine.

What are the miners solving?

In our example, you were solving simple arithmetic. Do miners solve that only? No, miners solve way complex problems or puzzles.

Miners be Mooooo

The Puzzle

I'll simplify this puzzle using our simple arithmetic example. If I say, can you find the value x that satisfies 2 * x = 100 without using any division operation? All you are required to do is hit and trial.

How will you go about this problem?

Well, you can try every number and see if it holds equality. Such as, you'll begin a loop and first put x = 1, then 2, 3, 4, 5, 6.. and so on, until you hit x = 50. At that point, the equation will hold the equality, and the solution to the above problem will be 50.

If you took one second for each step, i.e., 2 * 1 = 2 (1s), 2 * 2 = 4 (1s), 2 * 3 = 6 (1s), and so on.

How many seconds would it take you to find the answer?

Of course, 50s, because each operation took 1s.

Our miners solve something similar.

A mathematical puzzle miners must solve is a one-way function that takes an input and produces an output that meets specific criteria.For example, in Bitcoin, the input is the block header, which contains information such as the previous block hash, the transactions in the block, and a random number called a nonce. The output is the block header's hash, which is a fixed-length string of alphanumeric characters.

To compute the hash, the miner has to use a hash function, which is a mathematical algorithm that maps any input to an output of a fixed size. For example, Bitcoin uses the SHA-256 hash function, which produces a 256-bit output.

A hash function has the property that it is easy to compute the output given the input but hard to find the input given the output.

The puzzle miners have to solve is finding a nonce (a random number) that makes the block header's hash start with a certain number of zeros. The number of zeros required depends on the network's difficulty, which adjusts every 2016 block to keep the average time between blocks at 10 minutes. The more zeros are needed, the harder it is to find a valid nonce.

To solve the puzzle, miners must try different nonces until they find one that produces a valid hash. This process is essentially guessing and checking and requires a lot of computational power. The first miner who discovers a valid nonce gets to add the block to the blockchain and claim the block reward and transaction fees.

Let's ask a few more questions. In proof of work, suppose one miner finds the nonce that produces the required zeros at the beginning and broadcasts the result to the network to prove it. Now, let's say another miner also found the same solution. How will the Bitcoin network decide to whom the block reward should go?

Who gets to keep the Reward?

In the Bitcoin network, when multiple miners find a valid solution (i.e., a valid nonce) for a block at approximately the same time, it creates what is known as a "fork" in the blockchain. I have written a dedicated article on Forking, if you are curious to know you can read it here . This fork represents a temporary divergence in the blockchain where different parts of the network have conflicting views on which block should be considered the next valid block.

However, only one of these blocks will ultimately become part of the longest chain, which is considered the valid blockchain. This is because Bitcoin follows the rule that the longest valid chain is the one accepted by the network. When a miner finds a block, they broadcast it to the network, and other miners start mining on top of it, effectively extending the chain. Whichever chain becomes the longest first (due to having the most computational work put into it) will be accepted by the network as the valid chain, and the other fork will be discarded.

As for the block reward, it will be given to the miner whose block becomes part of the longest chain. The reward is only received when the block is included in the longest valid chain, so miners have an incentive to ensure that their blocks are accepted by the network as quickly as possible. If multiple miners find valid solutions simultaneously, it essentially comes down to chance and the random nature of mining. The miner whose block propagates through the network fastest and is included in the longest chain first will receive the block reward, and this is one of the biggest reason why Bitcoin mining wastes so much energy and time.

Could another miner potentially receive the block propagated by the miner who discovers the solution, and then swiftly propagate their own block with the same result, thus winning without performing any additional computation?

You might be expecting a No answer right? But unfortunately, the answer is Yes. This scenario is known as a "race condition" in the context of blockchain mining.

In such a scenario, if the second miner manages to propagate their block faster through the network than the original miner, and if their block gets included in the longest chain first, then they would indeed receive the block reward without having done any additional computation themselves. This is because Bitcoin's consensus mechanism primarily relies on the longest valid chain, not on the effort expended by individual miners.

However, it's important to note that such occurrences are relatively rare and depend on various factors such as network latency, the speed of block propagation, and chance. Miners generally aim to minimize the likelihood of such scenarios by optimizing their network infrastructure and connectivity to maximize the chances of their blocks being included in the longest chain. Additionally, the reward for successfully mining a block includes not just the newly minted bitcoins but also transaction fees, so miners have incentives to actively participate in the mining process rather than rely solely on race conditions. Okay, let's get back to our original discussion on hashrate.

Confused? Don't worry; I'll try to clear the smoke.

Let's assume the block data is as follows. It contains information about transactions made by people.

2  "nonce": 1,
3  "prevhash": "232975iocsbc2984590zhdfkekro00kqabfosrf8349109",
4  "timestamp": 1687029267,
5  "transactions": [
6    {
7      "from": "alice",
8      "to": "kishan",
9      "amount": 1
10    },
11    {
12      "from": "bob",
13      "to": "mathew",
14      "amount": 0.1
15    }
16  ]
If we pass this data to our hash function SHA256(block data), we'll get the following output:

You can verify it yourself by copying the above data and pasting it to an online SHA256 function such as Online SHA-246

But what if I told you this differs from the output I am looking for? It starts with two zeros in front. Such as:
Note: the only thing matters is the two zeros; the following values can differ.

What will you do?

The only thing you can change in the block data is nonce; others can't change. So you'll put nonce = 2 (just like we changed the value of x).

Let's try with nonce: 2; we again put it in the SHA256 function and wait for the output. The output is:

We check the first two digits are still not 0s. We change it to 3, 4, 5, and so on.

I've written a simple Java program to help you find the nonce. All it needs is the block data and how many zeros you expect it to have in the output. You can copy the file content from here: SHA256 Example

1import java.io.ByteArrayOutputStream;
2import java.io.IOException;
3import java.io.ObjectOutputStream;
4import java.io.Serializable;
5import java.security.MessageDigest;
6import java.security.NoSuchAlgorithmException;
8public class Main {
10    static class BlockData implements Serializable {
11        int nonce;
12        String prevhash;
13        long timestamp;
14        Transaction[] transactions;
16        BlockData(int nonce, String prevhash, long timestamp, Transaction[] transactions) {
17            this.nonce = nonce;
18            this.prevhash = prevhash;
19            this.timestamp = timestamp;
20            this.transactions = transactions;
21        }
23    }
25    static class Transaction implements Serializable {
26        String from;
27        String to;
28        double amount;
30        Transaction(String from, String to, double amount) {
31            this.from = from;
32            this.to = to;
33            this.amount = amount;
34        }
35    }
37    public static void main(String[] args) throws NoSuchAlgorithmException {
38        String prevhash = "232975iocsbc2984590zhdfkekro00kqabfosrf8349109";
39        long timestamp = 1687029267L;
40        Transaction firstTxn = new Transaction("alice", "kishan", 1);
41        Transaction secondTxn = new Transaction("bob", "mathew", 0.1);
43        Transaction[] transactions = new Transaction[]{firstTxn, secondTxn}; // there are only two transactions in this block
44        int result; // the nonce that will give us the two zeros
45        MessageDigest digest = MessageDigest.getInstance("SHA-256");
46        for (int nonce = 1; ; nonce++) {
47            // we are trying the nonce
48            BlockData blockData = new BlockData(nonce, prevhash, timestamp, transactions);
50            ByteArrayOutputStream bos = new ByteArrayOutputStream();
51            ObjectOutputStream out;
52            byte[] hash;
54            // converting the Java object to bytes
55            try {
56                out = new ObjectOutputStream(bos);
57                out.writeObject(blockData);
58                out.flush();
59                byte[] byteArray = bos.toByteArray();
60                hash = digest.digest(byteArray);
61            } catch (IOException e) {
62                throw new RuntimeException(e);
63            }
65            // converting the hash to string (hexadecimal)
66            StringBuilder buffer = new StringBuilder();
67            for (byte b : hash) {
68                buffer.append(String.format("%02x", b));
69            }
70            // print the hash
71            System.out.println(buffer);
72            // see if its first two characters are 0
73            if (buffer.substring(0, 2).equals("00")) {
74                result = nonce;
75                break;
76            }
78        }
80        System.out.println("Result " + result);
81    }

After knowing all these things, one shall ask the question:

Does a system capable of attempting only one nonce per second indicate that its hashrate is 1?

A big Yes. If a system can only try one nonce per second, its hashrate is one hash per second (H/s). However, most modern systems can try much more than one nonce per second, and the current hashrate of the Bitcoin network is over 300 exahashes per second (EH/s), which is 100 quintillion hashes per second.

Thank You

.   .   .
Thank you for taking the time to read this article.


    .   .   .

    The 0xkishan Newsletter

    Subscribe to the newsletter to learn more about the decentralized web, AI and technology.

    © 2024 Kishan Kumar. All rights reserved.