What are hash pointers in blockchain?

Hash pointers are a data structure containing the previous block’s hash value and a pointer to that block. Here is a demonstration:

Chain of data blocks that contain hash values and pointers
Chain of data blocks that contain hash values and pointers

Here, we have four blocks that are connected. “Block 0” does not point to another block as it’s the first block in the chain. Block 0 is also identified as the genesis blockIt is the point of origin of blockchain. “Block 1” has a hash value stored in it that is calculated on the basis of the data present in the previous block. The previous value in this block is “Block 0.” Similarly, “Block 2” has the hash value of its previous block, and so on.

We use a hash function to convert the data in the previous block to a hash code or a hash value that we store in the following block.

Properties of good hash functions

Some properties of good hash functions are:

  • Hash functions are deterministic, meaning the hash function will always return the same output for the same input.

  • A good hash function is collision-free, meaning different inputs can’t be mapped to the same output.

  • After the hash function is applied to a string/input, it returns a different output. This property of the hash function helps us hide the actual data. A small change in the input will result in a significantly different hash value.

  • Hash functions are puzzle-friendly (puzzles are used in the consensus of the nodes in proof-of-work based blockchains, i.e., Bitcoin).

  • Good hash functions are computationally efficient to calculate. This ensures that the performance of the application is not compromised.

  • Hash functions are one-way functions, meaning the original input can’t be derived from the hash value, without an exhaustive search (brute-force attack).

Hash pointers in blockchain

Hash pointers are the building blocks of blockchain. Each block contains a hash pointer that points to the previous block and contains its hash. The immutability of blockchain is one of its most significant aspects, and hash pointers allow us to attain this property. Hash pointers help us validate if a block is modified or not. Let’s look at a demonstration:

Hash pointers
Hash pointers
1 of 6

Even a minor change in the blocks would completely change the hash code of that block. This is the reason why hash pointers are used to detect if the blockchain is altered or not. Mostly, we use SHA-256SHA-256 (Secure Hash Algorithm 256) is a widely used cryptographic algorithm that produces a fixed-length, 256-bit (32-byte) hash value. to compute the hash code. SHA-256 works on a fixed size of inputs, which is 512 bits.

Our data can exceed the size of 512 bits or be less than 512 bits. If our data exceeds 512 bits, we divide it into chunks of 512 bits. To work with data of arbitrary length, SHA-256 uses the Merkle-Damgard transform to work with inputs of arbitrary lengths.

The Merkle‐Damgard transform is quite simple. There is a compression functionIt is an underlying fixed‐length collision‐resistant hash function that takes inputs of length 512 bits to generate fixed size hash value, i.e., 256 bits. The input to the hash function, which can be of any size, is divided into blocks​ of size 512 bits. The construction works as follows: pass each block together with the output of the previous block into the compression function.

For the genesis block, we combine it with an initialization vector of 256 bits and pass it to the compression function, which gives us an output of 256 bits​. The output, along with the next chunk, is then forwarded to the compression function. The process continues until the last chunk, and the output we get at the end is the hash code of our entire block.

If we have a chunk with less than 512 bits, we pad a one and zeros to our chunk to get the desired size. Then, we pass it to the SHA-256 to calculate the hash code.

Here is an illustration of the Merkle-Damagard transform:

Data of size 1848 bits
Data of size 1848 bits
1 of 3

Hash pointers are the building blocks of the blockchain. They make the blockchain immutable. We can verify the blockchain using the hash values stored in the hash pointers. Even a minor change in one of the blocks would change the hash value of that block.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved