Demystifying the Blockchain

What Are Hash Functions, and How Do They Work?

The Sticky Stuff That Holds the Blockchain Together

Matt Stokes
Geek Culture
Published in
5 min readNov 14, 2021

--

Welcome to my series, “Demystifying the Blockchain.” Where in each article, I break down and explain a fundamental blockchain-related concept/subject in under 5 minutes (probably not actually). This article’s discussion is centred around Hashes… No, although I do like me a substantial breakfast hash every now and again, you probably don’t want to be caught eating this kind of hash (now that I think about it, I am not even sure how you would manage such a task).

Hashes, The Middle Child in the Blockchain Family

It is hard to get very far into an explanation of the Blockchain without mentioning Hashes Functions — they are quite literally the most integral part of the Blockchain. However, they are unfortunately also one of the most overlooked and under-explained — leaving Blockchain enthusiasts lost for words when their grandma or the girl/guy they are trying to impress ignores the super cool Solidity project they are working on and instead asks, “So how do blockchains work?”

You could theoretically continue with your day, forget you ever saw this article, and risk future embarrassment of a most profound order when you get out-geeked by the guy sitting behind you (and listening intently to you and your friend’s conversation). Or you could make the right decision, take 5-minutes now, and never be out-geeked again. 😏

Hash Functions: Basic Definition

A hash function put basically, is a mathematical function that takes an input of any length/size and produces an encrypted output of a fixed length. For instance, I could input my 3,000 word English Essay that was theoretically due last week (sorry unnamed teacher), and the hash function would produce a string of numbers exactly the same size as if I were to input the 7,000-word email I theoretically wrote to explain why my 3,000-word essay was not handed in on time. For example, in the case of a SHA-1 hash function (there are hundreds of examples of Hash Functions in the world, SHA-1 being one of them), the hash values of both my inputs would be 40 hexadecimal digits in length and 160 bits in size (different hash functions have different output sizes and lengths).

What are Bits, Bytes and Hexadecimal Numbers?

  • Bits are the universally accepted standard unit of information for computer systems
  • Bytes are simply collections of 8 bits
  • Hexadecimal digits, is a way of writing numbers that includes more possibilities than the regular base-10 system. Instead of only being able to place a single-digit number from 0–9 in the base-10 system, you can place single digits from 0–15; this is because, in hexadecimal, we include the letters A through to F in the framework (A = 11, F=15, etc).

Hash Functions vs Cryptographic Hash Functions

In their most basic form, hash functions are just simple mathematical functions used to (most of the time) securely encode data and thus are a very prevalent encryption tool used in a wide area of industries — with applications ranging from credit card transactions all the way to software updates. So what makes blockchain/cryptography-specific hash functions special? Well, in a sense, every cryptographic hash function is a hash function, but not every hash function is a cryptographic hash function; in order to understand why you will need a primitive understanding of how a blockchain works.

How the Blockchain Works — In 32 Seconds (Yes, I Counted)

A blockchain is just a chain of digital cubes containing subsequent data. Each block is linked to the block behind it — going all the way to the first block in the chain (the Genesis Block). Each block in the chain contains vital, transaction-specific information like the value/amount of data that is involved in the transaction, the timestamp, and the address. Each block is connected with an invisible chain created by cryptographic hash functions, which output hash values based on the transaction-specific data in the current block, plus the data from the preceding block. So essentially, blockchain-specific hash functions require multiple pieces of data in order to operate. However, it is possible and perhaps important to go a bit deeper in understanding than this. In general, we can define cryptographic hash functions under the following ruleset.

Cryptographic Function Rules:

The Avalanche Effect: A minuscule change in the input should result in a change of at least half the bits in the output. Meaning, when you make a tiny change to your input, the output should be entirely different/unrecognizable.

One-way Functions: A proper cryptographic hash must be within a percentage of impossible to reverse engineer and discover the transaction data from.

Deterministic: The same input must always result in the same output. It would be unfortunate if you inputted the words “pay Michael $10” into your hash function and used the key to later receive the message “pay Sally $10,000.”

Collision Resistant: It should be basically impossible to find two inputs that hash to the same output, i.e. the scenario F(g) = F(c) should never occur.

Non-Predictable: The same input should always create the same output, and said output should be impossible to predict in advance, meaning the output must be entirely random.

Time to Rehash 😏

Let’s recap. Hash functions in their most basic form are just functions that take an input and provide a random and unpredictable output of a fixed length. The hash functions used in blockchain-specific applications are known as Cryptographic Hash Functions, and although they are categorized under the umbrella of hash functions, they have a specific set of guidelines that they must satiate in order to fulfill the purpose required of them. These guidelines ensure that the hashes created by said functions result in the blockchain’s famed immutability.

Further Resources:

https://www.tutorialspoint.com/cryptography/cryptography_hash_functions.htm — Tutorials Point

https://www.thesslstore.com/blog/what-is-a-hash-function-in-cryptography-a-beginners-guide/ — The SSL Store

https://blockgeeks.com/guides/cryptographic-hash-functions/ — Block Geeks

--

--

Matt Stokes
Geek Culture

Hey! My name is Matt and I am a 17 yr/old innovator/entrepreneur, fascinated with the ever changing world of emerging technology!