Macroeconomic Monitor
Home / Economy / What is Bitcoin Part III: Electronic Cash and Blockchain

What is Bitcoin Part III: Electronic Cash and Blockchain

Author: Stilgar

This is the third part of our series "What is Bitcoin?". You can read the previous part, which explains the cryptography behind cryptocurrencies, here.

Let's say we want to make electronic cash and we're armed with cryptography. The first, most natural idea is to have a bank and everyone has an account there. Using public and private keys, we'll send messages to the bank and it will verify them and move money from one account to another. But what if we think the bank isn't good enough? Maybe we don't trust the bank because of fractional reserve banking, or we don't want the government to announce that it's confiscating our deposits, as has happened many times in history (for example, in Cyprus in 2013). We want to have electronic cash that doesn't require an intermediary.

The natural idea that might come to us is to create some units of our electronic cash in some way and distribute them to some people and then publish the initial distribution. Perhaps all units will initially be owned by the creators of the currency or perhaps they will be given in return for a donation to some charity, the point is to have an initial distribution and publish it publicly. Ownership is verified by signing with a public/private key, the public key is published with the initial distribution.

Then, when sending a unit of money, the owner signs a transaction (with his private key) that he gives that unit to another owner (via his public key). Something like a check. The new owner can give the money to another by signing a transaction (with his private key). The other can check the chain of signatures back to the original distribution which is publicly known. So far so good, but what prevents one owner from signing two transactions for the same money and giving it once to Pesho and once to Gosho? This problem is called double spend and for a long time no one had come up with a solution to it (there are other types of double spend). This is exactly the problem that Satoshi Nakamoto solved with the creation of Bitcoin and thus the world's first decentralized electronic cash appeared. He achieved this by inventing something called blockchain and combining it with an existing concept called proof of work.

Blockchain

Imagine that you want to somehow store a series of records so that it is certain that they have not been changed. Blockchain is a solution to this problem. Data is recorded in portions called blocks. Each block contains, in addition to the data, a hash of the previous block in the chain. When we send the entire chain to someone, they can check starting from the first block that each block really contains the hash of the previous one by simply generating the hash of each block and comparing whether it matches the record in the next one. I recall that even if 1 bit of information were to change, the hash would be totally different. Therefore, if someone tries to change a block, they will have to change all the blocks after it.

Of course, changing all blocks afterwards is possible, but it is possible to do something that prevents this. For example, we can periodically save the current block with a notary or have several people sign the current block with their keys, in which case in order to change the chain, these same people would have to sign all previous blocks up to the changed block. Blockchain is used for this type of audits and is a very suitable technology for the purpose. For example, my friend Bozhidar Bozhanov's company Log Sentinel offers such a solution, which is used by businesses and banks. We can easily imagine how such a data structure would be useful for building a payment system.

The Bitcoin network is a blockchain of data. Although it can record arbitrary data, such as notes and messages, the majority of the data on the Bitcoin blockchain is transactions to send some amount of bitcoins from one address to another, signed with the private key of the address sending the money. Bitcoin network addresses are the public keys of the recipients (actually hashes of the public keys, a curious arrangement that Satoshi did not explain, but for the purposes of this description we can assume it is the same).

A transaction contains the sender's address, the recipient's address, the fee (we'll explain it later), the amount to be sent, and a signature for this data set. (Again, I'm simplifying, it also contains a few more records needed for the network to work). A block includes many such transactions along with the hash of the previous block and it is published on the network. Many computers around the world running the Bitcoin software receive a copy of this block and store a copy of the entire blockchain. We call these computers nodes (literally "nodes", but it doesn't sound good, maybe "tops" is a more correct translation, I'll use a foreign language). None of the nodes is the main or official, all nodes are equal (peers).

So far so good, we have a scheme that prevents old transactions from being replaced, and a transaction history that allows transactions to be validated back to the origin of each coin. There is only one more problem left – if one node gives us one blockchain, and another node gives us another blockchain, how do we know which is the real Bitcoin blockchain? After all, there is no master or official node that we can trust?

Graphic: Highly simplified diagram of the Bitcoin Blockchain

Proof of Work

In 1997, cryptographer Adam Beck (who is now an active participant in Bitcoin circles and runs a large company in the industry) proposed a method for combating e-mail spam. In order for an e-mail not to be blocked, the sender's computer must solve a task that requires processor time. The idea is that for the sender of a genuine letter, a few tens of seconds of computer activity is not a problem, but spammers who send millions of letters will need a huge amount of hardware and electricity. We call this type of trust proof of work

In Bitcoin, with the creation of each block, a proof of work problem is generated, which must be solved in order to generate the next block. The process of solving the problem is called mining. Many miners compete to solve the problem, and the first one to succeed has the right to present the new Bitcoin block to the world (to all nodes). They can easily check whether the solution to the problem is correct and whether the block complies with the other rules of the Bitcoin network (for example, whether it does not contain a transaction sending non-existent Bitcoin units) and if the block is valid, they add it to their blockchain and send it to other participants in the network.

All miners start a “race” to generate the next block with the new task. The miner who generates a block receives a certain amount of Bitcoin as a reward. In the Bitcoin network, the reward is the way in which bitcoins are initially created. Every 210,000 blocks, the reward for a new block is reduced by half, an event we call halving and occurs about 4 years. One day, the network will stop giving rewards for new blocks and then all 21,000,000 bitcoins will have been produced. It is important to note that the purpose of mining is not to produce bitcoins. They could have been distributed in some other way, for example, at the beginning everyone was in Satoshi and he gave it to whomever he chose. The goal is to solve the double spend problem. Proof of work is part of the solution. The block reward helps to solve this problem.

How does proof of work work? Imagine that you have the equation x – 5 = 0 and you know that the answer is between 0 and 9, but you don’t know an algorithm for solving it efficiently (you can’t just transfer -5 and change the sign). Imagine that such an algorithm is not known to humanity. How can we solve the problem in such a case? Well, we just start trying all possible values for x:

Does 0 – 5 equal 0? No.
Does 1 – 5 equal 0? No.

Is 5 - 5 equal to 0? Yes. So 5 is the solution.

The interesting thing about this situation is that even though it took us many tries to guess the solution, if we tell someone that this is the solution, they can verify it much faster by checking only the case we gave them (5). Now imagine that the result is not between 0 and 9 but between 0 and a huge number (one of those that have no name and are written as powers because otherwise we would need a whole page). In this way, the process of finding a solution is very slow, but the process of verifying is very fast compared to solving.

Okay, but we all know how to solve the above equation by moving -5 and changing the sign. What would this problem be for which no one knows an efficient algorithm to solve and the only way is to try solutions one by one? Hmmm… cryptographic hash functions!

The problem solved in Bitcoin Proof of Work is finding a specific SHA-256 hash where the input data is the header of the future Bitcoin block. This data contains things like the generation date, the hash of the previous block, and a number called the nonce. The hash of the previous block is important and means that the work of mining the new block cannot start until the previous one has been mined. If this were possible, everyone would have a pre-mined collection of hashes and could extract them whenever it was convenient. The nonce is just a number. The miner can change this number to generate different hashes, while keeping the other data the same. In short, we solve SHA256(x) = …

The attentive reader would say "But author, no one can compose data for a certain hash using a cryptographic hash function. If they can, the function is considered broken and should not be used!". That's right, no one can compose data that generates a randomly chosen hash, but we could make the task easier. In Bitcoin, instead of looking for an entire hash, a hash is searched for that starts (or ends) with a certain number of zeros, and the other digits of the hash are ignored, that is, they can be anything. The number of zeros determines the current difficulty of mining and is self-regulated by the protocol. If blocks start coming too fast (that is, many computers are mining), the number of zeros that the system requires increases, and if blocks come too slowly, the number of zeros decreases. Bitcoin aims to generate an average of 1 block every 10 minutes. If you are interested, here you can see a more detailed explanation of the process as well as a person performing one step of it with a piece of paper and a pencil - http://www.righto.com/2014/09/mining-bitcoin-with-pencil-and-paper.html

Okay, but how does this help us solve the problem of two nodes giving us two different chains? After all, they can mine perfectly legitimate hashes and produce different blocks. At this point, the Bitcoin Whitepaper contains a short and beautiful sentence that summarizes Satoshi's innovation (I recall that PoW has existed since before Bitcoin and even has blockchain precursors). The sentence is:

" The longest chain is Bitcoin. "

Nodes should choose the version of the proposed (valid) chains that has more blocks, i.e. more work done. This is the last element needed for peer to peer electronic cash (a payment network without a central server). We have a way to sign transactions (public and private key cryptography), we have a way to sequence transactions (blockchain), we have a decentralized way to know which chain is the real one.

A visual representation of what has been explained so far can be seen in this video:

Did you like it? Take a minute to support the EKIP on Patreon!
Become a patron at Patreon!

About Guest Author

Read more

The financial coup in Bulgaria of 1947

The year 1947 in Bulgarian history is associated with the implementation of an important monetary reform. It is …