Blockchain · Guide

Blockchain Fundamentals

What a blockchain actually is, how strangers agree without a referee, and where the costs come from.

— min read Blockchain

A Ledger Nobody Owns

A blockchain is an append-only ledger replicated across machines that do not trust each other, where the ordering of entries is agreed by a rule rather than by an authority. Everything else is a consequence of that one constraint.

Each block holds a batch of transactions and the hash of the block before it. Change an old transaction and its block's hash changes, which breaks the link every later block depends on — so tampering means redoing everything since, faster than the rest of the network is extending it.

That is the whole security model, and it is worth being blunt about the trade. You get an audit trail nobody can quietly rewrite. You pay for it with throughput measured in tens of transactions per second, storage replicated thousands of times, and latency measured in block times. If a database with an owner is acceptable, use the database — it is faster, cheaper and easier in every dimension.

Merkle Trees

A block may hold thousands of transactions, but its header holds one 32-byte number: the Merkle root. Hash each transaction, hash them in pairs, keep going, and the single value at the top commits to every transaction underneath it.

The useful property is the proof. To show a transaction is in a block you do not need the block — you need the transaction and one hash per level, about twenty values for a million transactions. Recompute upward and compare against the root.

TransactionsProof size
1,000~10 hashes
1,000,000~20 hashes
1,000,000,000~30 hashes
This is what makes light clients possible: a phone can verify that its payment was included without storing a terabyte of chain, because a logarithmic proof is enough.

Consensus Mechanisms

Consensus answers one question: whose version of the next block counts? Both dominant answers make attacking expensive rather than impossible.

Proof of workProof of stake
Scarce resourceElectricity and hardwareCapital locked as stake
Attack costOut-hash the networkAcquire a large share of the stake
Penalty for cheatingWasted energyStake destroyed by slashing
EnergyVery high by designNegligible
FinalityProbabilistic — wait for confirmationsExplicit, after a couple of epochs

Finality is the practical difference. Under proof of work a block is never strictly final; it just becomes exponentially unlikely to be reorganised, which is why exchanges wait for confirmations. Proof-of-stake chains finalise explicitly, after which reversal would require destroying an enormous amount of staked capital.

An attacker with a majority of the hash rate or the stake can reorder or censor recent transactions — but cannot forge signatures or spend from an account whose key they do not hold. The keys are protected by cryptography, not by consensus.

Wallets & Keys

A wallet holds no coins. It holds a private key; the balance lives on the chain. The public key derives from the private key, the address derives from the public key, and the derivation only runs one way.

ThingIs
Private keyA random 256-bit number. Whoever has it owns the funds
Public keyDerived from the private key, used to verify signatures
AddressA hash of the public key — what you share
Seed phrase12 or 24 words that regenerate every key in the wallet
SignatureProof a transaction was authorised, without revealing the key
There is no password reset. Lose the seed phrase and the funds are unreachable forever; share it and they are gone immediately. No support desk can help, because nobody else has a copy — that is the design, not a gap in it.

Hence the split between hot wallets — keys on an internet-connected device, convenient and exposed — and cold storage, where the key never touches a networked machine. Anything worth protecting lives cold, and a hardware wallet signs without the key ever leaving the device.

Gas & Fees

Every operation costs gas — a unit of computational work — because otherwise an infinite loop would halt the network for everyone. You pay gas used × gas price, and if execution runs out of gas it reverts but still charges you: the work was done and someone has to be paid for it.

OperationRelative cost
ArithmeticTrivial
Reading storageExpensive
Writing storageVery expensive
Deploying a contractEnormous
Emitting an eventCheap — the log way to record data

Gas price is an auction. When the chain is busy, everyone bids higher and a transaction that cost cents becomes tens of dollars — which is exactly the pressure that produced layer 2.

Storage dominates the bill, so contract design is unlike ordinary programming: pack variables into single slots, keep bulk data off-chain and store a hash, and emit events instead of writing state you only ever read from outside.

Layer 2 & Scaling

A chain where every node re-executes every transaction cannot scale by making blocks bigger without pushing nodes onto expensive hardware — which centralises the thing whose whole point was decentralisation. Rollups take the other route: execute elsewhere, settle on the base chain.

TypeHow it proves correctnessCost
Optimistic rollupAssumes valid, allows fraud proofs during a challenge windowWithdrawals wait days
ZK rollupSubmits a validity proof with every batchHeavy proving, harder to build
SidechainIts own consensus, bridgedDoes not inherit base-chain security

Rollups post compressed transaction data to the base chain, so anyone can reconstruct the state independently. That data availability is what separates a rollup from a sidechain — and why a rollup inherits the security of the chain beneath it while a sidechain does not.

Interview Questions

Why is a blockchain hard to tamper with?

Each block commits to the hash of the previous one, so altering an old transaction invalidates every block after it. You would have to redo that work faster than the rest of the network extends the honest chain.

What does a Merkle root give you?

A single hash that commits to every transaction in a block, and inclusion proofs that grow logarithmically — about twenty hashes for a million transactions, which is what makes light clients viable.

Proof of work versus proof of stake?

Both make attack expensive: work burns electricity, stake risks capital that slashing can destroy. Stake adds explicit finality and negligible energy use; work gives only probabilistic finality.

What can a majority attacker actually do?

Reorder or censor recent transactions and double-spend their own. They cannot forge signatures or move funds from accounts whose keys they do not hold — that is cryptography, not consensus.

Why does a failed transaction still cost gas?

The network executed it up to the failure point. Charging for that work is what stops an attacker from submitting endless failing transactions for free.

What separates a rollup from a sidechain?

A rollup posts its transaction data to the base chain and proves its state there, so it inherits that chain's security. A sidechain runs its own consensus and inherits nothing.

Quick Quiz

1. Each block contains the hash of…
2. A Merkle inclusion proof for a million transactions is about…
3. Slashing exists in…
4. Losing a seed phrase means…
5. The most expensive common EVM operation is…