Blockchain the eyes of a developer
Why this story? When I studied the blockchain in open sources, such as Wikipedia, the information seemed sketchy and incoherent. Time passed before she formed a coherent picture. I think I know in what order and what words to describe the introduction in the blockchain that any professional developer can understand the overall picture for 1-1. 5 hours. In the text there will be some simplification. It is clear that in any subject there are many parts where you can, if you wish to take.
let's Start. Long asymmetric cryptography. Let me remind you, there are public and private keys. Open encrypted decrypted private. Or Vice versa. One of the other to impossible. Thus, using only asymmetric cryptography, I can send someone a message, for example: "I transferred 100 rubles," thus all will know that it sent it I and that it is delivered without modification.
Let the ten men agreed that each of them has a million new currency. Each of them can confirm (and can verify) that he had sent 300 thousand of that currency to another. It is unknown if he had available the 300 thousand or not. To get this knowledge, you can know the balances of each. To do this, simply mathematically add up all the receipts of money, and subtract all the expenses of the person. Thus, required all transactions of income and expenditure. Hence the public ledger, public Ledger. It will say, can a person send 300 thousand.
Bitcoin:
one problem Remained: what if I send all their money at the same time two? It's a double spending or double-spending. Of course, these two should not simultaneously receive on account of an amount equal to my balance before the surgery. And to sort out among themselves who came the payment to them is also inconvenient. To focus on time stamps (to whom I sent the money sooner) is unreliable. There is a solution: arrange the transaction. Then just be clear that the first payment went Bob, and I just can't do: no money. But now it is unclear who will speak in what order are transactions. Banks and other centralized systems have the Trustee — the Bank itself, a single point of failure and point of trust. The Bank says, who are gone with my money. In the blockchain a single Trustee no. It can be a big part of the network (of course, that is absolutely the whole network, because each party can not be trusted: there's sure to scammers). It is assumed that it is not controlled by one person and that most of the participants are acting purely in their financial interests.
But the problem is the ordering of transactions is still not solved: we need a so-called consensus among the members of the network. The solution to this problem involved one of the key algorithms of each individual blockchain — consensus algorithm.
Before we talk about specific consensus algorithm, say a few words about the notorious blocks in the blockchain. Blocks — technical measure, batch processing (batching) in order to consider consensus "pack" and "spread" other overhead costs of the network across multiple transactions. The order of transactions inside the block defines one member of the chain — the one who forms the block (a miner). But the block order determined by the algorithm of consensus. Consensus algorithms exist for quite some time. For example, the algorithms Paxos Raft in a MULTIMASTER-NoSQL-systems. But for a network with a million equal participants, they are unlikely to fit.
Bitcoin was a revolutionary at the time algorithm — consensus through proof of work (proof of work, PoW). New units are formed simultaneously by many members of the network — the miners. You need to decide what unit to take as the next. To block became the next block chain, the miner has to produce specially selected a very time-consuming hashing. The unit (along with incrementorum number, a nonce) to the hashed until the hash is being considered as a large number will not satisfy certain conditions, for example until will contain 10 zeros. This will require billions of keshirovaniya — that the work which a miner to "prove" your unit. And to check the correct operation is very easy: you need just one hashing. It is important to understand that the work is chosen so that the entire network (i.e., among the thousands of miners!) there was an average of one block per ten minutes (the average interval of occurrence of blocks in Bitcoin). Under these conditions, the probability of collisions, i.e. simultaneous presentation of two or more blocks as the next, is extremely reduced.
In fact, there is not a chain, and a directed graph without cycles (DAG) with many branches and chains, and a chain is usually called "conventional history" — chain with the greatest length. As consensus could not be achieved immediately, but a few blocks away, you should wait. To make sure that you will not make double-spending, usually waiting six blocks (Bitcoin hour in the Ethereum — a few minutes).
In the unit, except for transactions that present the hash of the previous block. Thus, it is impossible to fix something in the past: wrong will be all subsequent hashes. At the same time with the block is given a reward for mining — hence the new money! Otherwise it would be unclear how, in principle, to introduce money into the system: you need someone to give them, what makes that someone special and contrary to the idea of decentralization. Pay for mining it seems logical and workable solution.
speaking of mining. You need to understand that the main work of the miner is a fierce hashing a new block, asymmetric cryptography is not there, it is only needed to verify transactions before they are added to the block. Bitcoin uses the SHA-256 hash, Ethereum — Keccak-256. If one of mine — will have on average a very long time to live on rice and water before getting the block (the block every ten minutes, and competitors — hundreds of thousands!). Therefore, the miners together in pools. In a pool the reward somehow (there are different approaches) is distributed among the participants, ie you getting more money (of course, smaller than the reward for the block). That is, risk and benefit "smeared". At aspiration of time to infinity Mat. the expectation of profit from mining in a pool (if you neglect the pool fee) is equal to Mat. the expectation of profit from a single hashing.
so far we talked a lot about communication between members of the network, but does not touch the details. And do not touch. It is important to remember that the data are exchanged via a network peering that our transaction through it to reach the miners.
so we've got the technology of the bitcoin blockchain.
Smart contracts and ICO
Go ahead. In Bitcoin over every account, there are two operations: addition and subtraction, and they checked everyone, especially the miners. But what if we add internal variables to the account (storage), and the operations add, for example, comparisons. Suppose I want to stop taking money on your account when you have 10M on it — i.e. it turns out not just adding money to the account balance, and the addition of subject. Developing the idea, received the Turing machine and deterministic — i.e. all the same all can check the status of your account, and you get a smart contract. Further, under smart contracts we mean smart contracts the network Ethereum (Ethereum) as the most popular at the time of this writing.
Determinism means that for the same arguments of the transaction and the same initial state storage the output is the same result and the same changes made in storage. Only under these conditions the network will be able to reach consensus on each transaction. You need to understand what smart contract is quite isolated from the outside world because of the requirement of determinism, verifiability and decentralization. For example, he can't pull Web API in a decentralized style (there is a solution, the so-called oracles, but there are all easy, and that's a separate issue). In addition, the control of the contract over the outside world is extremely limited, for example it is difficult to rent an apartment through a smart contract, exchanging cryptocurrency electronic key (in spite of the glowing prospects, occurring in the Network): I still have to trust the landlord to know that when I come to the door, on top of the electronic lock will not hang the big barn.
to get the results of the work contract (new account or change of storage), network nodes have to perform the operations it is registered. Calculation on the set of the gcd can not be free, so the Ethereum introduced the concept of gas (gas) — not hardcoding the Commission for its calculations in bitcoin, and allow the user to calculate the amount of calculations and set the price. This construction is the additional level of indirection, it allows the user to choose between a cheap transaction and fast transaction.
total on top of the blockchain the bitcoin style we got the technology of smart contracts.
smart contracts Ethereum based a lot of cryptocurrencies, or so-called tokens. Yes, usually, this cryptocurrency is just an Ethereum contract (one!). Balances are records in the storage contract in the form of a map, and the transfer of currency from one to another is:
map[Alice] –= payment;
map[Bob] += payment;
they do not need your hash and your network: they use the infrastructure of Ethereum. ICO/ITO on the Ethereum is the exchange of air (cryptocurrency Ethereum network) for money (tokens). Standard ERC20 says which methods must be defined at the contract cryptocurrencies, due to which a cryptocurrency can be supported by exchanges and from supported e-wallets working with Ethereum.
Further development
on Top of the basic idea of the blockchain in addition to smart contracts there are many other ideas, such as the so-called zero disclosure or self-regulation network.
Zero disclosure is based on the same family of cryptographic protocols, the essence of which is to prove the possession of the object without showing it entirely. For example, I can prove that you own a particular file that is 1 GB, if you can answer ten questions about the bytes in different random positions of the file. In this case, obviously, I will give only 10 bytes from the 1 GB that the relying party, and so probably knows. Because RSA encryption is performed exponentiation, and
it turns out that
Thus, for example, anyone can verify that my account balance was multiplied correctly, with no need to disclose how much money I had in the account! Continuing this idea, you can create money with inside information about balances and payments (and it already is — zcash for) and generally to hide the arguments of the computation in the smart contract.
blockchains are common to the network parameters recorded in the program code of the network such as how many transactions to include in the block. Usually change requires the adoption community network members of these edits (which is reflected in the updated code) and threatens to fork the network (when some participants decide not to accept the edit, they just continue to work on the "old" code). These problems are trying to solve, self-regulation, for example blockchain Tezos. The point is that each edit will be possible to vote by their own means (without loss, of course).
Conclusion
total technology took place the following way:
transaction signature (asymmetric cryptography) + the openness of the transaction + transaction ordering + extension of operations to the Turing machine + (no disclosure | self-regulation | ...)
a few words about the landscape of the block chain. It has been said that there are many cryptocurrencies, representing the Ethereum contracts, i.e., using the Ethereum blockchain. But there are projects in addition to Bitcoin and Ethereum — they can vary in detail (e.g., forks), and pretty much trying to create a brand new baccani, such as EOS.
Bonus
the study smart contracts Ethereum. Infrastructure raw in places (not very useful) but quite reliable. Here is a set of links that studied the writing and the security of smart contracts I (don't forget about safety! At stake is money!). Recommend reading in this order:
the
-
the
- Bitcoin: A Peer-to-Peer Electronic Cash System section 1-8 the
- Just Enough Bitcoin for Ethereum the
- If you just want a little practice: The Hitchhiker''s Guide to Smart Contracts in Ethereum the
- Solidity Documentation the
- Ethereum Natural Specification Format the
- contracts/ Solidity Zeppelin the
- Onward with Ethereum Smart Contract Security the
- Ethereum Contract Security Techniques and Tips the
- of the relevant Hacking, Distributed
Комментарии
Отправить комментарий