Blockchains are often described as "encrypted ledgers". The expression is misleading: in a public blockchain such as Bitcoin's almost nothing is encrypted, and anyone can read every transaction. Cryptography is there, and it is essential, but it plays a different role: it does not hide the data, it makes it verifiable and hard to alter. Let us go through the ingredients one by one.
Ingredient 1: the hash chain
A blockchain is a sequence of blocks. Each block contains a set of transactions and, in its header, the hash of the previous block.
This simple device has a powerful consequence. If someone modified a transaction in an old block:
- the hash of that block would change;
- the next block, which contained the old hash, would no longer be consistent;
- to fix this, you would have to recompute that block, and then every block after it.
The hash chain therefore makes any change evident. On its own, however, it does not make it impossible: recomputing all the following blocks only takes computing power. This is where the consensus mechanism comes in.
Ingredient 2: the Merkle tree
A block can contain thousands of transactions. Instead of computing a single overall hash, the transactions are organised into a Merkle tree:
- the hash of each transaction is computed;
- the hashes are combined in pairs and the hash of each pair is computed;
- this is repeated until a single value is obtained, the Merkle root, which goes into the block header.
The advantage is that to prove a certain transaction is part of the block, you only need to supply a handful of hashes along the path to the root, not the whole block. This is what allows lightweight wallets, on smartphones for example, to verify payments without downloading the entire blockchain.
Ingredient 3: proof of work
In the Bitcoin blockchain, adding a block requires finding a value, called a nonce, such that the hash of the block header is below a very low threshold. Since hash functions are unpredictable, the only way is to try billions of values until one works. This work is the proof of work.
Verification, by contrast, is instant: it takes a single hash computation. This asymmetry between the effort of production and the ease of verification is the heart of the system. Rewriting history would mean redoing the work of all subsequent blocks faster than the rest of the network, which would require more computing power than all the other participants combined.
Other blockchains use different mechanisms, such as proof of stake, in which the choice of who adds blocks depends on the amount of currency locked up and misbehaviour is penalised. There too, digital signatures and hashes remain the fundamental building blocks.
Ingredient 4: keys and digital signatures
In cryptocurrencies there are no accounts held in people's names. Ownership is based on public-key cryptography:
- the private key is a secret number generated by the wallet;
- the public key is derived from it and, from that, through hash functions, the address you share to receive payments;
- to spend, you sign the transaction with the private key; every node on the network verifies the signature with the public key.
Bitcoin uses elliptic curve signatures on the secp256k1 curve, with ECDSA and, following a protocol upgrade, Schnorr signatures as well.
This leads to a rule with no exceptions: whoever holds the private key controls the funds. There is no customer service desk that can reverse a transaction or recover a lost key.
The recovery phrase
Many wallets represent the secret from which all keys are derived as a recovery phrase of 12 or 24 words. Anyone who knows it can rebuild the entire wallet on any device. It must therefore be kept offline, never photographed and never entered into a website that asks for it: no legitimate service needs to know it.
What a blockchain does not do
- It does not encrypt the data: in a public blockchain, transactions, amounts and addresses are visible to everyone.
- It does not guarantee anonymity: addresses are pseudonymous, but analysis of transaction flows and links to exchanges that identify their customers can trace them back to real people.
- It does not make information true: it guarantees that data has not been changed after it was recorded, not that it was correct in the first place.
There are blockchains and techniques geared towards confidentiality, such as zero-knowledge proofs, which make it possible to prove a transaction is valid without revealing its details. They are, however, a specific addition, not a basic feature.
In short
- A blockchain uses cryptography to make data verifiable and hard to alter, not to hide it.
- Each block contains the hash of the previous one; Merkle trees summarise transactions in a single value.
- Proof of work makes adding blocks expensive and verifying them easy.
- Owning funds means holding the private key that signs transactions.
- Transactions on public blockchains are visible and only pseudonymous.