Thuta Learning
Blockchain
ExercisesSecurityအဆင့်မြင့်

Blockchain အလေ့အကျင့် — အတွဲ ၁ (Hashing & Block အခြေခံ)

Blockchainသင်ခန်းစာ 35

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Blockchain အလေ့အကျင့် — အတွဲ ၁ (Hashing & Block အခြေခံ) ရဲ့ protocol model, trust assumptions နဲ့failure modes ကိုရှင်းပြနိုင်ရန်
  • Local simulation/testnet တွင် normal, tampered နဲ့failure cases ကိုစမ်းနိုင်ရန်
  • Real keys/funds မသုံးဘဲ security limitations နဲ့safe practice ကိုအသုံးချနိုင်ရန်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

ဒီ lesson မှာ အသစ် concept ဘာမှ မသင်ဘဲ Basic chapter မှာ ရှင်းပြပြီးသား hashing, blocks, immutability idea တွေကို ကိုယ်တိုင် code ရေးပြီး လက်ဆွဲစမ်းသပ်ကြည့်တာပါ။ SHA256 hash function ရဲ့ avalanche effect (input အနည်းငယ်ပြောင်းရင် output လုံးဝပြောင်းသွားတာ) ကို တွေ့မြင်ရအောင် ရည်ရွယ်ထားပါတယ်။ Task တွေက short ပါတယ်၊ terminal ထဲမှာ node ဖွင့်ပြီး တိုက်ရိုက် run ကြည့်နိုင်ပါတယ်။

လေ့ကျင့်ခန်းများ

Task 1 — Node.js crypto module ကို require လုပ်ပြီး 'Hello Blockchain' နဲ့ 'hello Blockchain' (H စာလုံးကြီး/သေး တစ်လုံးပဲ ကွာ) ဆိုတဲ့ string နှစ်ခုကို SHA256 နဲ့ hash လုပ်ပြီး output ကို ယှဉ်ကြည့်ပါ။ Task 2 — {index:0, timestamp: Date.now(), data:'Genesis Block', previousHash:'0'} ပါတဲ့ genesis block object တစ်ခု ကိုယ်တိုင်ရေးပြီး ၄င်းရဲ့ hash ကို JSON.stringify() နဲ့ ပေါင်းပြီး SHA256 တွက်ကြည့်ပါ။ Task 3 — Task 2 မှာရေးထားတဲ့ block object ရဲ့ data field ကို ပြောင်းလိုက်ပြီး hash ကို ပြန်တွက်ကြည့်ပြီး original hash နဲ့ တူ/မတူ ယှဉ်ကြည့်ပါ။

ပိုပြီးနားလည်ထားရမယ့် အချက်

ဒီ exercise set က hashing, block structure, links နဲ့tamper detection ကိုcopy မလုပ်ဘဲreason လုပ်နိုင်မှုစမ်းပါတယ်။ Exercise တစ်ခုစီမှာ exact serialized input, expected digest/link, mutation နဲ့validation result ကိုရေးပါ။ Hash collision/security claim ကိုtoy difficulty output နဲ့မရောဘဲ cryptographic property assumptions ကိုရှင်းပါ။

လက်တွေ့မှာ ဘယ်လိုအသုံးချမလဲ

Task တစ်ခုစီကို input specification → expected hash/tree → mutation → detected failure → explanation အစဉ်ဖြင့်တင်ပါ။

Code နမူနာ

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
Task သုံးခုစလုံး ပြီးရင် terminal ထဲမှာ hash string သုံးခု (character တစ်လုံးပဲ ကွာတဲ့ string နှစ်ခုရဲ့ လုံးဝမတူတဲ့ hash နှစ်ခု၊ block ရဲ့ hash) ကို မြင်ရပါလိမ့်မယ်။

ကိုယ်တိုင်စမ်းကြည့်ရန်

Blockchain အလေ့အကျင့် — အတွဲ ၁ (Hashing & Block အခြေခံ) နမူနာကို real funds သို့real seed/private key မသုံးဘဲ local simulation သို့testnet မှာပြန်တည်ဆောက်ပါ။ Normal case နှစ်ခု၊ tampered/adversarial case တစ်ခုနှင့် failure case တစ်ခုအတွက် expected state နဲ့verification evidence ကိုမ run မီရေးထားပါ။

Security သတိပေးချက်

Output hash ရှည်လျားပြီးrandom လိုမြင်တာကိုsecurity proof လို့ယူဆခြင်းမှားပါတယ်။

NISTIR 8202 — Blockchain Technology Overview — NIST

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Output hash ရှည်လျားပြီးrandom လိုမြင်တာကိုsecurity proof လို့ယူဆခြင်းမှားပါတယ်။
  • Happy path တစ်ခုအောင်တာနဲ့ system secure သို့production-ready ဖြစ်ပြီဟုယူဆခြင်းက adversarial, key-management နဲ့economic risks များကိုလွတ်စေနိုင်ပါတယ်။

လက်တွေ့လေ့ကျင့်ခန်း

Blockchain အလေ့အကျင့် — အတွဲ ၁ (Hashing & Block အခြေခံ) နမူနာကို real funds သို့real seed/private key မသုံးဘဲ local simulation သို့testnet မှာပြန်တည်ဆောက်ပါ။ Normal case နှစ်ခု၊ tampered/adversarial case တစ်ခုနှင့် failure case တစ်ခုအတွက် expected state နဲ့verification evidence ကိုမ run မီရေးထားပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Task သုံးခုစလုံး ပြီးရင် terminal ထဲမှာ hash string သုံးခု (character တစ်လုံးပဲ ကွာတဲ့ string နှစ်ခုရဲ့ လုံးဝမတူတဲ့ hash နှစ်ခု၊ block ရဲ့ hash) ကို မြင်ရပါလိမ့်မယ်။

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Blockchain အလေ့အကျင့် — အတွဲ ၁ (Hashing & Block အခြေခံ) | Thuta Learning