As previous Blockchain foundations post , a consensus protocol is mandatory to operate a blockchain network.
The protocol is a key properties to determine the network specifications as the images below:
- Security/Consistency vertex represent for ability to prevent from attacking such as double-spending or blockchain manipulation
- Decentralization vertex represents for how power in blockchain is allocated to all the participants
- Scalability vertex represents the ability to handle transaction , usually measure by Transaction Per Seconds (TPS)
There is a solid mathematical proof that there is no consensus protocol could achieve 3 vertexes. On the other hand, a consensus protocol could maximize 2 over 3 vertexes.
At least , this proof could be wrong if the quantum technology reach a mature milestone and there is no limit in resource and physics could block the blockchain.
What is the consensus protocol ?
The consensus protocol , in a word , it is a rule for all of the participants ( also called node ) to follow in order to add a block (data) to the blockchain.
The power or blockchain government ability is define in the rule. In the example below, each node holds a copy of ledger (full blockchain data) . In order to add new data to this ledger, all the node must agree on this modificaiton.
- sender : send 1 USD from A -> B
- A node receives the request -> validate signature (based on predefined cryptography)-> follow the rule to add this data to the ledger -> generate proof
- Broadcast the new update data to other nodes with a proof
- Other nodes receive the broadcast message contains proof -> validate the proof correctness -> add the new data to its ledger
- The whole network has sync the ledger data
- Receiver query the balance of B from any node -> get the balance of B
The consensus protocol has to define what is the transaction’s proof in order for adding it into the ledgers on every nodes .
Let’s dive deeper in the way Proof Of Work(PoW) define the proof.
Proof Of Work
As the name of this consensus protocol, it needs a proof proving that the node has been finish a lot of work.
The rule to generate the proof based on guessing number game , the node need to guess a number until it satisfy the condition of the network. The steps of the game are :
( the hash algorithm could be demonstrated in https://passwordsgenerator.net/sha256-hash-generator/ )
- Receive request from user with data: A send to B 1 USD
- Find a random number call Nonce, that satisfied the SHA256(“Previous block hash + A send to B 1 USD + Nonce”) having first-4-character all 0
- for example:
- SHA256(“Previous block hash A send to B 1 USD + 1“) C2575AB80D094F47FA57367F1B60CED33C6A40F1574BDD61756F32CA5323D8AD
- SHA256(“Previous block hash A send to B 1 USD + 2“) -> EE65B28B7FADFFEDBF8B2C556F11D66AA02ABB2992CD304C89F89FE53388019B
- As the above example, it demonstrate the difficult to generate a block with proof , the probability to find a Nonce to have first-4-character all 0 is about 36^64 / 36^68 = 1 / 36^4 = 1 / 1679616
- With the probability 1 / 1679616 , the node takes time and effort try to guess the Nonce as soon as possible before other node ( if the Nonce is finding after another node, the whole process must be repeat , due to the “Previous block hash” is updated.
- In the practice , the difficult level is much more than first-4-character , it could be 20 or more. The higher the difficult level, the more guesses need to be done by the node.
- This guessing number proof does consume a lot of energy wastefully
- 51% attack is possible to break this proof , it depend mostly on the total hashing power of all the nodes in the network
- it could add a malformed data to the blockchain if 51% hashing power is belong to someone
- The guessing processing always cost a fixed amount of time , thus , TPS have a upper-limit is about 5-30 transaction per second.
- Application Specific Integrated Circuits ( ASIC ) is a one of factor that made this guessing number proof cannot decentralized effectively. The hashing power of ASIC is much higher than a usual computer and it also costs much less energy -> hashing power is under control of some ASIC producers.
Proof Of Work is a basic proof to decentralized the blockchain to all of the participants effectively. The entry level of this proof is low , thus, anyone has a computer or ASIC could be take part in the network. However, it has a lot of downsides and too difficult to scale up.