Whenever we discuss the blockchain technology, we usually begin with Bitcoin. The reason for that is quite simple: everybody is familiar with the term Bitcoin to some degree or other. Bitcoin operates on the basis of a distributed database of transactions — the so–called blockchain. In even simpler terms, a blockchain is a set of protocols and technologies for distributed storage of transaction data, while Bitcoin is a crypto currency that utilizes such properties of blockchains as decentralization and anonymity to achieve greater stability and earn more trust from users. The blockchain is structured in a way that network participants automatically reach a consensus on the contents of the blockchain records, while guaranteeing the invariability of records and the overall network security. Let me illustrate this using an example: suppose you need to transfer funds using a blockchain protocol. Transactions happen among a certain number of network participants among whom trust is not required. There is also no need for the involvement of a particular centralized trusted authority (such as a bank) that would guarantee the validity of transactions.
How Does it Work?
How can a consensus be reached in a distributed network where participants do not trust one another? The secret is quite simple: a blockchain is not merely a technical implementation of the transaction transfer protocol; rather, it is a kind of ecosystem at the juncture of technologies and economic principles. In other words, a blockchain loses a number of its properties in the absence of economic principles. Let us begin by looking at the blockchain structure from a technical perspective.
As its name suggests, it is a chain of blocks:
These blocks and their chain are generated according to specific rules and synchronized among all network participants.
In turn, each block consists of a header and a list of transactions. The block header in turn includes: its own hash, the hash of the previous block, the hash of transactions, and additional service information.
The hash of any block consists of the hash of transactions. As a result, all information about the completed transmission of data is stored, and it cannot be spoofed without replacing the entire block. In this way a block becomes a kind of container for a set of transactions. Meanwhile, the presence of the hash of the previous block allows arranging blocks into a chain and provides protection against block spoofing.
Let us look at the rules according to which a block is generated. Here are a few essential principles that guarantee a transparent and decentralized network:
- All network users have access to the complete copy of the blockchain and store (or have the capability to store it on their systems;
- Any network user can generate blocks;
- Users are rewarded financially for generating blocks;
- A computing problem has to be solved to generate a block.
Now let us examine this in more detail. The first and second items on the list are more or less clear. We should only mention that storing the entire database copy is not obligatory in modern versions of blockchains. Regarding the third item: users are rewarded for generating a block, which creates an economic incentive to attract additional users who will generate new blocks. This process of creating blocks is known as mining and the person creating them is called a miner. We will come across this term many times subsequently. The fourth item is the most interesting of them all. What kind of computing problem is that? This is where the Proof of Work principle comes into play. Incidentally, it deserves a whole separate chapter.
The problem can vary depending on the blockchain implementation. As a general rule, it involves computing a certain hash in a way that allows solving the problem only using the brute force method.
Proof of Work (PoW)
Since Bitcoin is the most popular crypto currency, let us examine the operating principle of the blockchain as exemplified by this currency. Imagine that you have a set of transactions that are not yet included in the blockchain but are only candidates for inclusion. Miners receive these transactions and enter a competition of sorts for who can generate a specific block sooner than others and receive a reward. As I mentioned earlier, generating a block requires solving a certain computing problem. The problem involves generating a hash (the SHA–256 function). It should not be just any kind of hash; its numerical value has to be less than a certain number N. The result of SHA–256 is unpredictable, which is why the right hash can be chosen only using a brute force search. This usually requires a large number of recalculations that use up CPU/GPU resources of the mining computer. Once the block hash satisfying the rules has been found, the miner generates a block and sends it to other network participants for verification. If the block has been generated correctly, it is included in the chain and the miner receives a reward. Note that the rate at which blocks are generated does not change despite the growing network capacity (number of participants). The speed is balanced by complicating or simplifying the computing problem (by increasing or reducing the number N).
Why is all this needed? The network is distributed, and sometimes a parallel branch of blocks can form because miners were either unaware of one another or acted wrongfully on purpose (e.g., to perform the transaction in one chain and then spoof it in another). How should the only valid branch be selected? A rule applies whereby the main branch is the one where more CPU/GPU resources have been expended on generating this branch, i.e. essentially the branch containing more blocks. So if a miner starts a separate branch of blocks with its own history of transactions (either accidentally or intentionally), this branch will be declared dead sooner or later and discarded by the network. Transactions in this branch are canceled.
A separate branch can become the main branch only if it is longer than the main branch (black); this can happen if more CPU/GPU resources are expended on generating the branch compared to the other branch. This is in turn possible when somebody controls 51% of the network's computing power.
This was a description of the most basic blockchain operating principles. Now let us move on to online voting and discuss its difficulties and nuances.