Computer science, explained

The Byzantine Generals Problem

Three armies surround a city. If they all attack together, they win; if they all retreat, they live. If they split, the ones who attack are wiped out. Their only way to talk is to send riders through enemy lines.

Read9 min
ForAnyone curious; no background needed
HowScroll, and tap where it asks

Puzzle 1 · The lost messenger

Everyone is honest. Messengers can vanish.

Puzzle 2 · The liar

Every messenger arrives. Someone lies.

Can the loyal generals ever be certain they will act as one? The story above hides two different problems, and computer scientists study them separately. In the first, called the Two Generals problem, everyone is honest but riders can vanish. In the second, every rider gets through but someone is lying; that is the Byzantine Generals problem itself. Both have surprising answers. We’ll take them one at a time, but first, the rules.

Puzzle 1 · The lost messenger

“Got it.” “Got your ‘got it.’” …

Start with just two generals, A and B, both completely honest. A wants to attack at dawn, but only if B attacks too. The only danger is the valley between their camps: a rider sent across it can be captured, and his general never finds out.

Predict

General A sends “Attack at dawn.” General B sends back “Got it.” Both riders happen to get through, but each general knows only about the rider who reached him. Can each general now be certain that the other will attack?

Riders sent: 0

Answer the question above to start.

A’s rider gets through, so B knows the plan. But A has no way to know that. For all A can tell, his rider is lying in a ditch.

So B sends a rider back with “Got it.” When it arrives, A can relax. Now B is the one wondering whether his rider made it. If it didn’t, A may hold back, and B would attack alone.

So A sends a rider to confirm the confirmation. Now B can relax, and A is the one left wondering. See the pattern?

Your turn. Tap Send another rider as often as you like. Can you find the rider that ends the doubt?

There isn’t one. Whoever sends the last rider can never know that it arrived, so certainty would take an endless chain of confirmations. This was the first problem in computer communication to be proven unsolvable.

Real networks, including the internet’s TCP protocol, don’t solve it either. They live with it and shrink the doubt, much like sending a hundred riders: failure becomes very unlikely, but never impossible.

Puzzle 2 · The liar

The liar in the ranks

Now flip the danger around. We’re back to three generals, but this time the roads are safe.

Goal 1 Every loyal general does the same thing.

Goal 2 If the commander is loyal, they follow his order.

Without goal 2, “always retreat” would be a cheap win.

The rules: what changes for Puzzle 2

  • A messenger can be captured on the way. (No longer true.)

  • Every messenger arrives, carrying his message exactly as it was given to him.

  • The general who receives a message always knows which camp sent it.

  • Each general knows when a message is due. If one he’s expecting hasn’t arrived by then, he knows it isn’t coming. That deadline comes back at the end.

Messengers are still the only way to communicate. The danger now is a general who lies.

One general is the commander. He decides, and sends his order by messenger to the other two, his lieutenants.

To double-check, each lieutenant sends the other a messenger saying which order he got. With nobody lying, both attack, and both goals on the card are met.

Predict

Now every messenger arrives, but one of the three generals might be a traitor who lies. The two loyal generals can send each other as many messengers as they like. Can they always end up doing the same thing?

Through Lieutenant 1’s eyes

Here is how one traitor beats two loyal generals. Put yourself in one lieutenant’s boots.

Answer the question above to start.

You’re Lieutenant 1. The strip at the top shows every message that has reached you, and the two don’t agree. One of the other two generals is lying. Which one?

Maybe Lieutenant 2 is the traitor. Then the commander is loyal, and goal 2 says you must follow his order. You attack.

Or maybe the commander is the traitor, giving each lieutenant a different order. Then Lieutenant 2 is loyal, and is honestly passing on the order he got.

You get the same two messages, word for word, in both worlds, so nothing you receive can tell you which world you’re in. You must attack in the first world, so you attack in the second one too.

Explain

Lieutenant 2 is in the mirror image of your spot: the commander’s message to him says RETREAT, and your message to him says the commander said ATTACK. Using the same reasoning you just used, what must Lieutenant 2 do? Think it through, then reveal.

So in the second world you attack and Lieutenant 2 retreats. The loyal generals have split, and goal 1 fails. Two loyal generals couldn’t outvote one liar, because neither could tell who the liar was. And a smarter rule wouldn’t save them: the full proof shows that whatever rule the lieutenants agree on in advance, one traitor among three can break one of the two goals, either by splitting the loyal generals or by making them disobey a loyal commander.

Add a fourth general

Now add a third lieutenant, and keep the same moves. The commander sends his order to each lieutenant. Each lieutenant then sends the other two a messenger reporting the order he got. Finally, each lieutenant goes with the majority of the three versions he now holds. Walk through two cases, then put on the traitor’s mask yourself.

However you play the traitor, the loyal lieutenants agree. A lying lieutenant is outvoted by two true copies of the order. A lying commander can send different orders to different lieutenants, but because the others relay honestly, every loyal lieutenant ends up holding the same three values, so they all reach the same majority.

That turns out to be a general rule. When a liar can put anything he likes in a message, agreement can be guaranteed only if more than two-thirds of the generals are loyal. Three generals with one traitor falls short; four is enough.

Call the number of traitors f and the number of generals n. For the loyal generals to be guaranteed to agree, no matter what the traitors do, you need:

n ≥ 3f + 1

Fewest generals needed: 3 × traitors + 1
Traitors (f)Generals needed (n)
14
27
Apply

A system has 10 computers, and they send ordinary messages, so a liar can claim anything. At most how many of them can be traitors, with agreement still guaranteed?

The way out

How real systems get out of the trap

This puzzle came out of NASA-funded research into making computers reliable enough to fly airliners. Engineers have never beaten the impossibility. Instead, they change the rules of the game, in one of three ways.

Unforgeable seals

Change
Every order carries a seal nobody can forge. In computers, that’s a digital signature.
You get
Agreement despite any number of traitors. Even three generals are enough, because a two-faced commander’s seal turns up on two different orders.
The price
Every general needs a seal that can’t be faked, and every message still has to arrive.

Clocks and deadlines

Change
Assume messages arrive within a known time. That’s the deadline from Puzzle 2’s rules, and it’s how a missing rider gets noticed: if he isn’t there by the deadline, he isn’t coming.
You get
Systems like PBFT (Practical Byzantine Fault Tolerance, 1999) never give conflicting answers, even when the network is slow, and they keep making progress whenever messages arrive on time. They need 3f + 1 machines: the generals’ two-thirds rule again.
The price
If delays can be unlimited, no method can promise to ever finish, even if just one machine might crash. That was proven in 1985.

Settle for almost certain

Change
Votes count by computing power instead of by identity. That’s Bitcoin’s “proof of work.”
You get
≈0.09%chance that an attacker with 10% of the computing power reverses a payment 5 blocks deep. More blocks, smaller odds; never zero.
The price
It holds only while honest computers control most of the computing power.
Predict

A crypto fan says: “Bitcoin solved the Byzantine Generals problem. Once your payment is confirmed, it’s mathematically impossible to reverse.” Which version is accurate?

What to remember

  • If messages can be lost, two sides can never be certain they agree. Every confirmation needs another.

  • If messages arrive but someone may lie, agreement is guaranteed only when more than two-thirds are loyal: 4 generals to survive 1 traitor.

  • Real systems don’t beat these limits. They change the rules: unforgeable signatures, deadlines, or “almost certain.”

So can the generals ever be certain? Only by changing the rules of the game, and only for as long as those rules hold.

↑ Replay the siege