Decentralized digital currency. Part 1. Bitcoin



The theme of various cryptocurrencies and blockchains today has become quite popular and has ceased to be a lot of geeks, boomy about the revolution in the field of finance. But as soon as you try to delve into this topic, you will immediately encounter an information deficit: there is very little material that describes what is available, to the best of technical knowledge, about the concept and mechanisms of how these technologies work. Conventionally, all materials can be divided into two categories: either hardcore technical, where the first sentence begins to cry about cryptography, p2p, “digital gold”, etc., or marketing nonsense about the new Internet, capitalization of Bitcoin or as a kind of company / country I introduced the blockchain and solved all my problems. If you want to understand how this all works and what can be done with these technologies, then these articles are for you.







I will try to convey the basic idea of ​​a decentralized cryptocurrency, the mechanisms of its work, as well as disassemble the various Bitcoin forks. I specifically omit many technical details so as not to burden the text. The main thing is to understand the essence, and then you can easily understand the wilds on your own.







Part 1. Bitcoin

Part 2. Other (non) popular varieties of Bitcoin, blockchain

Part 3. Ethereum







Idea



As soon as we try to understand the mechanism of Bitcoin's work, we immediately begin to conflict with our usual way of thinking, which flatly refuses to accept the concept of an uncentralized control system, without the levers of power influence on violators. But the question immediately arises: if nobody manages Bitcoin, how does it function? In 2008, a certain Satoshi Nakamoto came up with an elegant solution in which each member of the network trusts only his own base, which he maintains on his own, and the majority base if he does not have any records.







Let's try to explain on the fingers using the example of a small village that has decided to abandon paper money circulation and introduce a decentralized currency. Let it be a special village in which all residents know each other by name, can recognize by voice, are very well versed in shades of colors and worship the royal-purple color. So, residents agree that the new currency will work as follows:







  1. All monetary movements are public, i.e. everyone knows who, to whom, how many listed;
  2. When someone wants to transfer money to someone, he publicly declares this: I, John, transfer 100 coins to James;







  3. Each resident has an accounting journal that fits all the money transfers that he heard. All translations of the day are recorded on one page, and the next day start with a clean slate.







  4. By the end of the day, residents perform a strange ritual that fixes all transactions for that day, since the transaction is not considered valid until it is fixed. The ritual is laborious, but you can get a reward for it and therefore everyone wants to participate in this process. The procedure is as follows:


4.1. For each transaction from this day, according to a special formula, a paint of a certain color and quantity is selected depending on the amount of transfer and recipients. Then all these jars of paint are drained into one vat and stirred well.







4.2. The ritual requires bringing the resulting mixture to a royal-purple color. To do this, in small doses, by a long and exhausting search, different colors are added to this mixture;







4.3. As soon as someone finds the necessary colors and their doses, he immediately records these data at the bottom of today's page, credits 50 coins to his account as a reward and announces it to all residents.







4.4. Residents quickly check whether he really found the correct proportions. If everything is correct, they approve the transfer-reward, close today's page and go to sleep.













Now more on the points:







  1. As we remember, residents can easily identify each other by voice, respectively, if someone tries to transfer money not on their own behalf, the residents simply ignore this statement, and no one will make this transfer to their records.







  2. Since all transfers are public, everyone knows how much money each resident has in his account, if John doesn’t have enough money, his transfer is ignored (no one makes his own records). Ideally, a single chain of records should be the same for everyone.







  3. If someone has lost his journal or missed some translations, he polls residents and synchronizes his records. At the same time it is necessary to rely only on those records that are agreed with the majority.







  4. Selection of the required dose and colors of paints is a very laborious process, and it is very easy to check the result of the work. Just take the transaction for that day, according to the formula, prepare the mixture and add the ink to the vat according to the declared dose. If it turned out royal-purple color - then everything is correct and residents agree to reward those who found these proportions. Once the page is sealed, all transactions are considered valid and remain in history forever. Thus, the integrity of the database is preserved, and new money flows into the system. The amount of remuneration is halved every 4 years, which limits the total amount of money in the system. And if you add the proportions of colors from the previous page to the next page, the pages will be linked and no one can change transactions retroactively. At the slightest change in the records, it is necessary to recalculate the dose of ink for this and all subsequent pages; in addition, most residents should be convinced to replace their own records with new ones.


Each network participant decides for itself whether to accept fraudulent transactions or not, and as long as the bona fide participants are in the majority, the system will function as it should. But what does “how to” mean, what goals did the developers of such a decentralized currency set?







  1. The amount of money in the system should be limited, in this sense, the currency is like gold. No one should be able to print a lot of money, which in turn can lead to inflation and the depreciation of savings.







  2. Remove restrictions associated with the minimum units of the current monetary system. For example, you want to sell your services for 1 kopeck, and maybe for a hundredth of a penny.







  3. The guarantee is that any correct generated money transfer will be carried out, due to the lack of a single point of failure, unless the entire Internet is disconnected. No organization, not even a state, should be able to roll back / block a transaction.
  4. In order to deceive the system or change the rules, it is necessary to convince the majority of participants (> 50%) of the network, etc.


Implementation



If everything is clear with the underlying idea, then we can move to a simplified technical implementation. Next, you need to know such things as hash, public key encryption and digital signature.













Each network participant generates an account / accounts for itself, where the account is just a pair of keys generated by the ECDSA algorithm (public key algorithm for creating a digital signature). The public key of the pair is used as the address of the account, and for transferring money from the account it is required to sign this transfer (transaction) with the private key. The transaction is broadcast to all network participants where there are special participants, miners, who are engaged in forming a single, consistent chain of history of all transactions (blockchain). Miners pack current transactions into a block simultaneously checking their correctness. In addition to the list of transactions, the block contains a hash from the previous block and some NONCE value. In order for the block to be considered correct, it is necessary to select a NONCE such that the hash of the whole block will be beautiful (with a large number of zeros at the beginning).







Since data hashing gives completely unpredictable values, it is very difficult to select this NONCE. The first transaction in the list of transactions is a special transaction (block reward) which awards the miner with a certain amount. As soon as the miner selects the required NONCE, he notifies everyone and other miners check the result of his work. This process is called mining, a single chain of blocks is created at the expense of it, and miners are rewarded for this work. The verification procedure is very fast, all transactions and the hash of the entire block are checked. If there are no errors and frauds, then each miner includes this block in his blockchain and continues to mine. If the block is included in the blockchain, then all transactions are considered to be completed, including the very special transaction that transfers the reward to the miner’s account.







Summing up





The next part will describe the current limitations and problems of Bitcoin, as well as a survey of forks aimed at solving various problems.







Literature: on bitcoin and on Gitkhub .








All Articles