Saturday, February 12, 2022

Byzantine Generals Dilemma and Blockchain

 



Summary:

Blockchain needs consensus within a large number of nodes, and Byzantine Generals Problem articulates the challenge. 

In simple terms, the Byzantine Generals Problem (BGP) involves arriving at the right decisions without full information or even some faulty information.

This concept is taken to novel level in Blockchain, a Proof of Work makes it very hard to tamper with information being presented to a large number of independent nodes. 

____________

Blockchain (for most of us synonymous with BitCoin) is a collection of technological inventions made possible by the advent of computing power. One of the central ideas is the consensus (or agreement) between participating computers (/parties/nodes) on what is an acceptable state of affairs by mutually agreed rules. Interestingly, Satoshi Nakamoto achieved this through a practical and novel solution to an existing distributed networking problem, the Byzantine Generals Problem (BGP). While explaining reliability of a computer system in-spite of having malfunctioning components, Lesle, Robert et all used fictitious battle situation, adding complexity to earlier 2 Generals Dilemma (https://people.eecs.berkeley.edu/~luca/cs174/byzantine.pdf).

Bit of history – The Byzantine Empire (aka the Eastern Roman Empire) was the continuation of the Roman Empire in its eastern provinces during Late Antiquity and the Middle Ages when its capital city was Constantinople (modern-day Istanbul). It survived the fragmentation and fall of the Western Roman Empire in the 5th century AD and continued to exist for an additional thousand years until it fell to the Ottoman Turks in 1453. During most of its existence, the empire was the most powerful economic, cultural, and military force in Europe.

Suppose you are a General from the Byzantine Army on a campaign and have targeted an enemy city. Along with other Generals, you have completely encircled it. You can communicate with other Generals only through messengers. All of you Generals got to agree on a simultaneous action: attack together or retreat together. If not, a half-hearted charge at the strong enemy will ruin your career, handing you a sour defeat. It would be a very simple solution if all generals and/or messengers were trustworthy. But some of the messengers and even a few generals /commanders are traitors.

So, the problem statement is how all loyal generals decide upon the same plan of action, ensuring that a small number of traitors cannot cause the loyal generals to adopt a bad plan. Solving this needs to consider how Generals reach a decision. The first condition can be achieved by having all Generals use the same method of combining information, and the second needs a robust method, say a majority vote.

The formal description of the Byzantine Generals’ Problem adapts a strict military chain of command to achieve common action (attack or retreat), 

  1. All loyal lieutenants obey the same order 
  2. If the commanding general is loyal, then every loyal lieutenant obeys the order he sends.

Consider a decision “attack at Friday 0200 Hrs”. Then the objective is (overly simplified) 

Each General sends this message v(i) to each of the other Generals. Then, the problem statement becomes

  • Every loyal general must obtain same set of information v(1), v(2), …v(i), … v(n), on which they somehow arrive at same decision

But then there may be a traitor General (or his messenger switched), and we need to establish the message is from a loyal General, hence

  • If the ith General is loyal, every other loyal General should use the same v(i) from him. 

This means that

  • Every loyal General must use the same information v(i) from the General, whether he is loyal or traitor!!

With some mathematics, it can be shown that if there are m traitors, fewer than 3m + 1 generals can’t arrive at a consensus. Real-life complexity compounds the situation, such as correct message delivery, knowing who messaged, and detection of missing messages, etc. But still, it works out to be that if less than 1/3rd of the generals are traitors, your army can act coherently and win the city!

How this relates to networking and Bitcoin:

This story maps neatly onto networking; computers are the generals, and their digital links are the messengers. Hence, a Byzantine Fault is a fault that presents conflicting symptoms to different observers. A  Byzantine Failure is the loss of a system component due to a fault in a distributed system that requires consensus. The objective of a Byzantine Fault Tolerant system is to be able to defend against these failures. A correctly implemented Byzantine Fault Tolerant system should be able to still provide service, assuming that the majority of the components are still healthy.

While BGP found practical applications in networking and complex systems like space shuttles, Satoshi Nakamoto (Bitcoin) developed a practical and novel solution. Instead of a signature that validates a message, the Proof-of-Work concept was introduced.

In simple terms, a list of transactions is bundled together, and the previous block’s hashed header is added to this list. Then, an additional random bit is added to this mixture and hashed to produce a new-sealed-chained block. Finding a suitable random bit used is purely a guessing game requiring hashing repeatedly using different random bits, such that the hashed output is less than a certain target number (all hashed outputs are represented by a number). This repeated hashing requires immense computing power, but once found, it is easy to verify that someone has spent effort doing this, hence PoW.

How does this help to get consensus? Satoshi designed an ingenious consensus method. A block on the blockchain is voted as the right one by thousands of nodes, chosen by simple rules and validated asynchronously. The key is not being able to alter a long chain without spending a great effort within an impossibly short time window.  

Suppose, as a Byzantine General, you take 10 minutes (the average time targeted to create a block in BitCoin) to create and seal the message; sealing needs a special mix of gums (equivalent to a random bit). It’s a long message role with all previous messages, too. So you (node A) send the (sealed, sealing takes 10 minutes) message to all other Generals, ‘attack’. 

A General (say node B) gets your message, takes 10 minutes to further seal it with his own message, and sends out all generals. For example, a general C would see “B says attack | A  orders attack”. Now, C is a traitor. C wants to change messages to “withdraw”.  He also has to change the messages of A and B to make this happen. That takes 20 more minutes as he has to recreate the random bits used by A and B over and above 10 minutes to find his own random bit satisfying sealing requirements. 

Next, General D receives either in 10 minutes “C orders withdraw |  B orders attack | A orders attack” or in 30 minutes (after C spent time fiddling with earlier messages) “C orders withdraw | B orders withdraw|  A orders withdraw.” In the first case, it is easy to see him as a traitor, and in the second case, too, the inordinate delay gives him away. By design, it is practically impossible for C to prepare all 3 messages in just 10 minutes.

This is a neat way to avoid double-spending Bitcoin money. Someone can’t send two differing transactions to nodes or go back in time and alter them. The first one is rejected by consensus rules of validation, and the second is impossible given current computing power.

Bitcoin’s decentralized consensus results from its design. The nodes independently verify each transaction based on a comprehensive list of criteria. Mining nodes aggregate those transactions into new blocks and add a random bit through lots of guesswork to meet criteria on hashed number output. Testing whether the random bit meets the condition is easy, but arriving at the first right random bit meeting the conditions is not. Hence, you can easily check if someone has spent enough time (hence proving the work) to find the right random bit. Every node continuously validates these random bits and selects the longest chain of blocks that has the longest cumulative linked and proved chain. Anyone wants to change a past entry will need to solve all the past random bits to represent an alternative chain to all nodes, longer the chain it becomes impossible to beat the system, because another block would have added and longest one gets selected!  

This novel way to solve BGP has proved useful and is creating new thinking in the fields of distributed computing and econometrics. Time stamping and immutability help with, say, digital money (of course, BitCoin), fairness in election voting, asset registers, digital notarization, etc. This seems to be only the beginning of a massive decentralized consensus economy.



No comments:

Post a Comment