Proof-of-Work: The security mechanism on which Bitcoin is built
The Proof-of-Work protocol used in Bitcoin, Litecoin, or Dogecoin, among others, is introduced to prevent unwanted actions in a blockchain. This protocol simply requires work by the user, which will later be verified by the network. This work is nothing more than the performance of a series of complex computational operations carried out by a computer.
What is Proof-of-Work
It is a consensus algorithm based on complex mathematical operations that must be performed by a computer team. Proof-of-Work requires a significant amount of computation but is doable. It serves to deter malicious attackers from launching a denial of service attack or a 51% attack.
PoW is a mechanism used for the confirmation of transactions and the generation of new blocks. Within this consensus, miners compete to validate transactions and generate new blocks. In exchange for their computational work, they receive a reward in bitcoins.
One reason to use proof of work is to prevent double-spend attacks. It also seeks to make performing a 51% attack so costly that launching one of these attacks is not feasible. All this is ensured by a complex mathematical puzzle and the simple proof of the solution.
Origin of Proof-of-Work
One of the biggest growing problems in the 1990s, when the internet became popular, was spam. We are talking about the massive sending of spam by the end-user. Sending thousands of emails is very simple and the cost is minimal for those who want to send them. To do this, a system called proof of work was devised.
In 1992, IBM Research Department workers Cynthia Dwork and Moni Naor devised the Proof-of-Work algorithm to combat spam. Such a mechanism requires the sender to do a little work that is added to the mail as a signature. This job takes just a few seconds, enough to make it costly in time and resources to carry out spam. And is that spam is based on sending hundreds or thousands of emails in the shortest amount of time possible.
Adam Back, back in 1997, picked up this anti-spam solution and added it to his anti-spam project called HashCash. What’s interesting about Back’s solution is that it uses pretty much the same cryptography that Bitcoin technology uses today. Satoshi Nakamoto, in the Bitcoin whitepaper, mentions the solution developed by Back.
This means that the Proof-of-Work consensus algorithm is much older than its implementation in Bitcoin. Although it was initially developed to combat spam, it has become a security system for cryptocurrencies.
Proof of Work Features
Prevent double spending
Process of spending the same funds on more than one occasion. The possibility that there is double-spending in a cryptocurrency would mean that it would not be useful. A user could use the same number of coins repeatedly without incurring a cost. This means that the coin is worth nothing since no seller will accept it.
A security element is required to prevent precisely this. To do this, a computationally complex mathematical puzzle has been established that prevents this process. Any attempt to tamper with a transaction validated and added to a block is impossible. Manipulating a transaction means manipulating the block, which has a brutal computational cost.
The computational cost of manipulation grows exponentially the older the block is. If the chain has 1000 blocks and we want to manipulate a transaction from block 700, we will have to manipulate the transaction, the block, and the next 300 blocks. But in addition, all the new blocks that are added to the blockchain must be manipulated, since it does not stop. Then, all owners of a copy of the blockchain must accept the new chain, something that is not feasible, since the scammer will be quickly detected.
The math puzzle
When we talk about math puzzles, we are talking about a math problem that requires a lot of computation. To solve the calculation, complex operations only accessible to computers are performed.
Bitcoin makes use of a hash function system. This system establishes that from some inputs we will obtain a semi-random output based on mathematical rules. The output has a length based on the cryptosystem used. What the miner knows is the output and must find the input parameters based on brute force (and a bit of luck)
All miners compete to be the first to solve the math puzzle on equal terms.
The problem must be computationally difficult, but not so difficult that it slows down block generation. If it were too hard, the transactions would pile up and that would make the network absurdly slow. If the blocks cannot be generated in the expected time, the network will become congested and the cost of using it (transaction fees) will skyrocket.
Nor can the math puzzle be overly simple, as this would lead to problems. It could be very cheap to launch a denial of service attack or spam attack.
The integration of a mechanism that dynamically adjusts the difficulty is required. Bitcoin, like any other cryptocurrency, adds mechanisms that do it from time to time. For Bitcoin, the difficulty of the math puzzle is adjusted every 2016 block.
How is the proof of work?
We must understand that the transactions when they are made and launched, are announced transactions. These transactions must be included in a candidate block, which is a block that is postulated to be added to the blockchain. Transactions and candidate blocks are only considered “good” when the block is added to the blockchain.
Including a block in the chain is not cheap, the miner is required to pass a proof of work, based on the resources offered to the network. The resource of a mining node is the computing power to calculate the hash of the block data until it finds the solution to the problem.
This process requires all data in the block to be hashed to generate a valid hash. Note that the hash acts as a unique and unrepeatable identifier for the information stored in the block.
Reversing the hash of a block to get the inputs is impossible, well practically impossible. Finding inputs from output requires an enormous amount of computing power (and luck). But if we know the input, confirming the hash becomes trivial. It is required to pass the input through the hash function, obtain the output and compare them to verify that they are correct.
The randomness of the hash
The proof of work requires that a series of data be given whose hash meets certain conditions. The problem is knowing how to get that hash. We must pass the data through a hash function and check if the conditions are met. If the obtained hash is different, we will have to modify the data slightly until the two hashes coincide. We have to take into account that modifying a single character supposes modifying the output. For example:
|Input-||Output (passed through the SHA-256 algorithm)|
|bitcoin is money||0A0E9D4319FB2C2C1A41777FB5F3E173D44E17249EDA33B7A491933E552A8F94|
|bitcoin is money||B47983C3621EE91AD11F73A01121BB66BC23375B1CC10D9D5E60BD7238078E25|
|bitcoin is money||2E2613F96206B48A257D5FBF4759F6B1621E2861753702FE58D7766049B1B891|
Generating a block is playing guessing games. What is done is to take all the information of the transactions that we want to add and other important data, finally combining them. The data set will not have variations, so we must add an element that can be variable. If we don’t add a variable value or parameter, we will always get the same output hash. The variable parameter is the nonce, a number that is only used once and is changed on each try. All this is the basis of mining.
Simply put, mining is a process of collecting data and combining it with a nonce to obtain a specific final hash. When we get a block that meets the network’s consensus rules, we can add the new block. The rest of the network members’ copy of the blockchain is updated to add it.
The higher the hash rate of a blockchain, the more difficult it is to find the valid hash. This mechanism is added to ensure blocks are not found too quickly. It implies, therefore, that finding a massive amount of hashes with specialized computer equipment is very expensive. It is a waste of computing cycles and electricity. That is, if we find the valid hash, we will receive a reward.
To move the funds, proof is required that indicates that they are ours and therefore, we are authorized to move them. An asymmetric key mechanism is used for this. The asymmetric key is based on the generation of a private key that consists of a series of random words and from there the public key is obtained. Generating a public key from the private key is very easy, but the reverse process is extremely difficult.
A transaction requires a signature. The network verifies the signature with the public key and checks if both match. The next step is to check if there are funds and if they can be moved. It is also verified if the sum of the inputs is greater than the outputs, or what is the same, that you are not spending more than you have.
Invalid transactions and blocks that include them will be automatically rejected from the network. Making a false transaction means losing the commission paid to the miner who validates the transaction. Creating a block with a fake transaction is a sterile computational expense that will not get rewarded for the resources spent.
Proof-of-Work precisely what it does is that being honest is very cheap, but cheating is expensive in money, resources and time. Come on, the mechanism punishes malicious attackers and rewards good actors.
Putting Proof-of-Work in the balance
What strengths does proof of work have?
The most important points of the Proof-of-Work consensus, which give it great strength, are:
- High security: The greater the number of miners in the network, the greater the security of the network. This makes this type of consensus mechanism so interesting for large distributed networks.
- Simple implementation: It is characterized by being a very simple consensus to implement. It makes it easy, requiring only mining software that makes use of this mechanism. Additionally, it simplifies audits, making it very easy to maintain network security.
- Adaptable to hardware: It can be a mechanism to generate or implement add-ons that provide resistance against certain types of computer equipment. It is also adaptable to technological advances, making it easier or more difficult. It also allows the difficulty to adapt to the power of the network, adapting to the inclusion of new members and new technologies. Additionally, it is a mechanism that seeks to minimize the centralization of mining.
- Resistant to malicious attacks: This mechanism was developed in 1992 to prevent spam and also to prevent denial of service attacks. A resistance that they have shown on countless occasions.
- Resource consumption Requires computational work that in turn requires energy consumption. This factor makes attempting to cheat costly and deters malicious attackers from launching an attack. Also, good actors are rewarded for being honest.
What Weaknesses Does Proof-of-Work Have?
The Proof-of-Work consensus mechanism currently has two major problems. These are:
- 51% attack: It is an attack in which most miners collude to manipulate the network. It assumes that attackers have enough power to control most network events. It allows monopolizing the generation of blocks, to receive rewards, rejecting the blocks of the rest of the network. In addition, they can reverse transactions or double-spending. For this type of attack, n/2+1 miners are needed, where ‘n’ represents the total number of miners in the network.
- Energy consumption: What is a great strength, such as the computational capacity that makes manipulation difficult, becomes a problem when we talk about energy. A miner requires good cooling and has a high electrical consumption. If we multiply this by hundreds or thousands, which is usually the number of miners that farms have, we are talking about enormous consumption. The problem is that most of the energy comes from polluting sources, becoming one of the main aspects for which mining is attacked through proof of participation.
Final Words on Proof-of-Work
The proof-of-work consensus mechanism has the strength of being highly secure and penalizing malicious attackers. To try to manipulate a transaction or movements in the Bitcoin network, for example, we would currently need a huge amount of hardware, which is extremely expensive. Additionally, we would need huge amounts of electrical energy. Precisely this strength, in smaller cryptocurrencies, can be a problem, as it already happened with Vergeoin, which suffered a 51% attack some time ago.
The good thing about this mechanism is that it adapts perfectly to changes in hardware and the entry and exit of miners from the network. Mechanisms are introduced to adapt the difficulty of mining according to the computing power of the network and the number of members of the network. It is also on the positive side that tampering attempts have enormous costs in computing power, time, and energy. This last parameter, energy, is the weak point of the proof-of-work consensus and is used by critics of cryptocurrencies to launch attacks. Although precisely this cost in electrical energy is what gives cryptocurrencies and Bitcoin security.
What do you think about proof-of-work consensus, is it a good thing for the security it offers, or is it just a waste of energy and resources?