How bitcoin works (in technical detail)
Table of contents:
How bitcoin works
The central question for Bitcoin is: Who is allowed to timestamp what?
This question has classic answers in the so-called ‘Time Stamping Authorities’, TSA. For example, the EU maintains a list of accepted Time Stamping Authorities. A TSA collects requests with data to be timestamped and then signs them using a public-key cryptography method. Only the TSA knows the private key needed to create a signature. But the public key is generally known. Through the mathematical details, anyone can now verify whether a data signature was performed by the owner of a private key that belongs to a public key.
But nothing prevents the TSA from predating data. Or postdating it. You have to trust the TSA. The inventor of Bitcoin was a mathematical genius and a libertarian enemy of the system; he wanted to eliminate states and banks. The fact that this has not yet succeeded is due to two things: Bitcoin is slow and Bitcoin is special. Slow here means it takes minutes to carry out a transaction. With Bitcoin, it is the ‘miners’ who timestamp ‘blocks of transactions’.
A miner solves a difficult mathematical problem; it is hard to calculate, but easy to prove that you have a solution. Solving this problem entitles a participant in the Bitcoin network to timestamp a block of transactions. The miner receives a contractually agreed amount of Bitcoin for this. A block can contain a large number of transactions. However, the number is limited upwards by the Bitcoin protocol. Which ‘pending transactions’ are then timestamped by the miner is at the miner’s discretion. Users can offer this miner transaction fees for this. Each of these individual transactions has a kind of digital fingerprint, it’s called a ‘Hash’. Now, Bitcoin transactions are chained together. Every transaction that spends money must refer to a previous transaction that ‘transferred’ this money into this wallet. Through the chaining and signing, the following situation arises: If one were to try to retroactively change data, the chain of signatures would break because each data signature of a transaction always refers to the signature of another transaction.
The transactions that the miner has chosen to confirm are now all hashed first. Then the hashes are pairwise rehashed. And the resulting hashes are pairwise rehashed again. This results in the structure of a binary tree. This is done until the so-called ‘Merkle root’ is obtained. So, if you confirm, say, 1024 transactions, you have 512 hashes on the level above, 256 hashes above that, then 128 hashes and so on, until you arrive at one hash. If one of the 1024 original signatures of the transactions were changed, the Merkle root would also be different. Theoretically, you could also chain the hashes of the transactions and then hash them again. But if you want to check whether a transaction has been confirmed by a block, you would have to know all the hashes of all the transactions.
The tree structure of the hashes provides a more elegant way; you can verify a ‘Merkle proof’; you can traverse the tree structure from your transaction up to the root and include the sibling for each node. As a result, someone does not have to verify N signatures, but O(log N) signatures to know whether a transaction has been confirmed by a block. The Merkle root is now part of the Bitcoin header. What miners do is the following: In the Bitcoin header there is a number that you can adjust yourself, called a Nonce.
He now guesses a Nonce and creates the hash of the Bitcoin header. If he has now chosen the Nonce in such a way that the hash of the Bitcoin header begins with a certain number of leading zeros, then the problem is considered solved.
To understand this, you need to know that hashes are trapdoor functions: It is very fast to calculate a hash of data, but almost impossible to recover the original data from this hash; it is a kind of ‘meat grinder’ for data.
Other miners can now confirm that you have solved the problem by hashing your Merkle root and your Nonce and checking if it starts with the required number of zeros. They then award you the contractually agreed number of Bitcoin. Ethereum, with ‘Proof of Stake’, which I will not go into in detail today, used an insight: In principle, it is only important that the person who gets the right to timestamp a block is more or less random. It does not necessarily have to be tied to a difficult problem.