Unit 4: Hashing and Mining
Hashing is ubiquitous in the Bitcoin system. It's used in addresses, transactions, the Proof-of-Work consensus algorithm, and the data structure of blocks. Understanding the utility of hashing is necessary for comprehending the Bitcoin system as a whole.
Here, you'll learn what hashes are used for in Bitcoin and practice generating hashes. Then, we'll dive into the use of hashing in mining and learn to differentiate between the different uses of hashing in Bitcoin, from mining to Merkle trees.
Completing this unit should take you approximately 2 hours.
Upon successful completion of this unit, you will be able to:
- explain the utility of hashing data;
- describe how hashing is used in Bitcoin mining;
- differentiate between the different uses of hashing in Bitcoin;
- hash data and verify that a hash was produced from that data; and
- describe the utility of a Merkle tree.
- explain the utility of hashing data;
4.1: What is a Hash?
Let's start our deep dive into how Bitcoin uses hashing by refresh our memory on what a hash is and how it works. This video explains the basics of hashing and its utility.
4.2: Hashing Algorithms
The first hash functions were created in the 1970s and have evolved rapidly since then. Many of the early hash functions have been "broken" or are no longer secure as methods have been discovered to essentially reverse these types of hashes. As the utility of a hash comes largely from the infeasibility of reverse it, using secure hashing algorithms is vital. Here, we'll review what purposes hashing functions can serve and walk through some more popular algorithms.
4.3: Exercise: Hash Something
Let's see hashing in action. In this exercise, we'll try out hashing data of varying lengths, which will allow us to verify that the outputs are deterministic and uniform in length.
4.4: Hashing and Bitcoin Mining
Bitcoin makes heavy use of hashing, from addresses to transactions IDs and mining. This chapter introduces the mining process. Let's start with some background on the mining process by looking at the monetary aspects of mining, incentives, nodes, and transaction validation. Later, we will discuss some of the more technical aspects of mining.
Now that we have some background on what the mining process does for Bitcoin, let's cover the specifics. This chapter covers the technical process, including mining fees, block data, block headers, and Proof-of-Work.
One of the more interesting, and often confusing, aspects of the mining process is the importance of the number of zeros in a block hash and how the mining difficulty is adjusted. This video will help you visualize target hash difficulty and explains how all nodes come to an agreement regarding the hashing difficulty.
4.5: Exercise: Try a Mining Simulator
Have you ever tried to guess the outcome of a hashing algorithm? Trying out a mining simulator will give you an appreciation for how incredibly unlikely it is to select an input that will give you a specific hash digest. In this exercise, we'll make an attempt at guessing which nonce values will provide us with a desired hash, and have a look at how blocks are linked together.
4.6: Merkle Trees
Before we wrap up this unit, let's take a look at some of the other ways that Bitcoin makes use of hashing. Have you heard of a Merkle tree? This is the data structure that prevents any alteration of transaction data in a Bitcoin block. This page covers the data structure of a block, including Merkle trees.
Study Session Review Video
- View
Unit 4 Assessment
- Receive a grade
Take this assessment to see how well you understood this unit.
- This assessment does not count towards your grade. It is just for practice!
- You will see the correct answers when you submit your answers. Use this to help you study for the final exam!
- You can take this assessment as many times as you want, whenever you want.