Learning Objectives – after this chapter you will be able to:
  • Define a cryptographic hash function and its required properties.
  • Demonstrate the avalanche effect with real SHA-256 outputs.
  • Identify the hash functions used by Bitcoin and Ethereum.
  • List the places where hashing is used inside a blockchain.
What is a Cryptographic Hash Function?
A hash function takes an input (message) of any length and produces a fixed-length output called the hash or digest. A cryptographic hash function additionally makes it practically impossible to reverse the hash or to find two inputs with the same hash.
  • Think of a hash as a digital fingerprint of data: tiny in size, unique in practice, and it changes completely if the data changes.
  • Hashing is not encryption: encryption can be reversed with a key; a hash cannot be “decrypted”.
Properties of a Cryptographic Hash Function
PropertyMeaning
DeterministicThe same input always produces the same hash.
Fixed-size outputSHA-256 always outputs 256 bits (64 hex characters), whether the input is one letter or a whole book.
Fast to computeCalculating a hash is quick for any input.
Pre-image resistanceGiven a hash h, it is infeasible to find any input x with hash(x) = h (one-way).
Second pre-image resistanceGiven an input x, it is infeasible to find a different y with the same hash.
Collision resistanceIt is infeasible to find any two different inputs with the same hash.
Avalanche effectA tiny change in input (even one bit) changes about half of the output bits.
Puzzle friendlinessThere is no shortcut to find an input whose hash falls in a target range – only trial and error. This is what makes Proof-of-Work fair.
Avalanche Effect – Real SHA-256 Examples
InputSHA-256 hash
Blockchain625da44e4eaf58d61cf048d168aa6f5e492dea166d8bb54ec06c30de07db57e1
blockchainef7797e13d3a75526946a3bcf00daec9fc9c9c4d51ddc7cc5df888f74dd434d1
Blockchain.d70efa3d07ce636c2843270e3a67094e60889d5fbd6829a113b14716ee1c0c4f

Changing one capital letter, or adding a full stop, produces a completely different hash. This is why a single altered transaction changes the Merkle root, the block hash and every link after it.

Hash Functions Used in Blockchains
FunctionOutputWhere it is used
SHA-256256 bitsBitcoin: block hashes and mining (applied twice – “double SHA-256”), transaction IDs, Merkle trees.
RIPEMD-160160 bitsBitcoin: combined with SHA-256 to shorten public keys into addresses (HASH160).
Keccak-256256 bitsEthereum: addresses, function selectors, storage slots, block and transaction hashes.
SHA3-256 (FIPS 202)256 bitsNIST standard version of Keccak with different padding – not the same output as Ethereum’s Keccak-256.

Example: Keccak-256("Blockchain") = fa8871e962875d078135f1c5b27b0f184ab6f4dff8641dd81032226ea0ae9e8c, whereas SHA3-256("Blockchain") = 94074fd5892e84da500a78e4c02ff986c38815ad4063441a1caad310e89cf709.

Where Hashing is Used in a Blockchain
  • Chaining blocks – each block header stores the previous block’s hash (Chapter 1).
  • Merkle trees – summarise all transactions into one root hash (Chapter 21).
  • Proof-of-Work – miners search for a hash below a target (Chapter 15).
  • Addresses – derived by hashing public keys (Chapter 10).
  • Identifiers – transaction IDs and block IDs are hashes.
  • Digital signatures – the message hash, not the whole message, is signed (Chapter 20).
Hash functions can be broken over time: a practical collision for the older SHA-1 was demonstrated in 2017, which is why modern systems use SHA-256, SHA-3 or Keccak.
Key Takeaways
  • A cryptographic hash is a one-way, fixed-size digital fingerprint of data.
  • Key properties: pre-image, second pre-image and collision resistance, plus the avalanche effect.
  • Bitcoin relies on SHA-256 (and RIPEMD-160); Ethereum relies on Keccak-256.
Question / Answer (15 questions)

Answer : It is a function that maps input data of any size to a fixed-size output (hash or digest) in a way that is deterministic, fast to compute and practically impossible to reverse or to make two different inputs produce the same output.

Answer : Encryption is reversible: with the correct key, ciphertext can be decrypted back to the original data. Hashing is one-way: there is no key and the original data cannot be recovered from the hash.

Answer : Given only a hash value h, it is computationally infeasible to find any input x such that hash(x) = h. This makes the function one-way.

Answer : Second pre-image resistance: given a specific input x, it is infeasible to find another input y with the same hash. Collision resistance: it is infeasible to find any pair of different inputs with the same hash, both chosen freely by the attacker.

Answer : A tiny change to the input causes a large, unpredictable change in the output – about half of the bits flip. For example, SHA-256 of “Blockchain” and “blockchain” produce completely unrelated hashes even though only one letter’s case changed.

Answer : It means there is no strategy better than trial and error to find an input whose hash falls within a given target range. This ensures Proof-of-Work mining is a fair lottery proportional to computing power.

Answer : 256 bits, which is 32 bytes or 64 hexadecimal characters.

Answer : Bitcoin uses double SHA-256 for block hashes, mining, transaction IDs and Merkle trees, and uses RIPEMD-160 applied after SHA-256 (HASH160) to create shorter address hashes from public keys.

Answer : Ethereum uses Keccak-256 for addresses, function selectors, storage-slot calculation, and block and transaction hashes.

Answer : Ethereum adopted Keccak before NIST finalised FIPS 202. The final SHA-3 standard changed the padding rule, so the two functions produce different outputs for the same input.

Answer : Linking blocks through the previous-block hash, building Merkle trees of transactions, Proof-of-Work mining, deriving addresses from public keys, generating transaction and block IDs, and hashing messages before signing them.

Answer : The hash is small and fixed-size, so signing it is efficient regardless of message length. Because of collision resistance, a signature on the hash securely binds the signer to the full message.

Answer : An attacker might create two different blocks or transactions with the same hash and substitute one for the other, undermining the integrity guarantees of the chain. The system would need to migrate to a stronger hash function.

Answer : Researchers demonstrated a practical SHA-1 collision in 2017, showing it is no longer collision resistant. Modern systems use SHA-256, SHA-3 or Keccak instead.

Answer : Mathematically yes, because there are infinitely many inputs and only 2^256 outputs. However, no collision has ever been found, and finding one is computationally infeasible with current technology.
MCQ Test : Check Your Understanding (5 questions)

Select an option and press Check Answer, or answer all questions and press Submit Test to see your score. Each answer comes with an explanation.

Q1. Which property makes it infeasible to recover the input from its hash?

Show Answer

Correct Answer : C. Pre-image resistance
Pre-image resistance is the one-way property.

Q2. SHA-256 produces an output of:

Show Answer

Correct Answer : B. 256 bits
SHA-256 always outputs 256 bits (64 hex characters).

Q3. Ethereum’s primary hash function is:

Show Answer

Correct Answer : A. Keccak-256
Ethereum uses Keccak-256 throughout the protocol.

Q4. A one-letter change in the input completely changes the hash. This is called:

Show Answer

Correct Answer : D. Avalanche effect
The avalanche effect flips about half of the output bits for tiny input changes.

Q5. Which statement about hashing and encryption is TRUE?

Show Answer

Correct Answer : B. Hashing is one-way; encryption is reversible with a key
Hashes cannot be decrypted; ciphertext can be decrypted with the right key.

Bibliography/References

The notes, questions and MCQs on this page are original explanations written for this course. The works listed below were consulted and are cited for attribution and further reading. Product names, logos and trademarks belong to their respective owners. Short quotations, where used, are marked and attributed.

  1. National Institute of Standards and Technology. (2015). Secure Hash Standard (SHS) (FIPS PUB 180-4). https://doi.org/10.6028/NIST.FIPS.180-4
  2. National Institute of Standards and Technology. (2015). SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions (FIPS PUB 202). https://doi.org/10.6028/NIST.FIPS.202
  3. Narayanan, A., Bonneau, J., Felten, E., Miller, A., & Goldfeder, S. (2016). Bitcoin and Cryptocurrency Technologies: A Comprehensive Introduction. Princeton University Press. ISBN 978-0-691-17169-2.
  4. Nakamoto, S. (2008). Bitcoin: A Peer-to-Peer Electronic Cash System. https://bitcoin.org/bitcoin.pdf
  5. Wood, G. Ethereum: A Secure Decentralised Generalised Transaction Ledger (Ethereum Yellow Paper). https://ethereum.github.io/yellowpaper/paper.pdf
  6. Antonopoulos, A. M. (2017). Mastering Bitcoin: Programming the Open Blockchain (2nd ed.). O’Reilly Media.
  7. Yaga, D., Mell, P., Roby, N., & Scarfone, K. (2018). Blockchain Technology Overview (NISTIR 8202). National Institute of Standards and Technology. https://doi.org/10.6028/NIST.IR.8202