Sub topic 14
Risks: custody, smart contract bugs, scams, and regulation
This chapter assumes you know how keys and addresses work, how Bitcoin's UTXO model differs from Ethereum's account model, and what a smart contract is. It also assumes you can read short Python snippets. The chapter is educational and gives no investment advice.
Earlier chapters covered how these systems are designed. This one covers how people lose money with them. Most losses come from four places: who holds the keys, flaws in contract code, deception, and legal or regulatory change. Protocol failures are rarer.
Why risk looks different here
A bank transfer can often be disputed or reversed. A confirmed blockchain transaction usually cannot be. Three properties follow from this.
- Finality moves responsibility to the user. If you sign a transaction to the wrong address, no operator can undo it.
- Control of the key is control of the funds. The network does not check who you are, only that the signature is valid.
- Code often holds the money. On Ethereum and similar platforms, a contract's rules are the only rules, including its mistakes.
Custody risk
Custody means who controls the private keys. There are two basic models.
| Model | Who holds the keys | Main risk | Typical protection |
|---|---|---|---|
| Custodial (exchange, broker, app) | The provider | Insolvency, fraud, hacks, frozen withdrawals | Audits, proof of reserves, regulation, insurance (varies) |
| Self-custody (hardware or software wallet) | You | Lost seed phrase, theft, phishing, user error | Offline backups, hardware wallets, multisig |
Custodial failures
When you deposit coins at an exchange, you usually hold an IOU. The exchange's database says you are owed an amount. If the exchange is hacked, mismanaged, or commingles customer funds with its own, that claim can be worth less than you expected. In an insolvency, customers may rank as unsecured creditors. The common saying is "not your keys, not your coins." It is shorthand for counterparty risk, which is the chance that the other party fails to deliver.
Self-custody failures
Self-custody removes the counterparty but adds operational risk. The usual causes of loss are:
- A lost or destroyed seed phrase with no backup.
- A seed phrase photographed, stored in cloud notes, or typed into a fake site.
- Malware that swaps the address you paste (clipboard hijacking).
- Signing a transaction or approval you did not understand.
Multisignature wallets (for example 2-of-3 keys) reduce single points of failure. They add setup complexity, and a mistake in that setup can lock funds permanently.
Token approvals
On Ethereum, a token holder often grants a contract an allowance to move tokens on their behalf. An unlimited allowance to a malicious or later-compromised contract can drain a wallet without any further signature from you. Reviewing and revoking old approvals is a routine hygiene step.
Smart contract risk
A smart contract bug is a flaw in code that holds or moves value. Deployed contracts are generally hard to change, so a bug may stay exploitable until funds are gone or the team uses a planned upgrade path. Upgrade keys bring their own trust risk, because whoever holds them can alter the rules.
Common bug classes:
- Reentrancy: a contract sends value to an outside address before updating its own records, so the receiver calls back in and withdraws again.
- Access control mistakes: an administrative function that anyone can call.
- Oracle manipulation: a contract trusts a price feed that an attacker can move, for example by distorting a thinly traded pool.
- Arithmetic and logic errors: rounding, overflow in older compilers, or wrong accounting in edge cases.
- Bridge flaws: contracts that lock tokens on one chain and mint wrapped versions on another. They concentrate large sums and have been frequent targets.
A reentrancy simulation
The Python below models the idea. It is not Solidity, but the ordering problem is the same. In the unsafe version, the vault pays out before it zeroes the balance. In the safe version, it updates its records first. This pattern is often called checks-effects-interactions.
class Vault:
def __init__(self):
self.balances = {}
self.pool = 0
def deposit(self, who, amount):
self.balances[who] = self.balances.get(who, 0) + amount
self.pool += amount
def withdraw_unsafe(self, who, receive):
amount = self.balances.get(who, 0)
if amount > 0 and self.pool >= amount:
self.pool -= amount
receive(amount) # external call BEFORE state update
self.balances[who] = 0
def withdraw_safe(self, who, receive):
amount = self.balances.get(who, 0)
if amount > 0 and self.pool >= amount:
self.balances[who] = 0 # state update BEFORE external call
self.pool -= amount
receive(amount)
def run(method_name):
vault = Vault()
vault.deposit("alice", 100)
vault.deposit("bob", 10)
received = []
depth = {"n": 0}
withdraw = getattr(vault, method_name)
def receive(amount):
received.append(amount)
if depth["n"] < 3: # attacker re-enters up to 3 more times
depth["n"] += 1
withdraw("bob", receive)
withdraw("bob", receive)
return sum(received)
print("unsafe:", run("withdraw_unsafe"))
print("safe: ", run("withdraw_safe"))Bob deposited 10. The unsafe vault pays him 40, which includes 30 of Alice's money. The safe vault pays him exactly 10. The attacker's callback is identical in both runs. Only the order of operations differs.
What audits do and do not show
An audit is a time-limited expert review. It lowers risk but does not remove it. Audited contracts have still been exploited, because audits cover a specific code version, can miss interactions between protocols, and cannot judge the economic design. Treat an audit as one input. Also look at how long the code has held real value, whether there is a bug bounty, and whether admin keys can change the contract.
Bitcoin's limited scripting gives a much smaller attack surface for this class of bug. The trade-off is less programmability, which you saw in the chapter on Bitcoin's design.
Scams and social engineering
Scammers target people rather than protocols, because deceiving a user is easier than breaking cryptography. Frequent patterns:
- Phishing: fake wallet or exchange sites and fake support staff asking for a seed phrase. No legitimate service needs your seed phrase.
- Rug pulls: developers launch a token, attract buyers, then drain the liquidity or sell their large holdings. Some tokens are coded so that holders cannot sell.
- Pump-and-dump schemes: coordinated promotion of a low-liquidity coin so insiders can sell to latecomers.
- Impersonation and giveaways: "send 1 and get 2 back" posts, often on hijacked accounts.
- Romance and investment fraud ("pig butchering"): a long, trust-building conversation that ends with a fake trading platform.
- Address poisoning: a tiny transfer from a look-alike address so it appears in your history, hoping you copy it later.
Regulatory risk
Regulation is a risk because rules differ by country and change over time. The effects can be direct, such as a ban or a delisting, or indirect, such as a bank refusing transfers to an exchange.
Areas where rules commonly apply, with details varying by jurisdiction:
- Classification: whether an asset is treated as a commodity, a security, property, or a currency affects who supervises it and how it can be sold. Tokens sold to fund a project face more scrutiny than Bitcoin does.
- Anti-money-laundering rules: exchanges and some other service providers must verify customer identity and screen transactions.
- Taxes: many jurisdictions tax disposals, including swapping one coin for another, and some tax staking rewards. Record-keeping is the user's job.
- Stablecoin and custody rules: reserve requirements, licensing, and segregation of customer assets are active policy areas.
- Sanctions: some addresses and contracts may be blocked by service providers, which affects how freely a given asset can be used.
Different assets carry different regulatory exposure. A token with an identifiable issuer or team is easier for a regulator to act on than a widely distributed network with no central party.
Mapping risks to assets
The same risks weigh differently across assets.
| Risk | Bitcoin | Ether and Ethereum tokens | Small altcoins |
|---|---|---|---|
| Custody | Same as any asset | Same, plus token approvals | Same, often fewer custody options |
| Contract bugs | Low, scripting is limited | Material, applies to every dApp used | High, code is often new and unaudited |
| Scams | Impersonation, phishing | Phishing, fake tokens, approvals | Rug pulls and pump-and-dump are common |
| Regulatory | Generally the most settled | Varies, staking and tokens draw attention | Higher, especially for tokens sold by a team |
A practical checklist
- Decide who holds the keys and write down what happens if that party fails or you lose access.
- Test recovery. Restore a small wallet from its backup before trusting the backup with a large balance.
- Keep approvals narrow and revoke unused ones.
- Before using a contract, check for audits, time in production, admin keys, and upgradeability.
- Verify URLs and addresses independently, and send a small test transaction first.
- Check the tax and legal rules where you live.
Exercise
A lending protocol's withdraw function sends tokens to the caller and only afterward subtracts the amount from the caller's recorded balance. Name the bug class, explain how an attacker exploits it, and state the fix.
Show answer
This is reentrancy. The attacker uses a contract whose receiving code calls withdraw again before the first call has updated the balance. Each nested call still sees the old balance, so the attacker withdraws repeatedly and drains funds belonging to other users. The fix is to update the recorded balance before making the external call (checks-effects-interactions). A reentrancy guard that blocks nested calls also helps.
Exercise
You keep all your coins on an exchange that advertises "bank-level security." Which two risks remain that security alone does not remove, and what is one way to reduce each?
Show answer
Counterparty risk (insolvency, mismanagement, or fraud, since you hold an IOU, not the keys) and withdrawal or regulatory risk (frozen withdrawals or a shutdown). To reduce them, move long-term holdings to self-custody you have tested, or spread balances across providers and withdraw regularly. Self-custody then adds its own backup risk, so test recovery first.