ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
ဒီ 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 နမူနာ
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);
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 လို့ယူဆခြင်းမှားပါတယ်။