DisSysLab

Byzantine Consensus

Consensus when agents may lie

The Byzantine generals algorithm solves the consensus problem specified by the requirements of validity, agreement and termination (see Distributed Consensus). The algorithm, created by Pease et al., allows correct (i.e., non-faulty) agents to reach a consensus even if faulty agents halt, lie, and send different messages to different agents. The FLP theorem says that in an asynchronous system no algorithm can guarantee consensus if even one agent may halt. Byzantine consensus assumes that agents operate synchronously, and the FLP theorem does not apply under this assumption.

The assumption of synchronous rounds Byzantine consensus algorithms are synchronous. The algorithm proceeds in rounds: every message sent by a correct agent to a correct agent in a round is received when the next round begins.

The implementation of rounds is unspecified. There are many ways to implement rounds. A central clock can send signals to agents to start rounds. Or each agent starts a round when its local clock reaches a multiple of T, where T is larger than the maximum message delay plus the maximum difference between local clocks.

The consensus problem is to come to consensus on a value. We will assume that the value is a single bit. To get consensus on a 64-bit value, the brute-force way is to run the algorithm 64 times; however, there are more efficient ways, which you can determine for yourselves.

Why this matters

Faulty agents need not be malicious. A sensor with a failing chip can report different readings to different receivers; an agent in an office can be hacked; a buggy agent can give different answers to different peers. In each case an agent tells different listeners different things — exactly the fault this lecture tolerates. Blockchains face the same problem with participants nobody trusts.

The problem

The Byzantine Generals Problem is faced by an army in which the general and some lieutenants may be traitors. The problem is to develop an algorithm by which loyal lieutenants come to a consensus on whether to attack or retreat. We use the term source for the general and agent for a lieutenant. We use the term faulty for a source or agent that does not obey the specified protocol, and correct for one that does.

A correct source sends the same command to every agent. The command is either retreat (0) or attack (1). A faulty source may send different commands to different agents, and may send no command at all to some agents.

The fault bound t You are given t, an upper bound on the number of faulty participants, the source included.

For example, if t = 1, then either the source is faulty and all the agents are correct, or the source is correct and at most one of the agents is faulty. We are not told whether the source is faulty, nor which, if any, of the agents are faulty. The problem is to design a consensus protocol that has the following specification.

The specification

For an agent x, let x.v be the local value of x: its decision when the algorithm terminates. Let S be the source, and S.v be the value of the source.

  1. Termination The algorithm terminates.
  2. Agreement Correct agents come to a consensus. When the algorithm terminates, all correct agents have come to a consensus.
    For all correct agents x and y, x.v = y.v.
  3. Validity Correct agents obey a correct source.
    If the source is correct, then for all correct agents x, x.v = S.v.

The specification does not require that faulty agents be identified. Without the validity requirement, the solution is trivial: all correct agents retreat. Without the agreement requirement, the solution is trivial: obey the source. The problem is non-trivial because both requirements must hold at once.

Example 1. Suppose the agents decide by majority vote, and the source and one of five agents are faulty. The source sends attack to two of the correct agents and retreat to the other two, so the faulty agent can swing the decision of each correct agent either way.

Figure 1. Example 1: two faulty agents are enough to split the rest. The source and agent A are faulty (dark coats); B, C, D and E are correct. A blue letter says attack and a red letter says retreat. Round 0: the source sends attack to A, B and C, and retreat to D and E. Round 1: every agent tells the others what it heard — which message goes where is not drawn, except for A’s, and A says attack to B and C and retreat to D and E. Then they count. B and C hold three attacks against two retreats, while D and E hold two against three. Every correct agent follows the majority it can see, and the two halves decide opposite things.

Example 2. Majority voting fails however many agents there are. Consider a faulty source, one faulty agent, and 999,999 correct agents. The source sends attack to 499,999 of them and retreat to the other 500,000.

Figure 2. Example 2: a million agents, and one faulty agent still splits them. Nothing above depended on there being only five agents. Here the source is faulty and exactly one agent is: it sends attack to 499,999 correct agents and to the faulty agent, and retreat to the other 500,000. Every agent then reports what it heard to all the others — and the faulty agent tells the first group attack and the second group retreat. Counting its own order together with the 999,999 reports, each agent of the first group holds 500,000 attacks and 500,000 retreats, and each of the second holds 499,999 attacks and 500,001. A tie goes to attack. One faulty agent moved one vote, and half a million agents march while half a million stay.

Encrypted messages

If messages are encrypted, then a faulty agent can make copies of the message and forward copies to other agents, but it cannot change the message. When messages are unencrypted, a faulty agent can change the message and forge signatures. In both cases, a faulty agent can choose to send nothing to some agents. The problem with encrypted messages is called the "Written Message" problem, and the problem with unencrypted messages is called the "Oral Message" problem.

What a signature guarantees

A digital signature is computed from the message and a secret key that only the signer holds; anyone can check it with the signer’s public key. It guarantees two things: the signer produced it, and the message has not changed since. It does not hide the message — that is encryption, a different tool. The algorithm needs signatures, not secrecy; this lecture says “encrypted” as shorthand for “signed”.

  1. Written Written, or encrypted, messages. A letter containing message M signed by agent X and received by agent Y can be forwarded by Y, but Y cannot change the message or forge X’s signature.
  2. Oral Oral, or unencrypted, messages. An agent can forge signatures and corrupt messages.
Figure 3. The three things an agent can do, all at once. 1. A signed attack message reaches A from the source. 2. A forwards it to B — the same message under the same signature, which is the one thing a faulty agent can do with a signed letter. 3. A sends C nothing at all, and C cannot tell that from a source who never wrote. 4. A tries to send D a retreat in the source’s name. With written, encrypted messages it cannot: the signature is not forgeable. With oral messages nothing stops it, and D cannot tell.

The rest of this document considers the encrypted message case. Oral messages are not covered in this lecture. Note that for oral messages, when there can be up to t faulty agents (source included), the number of correct agents must exceed 2t for consensus to be possible. For written messages there is no such bound.

The algorithm with encrypted messages

Messages are sent in rounds: a message sent in round k is received at the start of round k+1. An agent that sends a message can sign it with its own signature, and an agent that reads the message can verify the signature.

One simplification, used throughout In a round an agent sends 0, 1, or nothing. Treat a 0‑message as equivalent to no message. Then, every message in the algorithm is a 1‑message, and the absence of a message stands for either a 0 or no message.

Let S.sign be the signature of the source, and x.sign the signature of agent x. A message is a set of signatures: the source’s message is {S.sign}.

A first attempt to gain intuition

Round 0: the source sends {S.sign} to some, all, or none of the agents. In this algorithm, if a correct agent x receives {S.sign} in round k, then it sets x.v = 1 and broadcasts {S.sign} to all agents in round k; these messages are received at the start of round k+1.

# code for agent x; K is determined later
x.v = 0
for k in 1..K:
    if x receives {S.sign} in round k:
        x.v = 1
        broadcast {S.sign}

What is K?

Can K be 1? If the source is correct, it sends {S.sign} to every agent in round 0, and every correct agent y receives it at the start of round 1 and sets y.v = 1. But the source may be faulty.

The counterexample a faulty source, and correct agents y and z.

  1. Round 0. The source sends {S.sign} to y, and nothing to z.
  2. Round 1. y receives it, sets y.v = 1 and broadcasts it; z receives nothing. The algorithm stops before y’s broadcast reaches z.

At the end of round 1, y.v = 1 and z.v = 0. Agreement is violated, so K = 1 does not work.

And no K works A faulty source sends {S.sign} only to a faulty agent x. x stays silent until round K−1 and then sends it to y and not to z. y sets y.v = 1 in round K, but its broadcast arrives in round K+1, after the algorithm stops.

How can you modify the algorithm so that it stops with a consensus after some round K?

The algorithm

In the algorithm, every message is a set of signatures that includes S.sign. In the code, m + x.sign = m UNION {x.sign}.

The rule If a correct agent x receives, in round k, a message m that contains S.sign and has at least k signatures, then x sets x.v = 1 and broadcasts m + x.sign.

# code for the source S, in round 0
if S.v == 1:
    send {S.sign} to every agent

# code for agent x; K is determined later
x.v = 0
for k in 1..K:
    if message m is received where S.sign in m and len(m) >= k:
        x.v = 1
        broadcast m + x.sign
Figure 4. The source and A are faulty; B and C are correct. Round 0: the source sends {S.sign} to A and nothing to B or C. Round 1: no messages are sent; A holds the source’s message and waits. Round 2: A adds its signature and sends {S.sign, A.sign} to B, and nothing to C. B and C have nothing to send. Round 3: B receives the message, but len(m) = 2 < 3, so B does not set B.v = 1 and does not broadcast. B and C still agree.
Figure 5. The same agents as figure 4, but A sends a round earlier. Round 0: the source sends {S.sign} to A and nothing to B or C. Round 1: A adds its signature and sends {S.sign, A.sign} to B, and nothing to C. Round 2: B receives the message; len(m) = 2 ≥ 2, so B sets B.v = 1 and broadcasts {S.sign, A.sign, B.sign}. Round 3: C receives B’s message; len(m) = 3 ≥ 3, so C sets C.v = 1. B and C agree.

Observations

  1. If the source is correct and sends S.sign, then every correct agent x sets x.v = 1 by the end of round 1. Why At the start of round 1, all correct agents x have received {S.sign}, and so len(m) >= 1.
  2. If the source is correct and does not send S.sign, then x.v = 0 in all rounds for all correct agents x. Why No message contains S.sign: the source signed none, and no one can forge it.
  3. If a correct agent x changes the value of x.v from 0 to 1 in round j, where j < K, then every correct agent y sets y.v = 1 by the end of round j+1. Why An invariant of the algorithm is that for all correct agents x, a message contains x.sign only if x.v = 1. In round j, x received a message m that contains S.sign and has len(m) >= j, and x broadcast m + x.sign. Since m does not contain x.sign, len(m + x.sign) >= j+1. So at the start of round j+1, all correct agents y have received a message that contains S.sign and has len >= j+1.
Figure 6. Observation 3. A, B and C are correct; u and v are faulty agents. Round 2: A.v = B.v = C.v = 0. Round 3: B receives {S.sign, u.sign, v.sign}; len(m) = 3 ≥ 3, so B sets B.v = 1 and sends {S.sign, u.sign, v.sign, B.sign} to A and C. Round 4: A and C receive it; len(m) = 4 ≥ 4, so A and C set A.v = 1 and C.v = 1.

On which round should the algorithm stop?

Lemma

If K = t+1, the algorithm satisfies termination, agreement and validity.

Proof

Termination holds because the algorithm runs for K rounds.

Case 1: the source is correct. Agreement and validity follow from observations 1 and 2.

Case 2: the source is faulty, and there exist k ≤ t and a correct agent x such that x.v changes from 0 to 1 in round k. By observation 3, for all correct agents y, y.v = 1 by the end of round k+1 ≤ t+1. So the agreement requirement is satisfied. Validity holds trivially because the source is faulty.

Case 3: the source is faulty, and for all rounds k ≤ t and all correct agents x, x.v = 0. In rounds 1 to t, no correct agent signs a message, because a correct agent x signs only after setting x.v = 1. The source is faulty, so at most t−1 agents are faulty. So every message received at the start of round t+1 has at most t signatures: the source’s and those of at most t−1 faulty agents. That is not enough for a correct agent y to set y.v = 1 in round t+1. So, for all correct agents y, y.v = 0 at the end of round t+1, and the agreement requirement is satisfied. Figure 7 shows this case.

The answer The algorithm stops after round t+1. Each correct agent x attacks if x.v = 1 and retreats if x.v = 0.

Figure 7. The source, u and v are faulty, so t = 3 and the algorithm stops after round t+1 = 4. A, B and C are correct. In round 0 the source sends {S.sign} to u and v only. Round 2: A.v = B.v = C.v = 0. Round 3: u and v send {S.sign, u.sign, v.sign} to A, B and C. Round 4: A, B and C receive the message, but len(m) = 3 < 4, so their values stay 0.

Why not stop after round t?

The counterexample t = 3: a faulty source and faulty agents u and v; correct agents A, B and C; and K = t = 3.

  1. Round 0. The source sends {S.sign} to u and v only.
  2. Round 2. u and v send {S.sign, u.sign, v.sign} to A only.
  3. Round 3. A receives a message with 3 ≥ 3 signatures, sets A.v = 1 and broadcasts {S.sign, u.sign, v.sign, A.sign}. That broadcast arrives in round 4, after the algorithm stops.

A.v = 1 but B.v = C.v = 0: agreement is violated. With K = t+1 = 4, B and C receive A’s message in round 4, with 4 ≥ 4 signatures, and agree. Try it in figure 8.

Try it yourself

Choose which participants are faulty and what the faulty ones do, then read off what each correct agent decides. The faulty participants collude: they can sign for one another, so a faulty agent can send {S.sign} together with every faulty agent’s signature.

Faulty
A correct source sends
In round 0, the faulty source sends {S.sign} to
The faulty agents send every faulty signature in round to
Number of rounds K
Figure 8. Try it yourself. Each row is a correct agent and each column a round; a cell shows the agent’s value at the end of that round. An outlined cell is where the agent accepted a message, shown under the 1. With K = t+1 no choice of faults breaks agreement; with K = t, look for one that does.

Paxos and Byzantine consensus compared

Paxos Byzantine consensus, signed messages
TimingAsynchronous: messages may be delayed or lostSynchronous rounds
FaultsAgents may haltFaulty participants may do anything except forge signatures
Fault boundA majority of acceptors must be reachableAny number t of faulty participants, if t is known
TerminationNot guaranteed (FLP)Guaranteed: t+1 rounds

No algorithm that tolerates t faulty participants can always finish in fewer than t+1 rounds (Fischer and Lynch, 1982), so this algorithm is as fast as possible in the worst case.

Exercises

  1. In the worst case, how many messages do the correct agents send in one round? In the whole algorithm?
  2. Suppose signatures could be forged. Construct a run with t = 1 in which the algorithm violates agreement or validity.
  3. Extend the algorithm to agree on a 64-bit value with fewer than 64 runs.
  4. Prove the invariant used in observation 3: for every correct agent x, a message contains x.sign only if x.v = 1.
  5. In figure 8, set K = t and find a choice of faults that violates agreement. Then explain why no choice works with K = t+1.