Thuta Learning
Blockchain
ExercisesSecurityAdvanced

Blockchain Exercises — Set 1 (Hashing & Block Basics)

BlockchainLesson 35

What you'll walk away with

  • Explain the protocol model, trust assumptions, and failure modes of Blockchain Exercises — Set 1 (Hashing & Block Basics)
  • Test normal, tampered, and failure cases in a local simulation or testnet
  • Apply safe practices and explain limitations without real keys or funds

Let's think about this for a second

This lesson doesn't teach anything new — it's about writing your own code to get hands-on with the hashing, blocks, and immutability ideas already explained in the Basic chapter. The goal is to actually see SHA256's avalanche effect (a tiny change in input completely changes the output). The tasks are short — you can open node in the terminal and run them directly.

Exercises

Task 1 — Require Node.js's crypto module, hash the two strings 'Hello Blockchain' and 'hello Blockchain' (differing only by the capital/lowercase H) with SHA256, and compare the outputs. Task 2 — Write a genesis block object yourself containing {index:0, timestamp: Date.now(), data:'Genesis Block', previousHash:'0'}, then combine it with JSON.stringify() and compute its SHA256 hash. Task 3 — Change the data field of the block object you wrote in Task 2, recalculate the hash, and compare it against the original hash to see whether they match.

Build a Complete Mental Model

This exercise set tests independent reasoning about hashing, block structure, links, and tamper detection. For each exercise, record exact serialized input, expected digest or link, one mutation, and the validation result. Do not confuse toy difficulty output with cryptographic collision or security guarantees; state assumptions clearly.

Apply It Safely

Submit each task as input specification, expected hash or tree, mutation, detected failure, and explanation.

Code Example

javascript
const crypto = require('crypto');

function sha256(input) {
  return crypto.createHash('sha256').update(input).digest('hex');
}

// Task 1: string နှစ်ခု hash ယှဉ်ပါ (H စာလုံးကြီး/သေးပဲ ကွာပါတယ်)
const hashA = sha256('Hello Blockchain');
const hashB = sha256('hello Blockchain');
console.log('hashA:', hashA);
console.log('hashB:', hashB);

// Task 2: genesis block object ရေးပြီး hash တွက်ပါ
const genesisBlock = {
  index: 0,
  timestamp: Date.now(),
  data: 'Genesis Block',
  previousHash: '0',
};
const genesisHash = sha256(JSON.stringify(genesisBlock));
console.log('genesisHash:', genesisHash);

// Task 3: data ပြောင်းပြီး hash ကို ပြန်တွက်ကြည့်ပါ (TODO — ကိုယ်တိုင်ရေးပါ)
// const changedBlock = { ...genesisBlock, data: 'Genesis Block v2' };
// const changedHash = sha256(JSON.stringify(changedBlock));
// console.log('changedHash:', changedHash);
You should see
Once you finish all three tasks, you'll see three hash strings in the terminal: two completely different hashes for strings that differ by just one character, and a block's hash.

Try It Yourself

Rebuild the Blockchain Exercises — Set 1 (Hashing & Block Basics) example on a local simulation or testnet without real funds, seeds, or private keys. Define two normal cases, one tampered or adversarial case, and one failure case, writing expected state and verification evidence before execution.

Security Warning

A long random-looking digest is not by itself a proof of correct or secure use.

NISTIR 8202 — Blockchain Technology Overview — NIST

Easy traps

  • A long random-looking digest is not by itself a proof of correct or secure use.
  • One successful happy path does not establish security or production readiness; adversarial, key-management, and economic risks need explicit analysis.

Hands-on Exercise

Rebuild the Blockchain Exercises — Set 1 (Hashing & Block Basics) example on a local simulation or testnet without real funds, seeds, or private keys. Define two normal cases, one tampered or adversarial case, and one failure case, writing expected state and verification evidence before execution.

You'll know it worked when: Once you finish all three tasks, you'll see three hash strings in the terminal: two completely different hashes for strings that differ by just one character, and a block's hash.

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Blockchain Exercises — Set 1 (Hashing & Block Basics) | Thuta Learning