If you read financial news or finance blogs, you probably have heard (a lot) about cryptocurrencies and especially Bitcoin. You probably have read some success stories where people made a fortune investing in one cryptocurrency. You also probably have read stories where people have lost a fortune with them. But what is a cryptocurrency really? And how do they work?
In this post, I am going to try to answer these questions for you. I am thinking that this could be interesting to know exactly how they work. You probably have heard of the words blockchain or miner or even hash function. We are going to see how they come into play for cryptocurrencies.
I am not going to cover the investment quality of the cryptocurrencies in this post. I plan to discuss that in another post. Finally, in a later post, I will also discuss the history of cryptocurrencies since their creation.
As their name indicates, cryptocurrencies are a form of currency. What is important here is that they are entirely digital. They only exist in a computer data format. You cannot have notes representing cryptocurrencies. You cannot put them in your wallet unless you put a USB key in your wallet that is ;)
Another very important fact is that they are entirely decentralized. There is no central authority that can emit currencies. There is not even a central computer. The entire network is collaboration to produce and manage the cryptocurrency. And each transaction is validated, cryptographically, by miners. These miners use their computers (or farm of computers) to validate transactions and gain extra currencies as such. The system sets the maximum number of currencies. The system also sets the cryptocurrency creation rate, decreasing over time.
The other part of the name tells you they use cryptography. Cryptocurrencies are based on cryptography to make it a safe and decentralized system. As it is, cryptography is used for validation of signatures and for preventing invalid or fraudulent transactions.
The most important part of each cryptocurrency is its ledger. There is a ledger containing the entire history of the transactions. That means you can find the amount of currencies of each user by reading the entire ledger.
How does it really work?
That is all good, but how does it really work under the hood. I am going to give you an overview of the main concepts. This is a general idea, some cryptocurrency may have a different concept. But they are generally using this concept. It is all about math! More specifically, it is all about cryptography.
Cryptography is the science behind secure communications. It is heavily based on mathematics and computer science. Without cryptography, you would not be able to safely buy things online for instance. It is also used in credit cards transaction. It is being used more and more.
The cryptocurrency ledger
Cryptocurrencies are keeping up a ledger of all the transactions. A transaction contains the following information: the sender, the receiver and the amount of currency. And anyone part of the system can add a new line to the ledger. But it is very important that these lines be verified. Otherwise, anyone can add transactions to the ledger without being valid. In such a system, you do not want to trust anybody. Therefore, everything needs to be verified, ideally several times.
Every user should sign its transactions, to make sure that they are valid. Every transaction will have a signature. This is a digital signature, generally around 256 bits of data (a bit is a 1 or 0). For this, every user has one pair of keys: A public key (PK) and a secret key (SK), also called a private key. When a user wants to sign a transaction, he uses a cryptographic signature function. This functions produces a strong signature based on the content of the transaction and the secret key of the user.
The cryptographic function is made so that using the transaction content, the signature and the public key of a user, it is possible to verify that the signature is coming from this user. In other words, you only need the public key to verify the transaction. And you can only sign documents with your private key. So of course, it is extremely important to keep your secret key as secret as possible. If someone gets access to your private key, he can create new transactions on your behalf.
But if a transaction has a signature and a content, anyone can still copy it. Therefore, it is also important that the transactions get a unique ID to avoid this situation. The unique ID will be part of the content of the transaction and will affect the signature. Like this, nobody can copy a transaction without knowing the secret key. This unique ID is the timestamp of the transaction.
When someone adds a cryptocurrency transaction to the ledger, it is necessary to check whether it is valid or not. You do not want someone transferring some currencies that he does not have. It is the same principle as your bank, you cannot spend what you do not have. That means that the system needs to validate every transaction before adding it to the ledger. Cryptocurrency systems do not keep track of balances. They use the ledger for this. So, it is necessary to look at the entire transaction history of the user to see how much remains and if the transaction is valid.
The proof of work
I said there is a ledger, but I also said the currency is not centralized. So there is no central place to store the ledger. Therefore, many people must have a copy of the ledger. For this, each transaction is sent to everyone. We call this process a broadcast. But then, there is the problem of making sure that each local ledger is up to date. There need to be a protocol for knowing which ledger is the correct one. For this, cryptocurrencies use a system called proof of work.
The idea is to validate the ledger with some extra information (the proof of work) that takes a very long time to compute. One example is to find the number that, added to the transaction list, will produce a hash of the transaction list (+ the number) that is starting with 30 leading zeroes. This number is the proof of work. The system uses a cryptographic hash function for this. The function matches the input with a fixed-size number (for most crypto-currencies, it is 256 bits). When using a strong cryptographic hash function, computing this proof of work is very computationally intensive. But verifying this proof of work is very fast. It is very important for a good hash function to be impossible (or very difficult) to reverse. If you could easily reverse it, this would break the entire system.
The cryptocurrency block chain
Since the ledger can be very big, it is split into blocks. A proof of work accompanies each of these blocks. One block is only valid if it has a valid proof of work. In order to keep the order of the blocks, each block also contains the hash of the previous block. The blocks are forming a chain. That is why the ledger is called a block chain in cryptocurrencies. You may have heard the word block chain before ;)
Some people are listening for the new transactions. Once they have enough of them, they are organizing them as blocks. Then, they compute the proof of work of the block. But before that, they add a transaction to the top of the block. This transaction is their reward. The system allows miners some amount of the crypto currency for each block. This special transaction does not need a signature. And this currency does not come from another user. This is the creation of a new currency. That is the way new crypto currency is created. They are miners that are mining for currency. Once a miner finishes with a block, it broadcast it to each user so that can then complete their block chain. Of course, the miner must abide by the network rules.
There is also a validation mechanism to decide which block to add to the block chain. In practice, there are many miners that work on the same list of transactions. There could be that two miners complete the same work and try to add the same block to the block chain. In that case, the first one is taken. If two block chain are diverging, the longest block chain is the valid one. The discarded blocks are sent back to the miners so that the transactions are not lost.
The block chain reward is generally decreasing over time to guarantee a limit on the total amount of cryptocurrencies in the system. Moreover, the difficulty of computing the proof of work is also increasing over time. The idea is to keep the time to create a new block constant over time. In addition to the block chain reward, miners also can take into a fee (in crypto currency unit). This is an incentive for them to include the transaction into the block that they are working on.
You should now have a better understanding on what are cryptocurrencies and how they are working. The model I have described here is the really the basic model. Some cryptocurrencies can be a bit different of course. Cryptocurrencies are not so difficult to understand. They are a digital currency with a shared ledger of all the transactions. Cryptocurrencies rely on computing power to validate all the transactions from the network. They are very safe, using advanced cryptography to make sure that nobody can forge transactions.
Of course, they are more complicated than your usual currency. But I think the concept is very interesting. I am not saying it is a good investment. I think it is not a good investment. But I will discuss that in more details in another post.
In the next post of the cryptocurrencies series, I will talk about the history of cryptocurrencies. How it all started and what is going with them now.
Do you understand better how cryptocurrencies are working? Are you investing in them?