Week 10 / Blockchain from zero
Wallets, Security And Custody
- Week 10 of Blockchain from zero
- Keep your keys safe and write contracts that hold up.
Week 10 · Blockchain
What You Can Do By The End
- Back up a seed phrase correctly
- Compare custody models
- Spot phishing and revoke approvals
- Fix a reentrancy bug
- Read an audit with care
Week 10 · Blockchain
Whoever Holds The Key Holds The Asset
- A wallet stores keys and signs for you.
- Assets stay on the chain.
- No password reset exists for a lost key.
- You become your own security department.
Week 10 · Blockchain
Seed Phrases
- 12 or 24 words created with BIP-39.
- All keys derive from the phrase.
- Anyone with the words controls the account.
- No legitimate service ever asks for it.
Week 10 · Blockchain
Backing Up A Phrase
- Write on paper or stamp in metal.
- Keep two copies in different places.
- Never store it in photos, notes or cloud.
- Test the restore on a second device.
Custody
Who Holds The Keys?
- Custodial: the company holds keys, you hold a claim.
- Self-custody: you hold keys and risk.
- Each model trades convenience for control.
| Model | Keys held by |
|---|
| Exchange | The company |
| Software wallet | You |
| Hardware wallet | You, offline |
| Multisig | Several parties |
Week 10 · Blockchain
Hardware Wallets
- The key lives inside a secure chip.
- The computer builds the transaction.
- You verify details on the device screen.
- The device signs and returns the signature.
computer: builds transaction
device: shows to, amount, fee
you: press confirm
device: signs, key never leaves
Week 10 · Blockchain
Multisignature Wallets
- Several keys must approve a spend.
- Example: 2 of 3 signers.
- Protects against one lost or stolen key.
- Safe is a widely used contract wallet.
Week 10 · Blockchain
How Phishing Works
- Fake sites reached by sponsored search results.
- Fake support agents in direct messages.
- Urgent emails about account risk.
- Free token claims that ask for a signature.
Week 10 · Blockchain
Connect, Sign, Approve
- Connect shares only your public address.
- A transaction signature can move funds.
- An approval lets a contract spend tokens later.
- Off-chain permits grant rights with no visible transaction.
Week 10 · Blockchain
Reduce The Damage
- Verify full addresses, not just the ends.
- Send a small test transaction first.
- Revoke old allowances monthly.
- Use a separate wallet for experiments.
Contract bug
Reentrancy: The Vulnerable Vault
- The vault sends ether before updating balance.
- The receiver calls withdraw again.
- The old balance is still recorded.
function withdraw() external {
uint256 amount = balances[msg.sender];
require(amount > 0, "nothing");
(bool ok, ) = msg.sender.call{value: amount}("");
require(ok, "send failed");
balances[msg.sender] = 0;
}Week 10 · Blockchain
Reentrancy: The Fix
- Checks, then effects, then interactions.
- Zero the balance before the external call.
- Add a reentrancy guard as a second layer.
function withdraw() external {
uint256 amount = balances[msg.sender];
require(amount > 0, "nothing");
balances[msg.sender] = 0;
(bool ok, ) = msg.sender.call{value: amount}("");
require(ok, "send failed");
}Week 10 · Blockchain
Other Common Bugs
- Missing access control on admin functions.
- Unchecked results of external calls.
- Weak oracles that one trade can move.
- Authorization with tx.origin.
| Bug | Idea |
|---|
| Reentrancy | Call back before state update |
| Access control | Missing owner check |
| Overflow | Number wraps around |
Week 10 · Blockchain
What An Audit Can And Cannot Say
- It reviews one version at one moment.
- It can miss bugs.
- It does not judge economic design.
- Check which findings were fixed.
Week 10 · Blockchain
Recap
- Keys control assets, so back them up well.
- Pick custody to match the amount at risk.
- Read every signature, revoke old approvals.
- Audits help, and they have limits.
Week 10 · Blockchain
Next Week: Real-World Use And Regulation
- Identity, supply chains, payments, public goods.
- How regulators approach crypto.
- The EU and Turkey at a high level.
Week 10 · Blockchain
Questions And Exercise
- Attack and fix the vault in Remix.
- Restore a test wallet from its phrase.
- Write your one-page security plan.