Docsity

Verifying the Hashgraph Consensus Algorithm, Schemes and Mind Maps of Algorithms and Programming

Toggle sidebar
bg1
Verifying the Hashgraph Consensus Algorithm
Karl Crary
Carnegie Mellon University
Abstract
The Hashgraph consensus algorithm is an algorithm for
asynchronous Byzantine fault tolerance intended for dis-
tributed shared ledgers. Its main distinguishing character-
istic is it achieves consensus without exchanging any extra
messages; each participant’s votes can be determined from
public information, so votes need not be transmitted.
In this paper, we discuss our experience formalizing the
Hashgraph algorithm and its correctness proof using the Coq
proof assistant. The paper is self-contained; it includes a
complete discussion of the algorithm and its correctness ar-
gument in English.
1 Introduction
Byzantine fault-tolerance is the problem of coordinating a
distributed system while some participants may maliciously
break the rules. Often other challenges are also present,
such as unreliable communications. The problem is at the
center of a variety of new applications such as cryptocur-
rencies. Such applications rely on distributed shared ledgers,
a form of Byzantine fault-tolerance in which a set of trans-
actions are assigned a place in a globally-agreed total order
that is immutable. The latter means that once a transaction
enters the order, no new transaction can enter at an earlier
position.
A distributed shared ledger makes it possible for all par-
ticipants to agree, at any point in the order, on the cur-
rent owner of a digital commodity such as a unit of cryp-
tocurrency. A transaction transferring ownership is valid
if the commodity’s current owner authorizes the transac-
tion. (The authorization mechanism—presumably using a
digital signature—is beyond the scope of the ledger itself.)
Because the order is total, one transaction out of any pair
has priority. Thus we can show that a commodity’s chain
of ownership is uniquely determined. Finally, because the
order is immutable, the chain of ownership cannot change
except by adding new transactions at the end.
Algorithms for Byzantine consensus (under various as-
sumptions) have existed for some time, indeed longer than
the problem has been named [12, 9]. Practical algorithms
are more recent; in 1999, Castro and Liskov [6] gave an algo-
rithm that when installed into the NFS file system slowed it
only 3%. As Byzantine consensus algorithms have become
more practical, they have been tailored to specific applica-
tions. Castro and Liskov’s algorithm was designed for fault-
tolerant state machine replication [13] and probably would
not perform well under the workload of a distributed shared
ledger.
However, in the last few years there have arisen
Byzantine fault-tolerance algorithms suitable for distributed
shared ledgers, notably HoneyBadgerBFT [10], BEAT [7],
and—the subject of this paper—Hashgraph [2]. Moreover,
the former two each claim to be the first practical asyn-
chronous BFT algorithm (with different standards of prac-
ticality). Hashgraph does not claim to be first, but is also
practical and asynchronous.
In parallel with that line of work has been the develop-
ment of distributed shared ledgers based on proof of work,
beginning with Bitcoin [11]. The idea behind proof of work
is to maintain agreement on the ledger by maintaining a list
of blocks of transactions, and to ensure that the list does not
become a tree. To ensure this, the rules state that (1) the
longest branch defines the list, and (2) to create a new block,
one must first solve a mathematical problem that takes the
list’s old head as one of its inputs. The problem’s solution
is much easier to verify than to obtain, so when one learns
of a new block, one’s incentive is to restart work from the
new head rather than continue work from the old head.
Bitcoin and some of its cousins are widely used, so in a
certain sense they are indisputably practical. They are also
truly permissionless, in a way that the BFT algorithms, in-
cluding Hashgraph, cannot quite claim. Nevertheless, they
offer severely limited throughput. Bitcoin is limited to seven
transactions per second and has a latency of one hour, while
its BFT competitors all do several orders of magnitude
better. Proof-of-work systems are also criticized for being
wasteful: an enormous amount of electricity is expended on
block-creation efforts that nearly always fail. Finally—more
to the point of this paper—the theoretical properties of proof
of work are not well understood.
The Hashgraph consensus algorithm is designed to sup-
port high-performance applications of a distributed shared
ledger. Like the other BFT systems, it is several orders of
magnitude faster than proof of work. Actual performance
depends very much on configuration choices (e.g., how many
peers, geographic distribution, tradeoff between latency and
throughput, etc.), but in all configurations published in
Miller, et. al [10] (for HoneyBadgerBFT) and Duan, et
al. [7] (for BEAT), the Hashgraph algorithm equals or ex-
ceeds the published performance figures [4]. A frequently
cited throughput goal is to equal the Visa credit-card net-
work. According to Visa’s published figures, Hashgraph can
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Verifying the Hashgraph Consensus Algorithm and more Schemes and Mind Maps Algorithms and Programming in PDF only on Docsity!

Verifying the Hashgraph Consensus Algorithm

Karl Crary

Carnegie Mellon University

Abstract

The Hashgraph consensus algorithm is an algorithm for asynchronous Byzantine fault tolerance intended for dis- tributed shared ledgers. Its main distinguishing character- istic is it achieves consensus without exchanging any extra messages; each participant’s votes can be determined from public information, so votes need not be transmitted. In this paper, we discuss our experience formalizing the Hashgraph algorithm and its correctness proof using the Coq proof assistant. The paper is self-contained; it includes a complete discussion of the algorithm and its correctness ar- gument in English.

1 Introduction

Byzantine fault-tolerance is the problem of coordinating a distributed system while some participants may maliciously break the rules. Often other challenges are also present, such as unreliable communications. The problem is at the center of a variety of new applications such as cryptocur- rencies. Such applications rely on distributed shared ledgers, a form of Byzantine fault-tolerance in which a set of trans- actions are assigned a place in a globally-agreed total order that is immutable. The latter means that once a transaction enters the order, no new transaction can enter at an earlier position. A distributed shared ledger makes it possible for all par- ticipants to agree, at any point in the order, on the cur- rent owner of a digital commodity such as a unit of cryp- tocurrency. A transaction transferring ownership is valid if the commodity’s current owner authorizes the transac- tion. (The authorization mechanism—presumably using a digital signature—is beyond the scope of the ledger itself.) Because the order is total, one transaction out of any pair has priority. Thus we can show that a commodity’s chain of ownership is uniquely determined. Finally, because the order is immutable, the chain of ownership cannot change except by adding new transactions at the end. Algorithms for Byzantine consensus (under various as- sumptions) have existed for some time, indeed longer than the problem has been named [12, 9]. Practical algorithms are more recent; in 1999, Castro and Liskov [6] gave an algo- rithm that when installed into the NFS file system slowed it only 3%. As Byzantine consensus algorithms have become more practical, they have been tailored to specific applica- tions. Castro and Liskov’s algorithm was designed for fault- tolerant state machine replication [13] and probably would

not perform well under the workload of a distributed shared ledger. However, in the last few years there have arisen Byzantine fault-tolerance algorithms suitable for distributed shared ledgers, notably HoneyBadgerBFT [10], BEAT [7], and—the subject of this paper—Hashgraph [2]. Moreover, the former two each claim to be the first practical asyn- chronous BFT algorithm (with different standards of prac- ticality). Hashgraph does not claim to be first, but is also practical and asynchronous. In parallel with that line of work has been the develop- ment of distributed shared ledgers based on proof of work, beginning with Bitcoin [11]. The idea behind proof of work is to maintain agreement on the ledger by maintaining a list of blocks of transactions, and to ensure that the list does not become a tree. To ensure this, the rules state that (1) the longest branch defines the list, and (2) to create a new block, one must first solve a mathematical problem that takes the list’s old head as one of its inputs. The problem’s solution is much easier to verify than to obtain, so when one learns of a new block, one’s incentive is to restart work from the new head rather than continue work from the old head. Bitcoin and some of its cousins are widely used, so in a certain sense they are indisputably practical. They are also truly permissionless, in a way that the BFT algorithms, in- cluding Hashgraph, cannot quite claim. Nevertheless, they offer severely limited throughput. Bitcoin is limited to seven transactions per second and has a latency of one hour, while its BFT competitors all do several orders of magnitude better. Proof-of-work systems are also criticized for being wasteful: an enormous amount of electricity is expended on block-creation efforts that nearly always fail. Finally—more to the point of this paper—the theoretical properties of proof of work are not well understood.

The Hashgraph consensus algorithm is designed to sup- port high-performance applications of a distributed shared ledger. Like the other BFT systems, it is several orders of magnitude faster than proof of work. Actual performance depends very much on configuration choices (e.g., how many peers, geographic distribution, tradeoff between latency and throughput, etc.), but in all configurations published in Miller, et. al [10] (for HoneyBadgerBFT) and Duan, et al. [7] (for BEAT), the Hashgraph algorithm equals or ex- ceeds the published performance figures [4]. A frequently cited throughput goal is to equal the Visa credit-card net- work. According to Visa’s published figures, Hashgraph can

handle Visa’s average load^1 and is in the ballpark of Visa’s claimed surge capacity.^2 The key to the Hashgraph algorithm’s performance is achieving nearly zero communications overhead. Previous BFT systems exchange messages to achieve consensus, but Hashgraph does not. In Hashgraph, no peer sends any mes- sages it did not intend to send anyway. Moreover, the over- head in each message it does send is light; each message con- sists mostly of transactions that are new to the recipient. In addition to the transaction payload, a message contains an array of sequence numbers (to keep track of which blocks each peer has seen), and the information needed by consen- sus: just two hashes, a digital signature, and a timestamp. In the Hashgraph algorithm, peers achieve consensus by voting, but each vote is fully determined by publicly avail- able information, so peers can determine each other’s votes without communicating with them. This allows the con- sensus election to be carried out virtually, with no extra messages exchanged. There is no magic here; it still takes multiple cycles of communication to achieve consensus, but every message is just an ordinary block filled with new transactions. Thus, consensus is essentially invisible from a throughput perspective. Another advantage of the Hashgraph algorithm is it re- quires no sophisticated cryptography. The only require- ments are digital signatures and cryptographic hashes, both of which are now commonplace and have highly optimized implementations available.

This work The Hashgraph consensus algorithm has been realized as a large-scale, open-access, commercial system called Hedera [3], so there is considerable interest in machine-verifying that it is correct. In this paper, we discuss the first steps toward doing so. Using the Coq proof assis- tant [5], we formalized the batch-mode algorithm given in Baird [2] and developed a machine-checkable proof of its cor- rectness. As usual when one formalizes a human-language proof, we found a few errors, but they were minor and eas- ily corrected. The algorithm implemented in Hedera is an online algorithm, inspired by the batch-mode algorithm dis- cussed here, but obviously a bit different.^3 We will discuss some of the differences in Section 5. We begin by giving an informal overview of the algo- rithm, to build intuition. Then we give a human-language mathematical definition of the algorithm and prove its prop- erties, in Section 2. We discuss the formalization in Coq starting in Section 3.

1.1 Hashgraphs in overview

A hashgraph is a directed graph that summarizes who has said what to whom. Each peer maintains a hashgraph re- flecting the communications it is aware of. In general, each peer knows a different subset of the true graph, but because of digital signatures and cryptographic hashes, they cannot disagree about the information they have in common. The nodes of a hashgraph are events. Each event is cre- ated by a particular peer. Except for each peer’s initial event, each event has two parents. One parent has the same creator (we call that one the self-parent), and the other has a

(^1) 3200 transactions per second in 2015 [14]. (^2) 65,000 transactions per second in 2017 [15]. (^3) As it happens, none of the minor errors we found appear to affect the implemented online algorithm.

A

A

Alice

B

B

B

B

B

Bob

C

C

C

Cathy

D

D

Dave

Time

Figure 1: A Hashgraph

different creator (we call it the other-parent). Honest peers do not create forks, where a fork is defined as two events with the same creator in which neither is a self-ancestor of the other.^4 In other words, the events created by an honest peer will form a chain. We can visualize a hashgraph as shown in Figure 1. In this example, all peers are behaving honestly. In the Hashgraph network, each peer periodically chooses another at random and sends that peer its latest event. The recipient then creates a new event, with its own latest event as self-parent and the event it just received as other-parent. Every event is digitally signed, so there can be no dispute over who created it. Each event also contains the hashes of its two parents, so there is no dispute over parentage either. The recipient of the event will request from the sender any of the event’s ancestors that it does not have. (For simplicity, we will ignore that part of the protocol in what follows.) The recipient also puts a timestamp into the event, which is ultimately used to determine a consensus timestamp for other events. Finally, each event contains a payload of transactions. When a peer wishes to inject a new transaction into the network, it stores it in a buffer of outgoing transactions. The next time it creates an event (this happens multiple times per second), it uses the contents of its buffer as the new event’s payload. Transactions are just along for the ride in the consensus algorithm, so we will discuss them little. In the example, Dave sent D1 to Cathy, resulting in Cathy creating C2. Then Cathy sent C2 back to Dave, re- sulting in Dave creating D2. Bob sent B1 to both Alice and Cathy, resulting in A2 and C3. At about the same time, Alice sent A1 to Bob, resulting in B2. Alice sent A2 to Bob, resulting in B3. Cathy sent C3 to Bob, resulting in B4. Finally, Dave sent D2 to Bob, resulting in B5. The algorithm partitions events into rounds, in a manner that is easy for all peers to agree on. The first event created by a peer in a round is called a witness. (Note that dishonest peers may have multiple witnesses in a single round.) A witness that is quickly propagated to most peers is called famous. Identifying the famous witnesses is the main job of the consensus algorithm. Each round, the algorithm selects one famous witness from each peer that has one to be a unique famous witness. (^4) A self-ancestor is an ancestor using only self-parent edges.

2.2 Rounds

Every event is assigned to a round. (Note that the round an event belongs to is different from the round that it is received by the network.) Initial events belong to round zero. For a non-initial event x, let i be the maximum of x’s parents’ rounds. Then x belongs to round i, unless x strongly sees events in round i on a supermajority of peers, in which case x belongs to round i + 1. For example, consider Figure 1. A1, B1, C1, and D1 are initial events, so they belong to round 0. For every other event, the maximum of the parents’ rounds is 0. Thus, every other event also belongs to round 0, except B5. As noted above, B4 can strongly see B1 and D1, but not A1 or C1, so it remains in round 0. However, B5 strongly sees B1, C1, and D1, so it advances to round 1. The first event in a round on each peer (or first events, in the case of a dishonest peer) are called witnesses. Witnesses are the events that can cast votes in an election. In Figure 1, the witnesses are A1, B1, C1, and D (round 0), and B5 (round 1). Note that if a peer has not heard from anyone in a while, it is possible for it to skip one or more rounds when it catches up. Thus, a peer might not have a witness in any particular round. Conversely, a dishonest peer can have multiple wit- nesses in a round, but (by Lemma 2.3) at most one of them can be strongly seen.

Two important properties of rounds follow more-or-less directly:

Lemma 2.4 Suppose i < j and x belongs to round j. Then there exists a supermajor set of round i witnesses W , such that for all w ∈ W , w  x.

Lemma 2.5 Suppose x and y are events. If there exists a supermajor set W such that for all w ∈ W , x ≤ w  y, then y’s round is strictly later than x’s round.

The main property we wish to establish about rounds is progress, which says that every round is inhabited.

Lemma 2.6 (Broadcast) Suppose x is an honest event. Then there exists an honest event y such that, in its ances- try, x has reached every honest peer. That is, for every hon- est peer a, there exists z created by a, such that x ≤ z ≤ y.

Proof Sketch

By induction on the number of honest peers, using the assumption that every honest peer eventually communi- cates with every other honest peer.

Lemma 2.7 (Progress) Every round is inhabited.

Proof

We prove the stronger property that for every round i, there exists an inhabitant of some round j ≥ i. The inhabitant can then be wound back to i using Lemma 2.4. The proof is by induction on i. The case i = 0 is im- mediate, so suppose i > 0. By induction there exists an inhabitant x of round i − 1. Using Lemma 2.6, there exists y such that x has reached every honest peer in y’s ancestry. And again, there exists z such that y has reached every honest peer in z’s ancestry. Suppose a is an honest peer. We show that there exists v created by a that x ≤ v  z. Since the honest peers

constitute a supermajority, it follows by Lemma 2.5 that z’s round is later than i − 1, and is thus at least i. By the specification of y, there exists v created by a such that x ≤ v ≤ y. It remains to show v  z. For every honest peer b, by the specification of z there exists w created by b such that y ≤ w ≤ z. Since a is honest, v E w ≤ z. Since the honest peers constitute a super- majority, v  z.

2.3 Voting One cannot use the raw witnesses to determine the round an event was received by the network, because one can never be sure that one has observed all the witnesses. Instead, we will use the notion of a famous witness—eventually everyone will know all the famous witnesses in any given round. The main function of the consensus algorithm is to determine which witnesses are famous. Fame is determined by an election. Votes are cast by witness events, not by peers. This is important because one peer has no way of knowing what another peer knows. In contrast, if a peer is aware of an event at all, it knows that event’s entire ancestry. Thus, if voting is determinis- tic, each witness’s vote can be determined by everyone who is aware of the witness, without any additional communica- tion. However, votes will be “collected” only from strongly- seen witnesses, so there can be at most one meaningful voter per peer per round. We will refer to the witness whose fame is being deter- mined as the candidate, and each witness that is casting votes on the candidate’s fame as the voter. The election begins d rounds after the candidate’s round, where d is a parameter that is at least 1. Thus if the candidate belongs to round i, the voters in the first round of the election belong to round i + d. In the first round of an election, each voter will vote yes if the candidate is among its ancestors. (In essence, you think someone is famous if you have heard of them.) In successive rounds, each voter votes the way it observed the majority vote in the previous round. We say that a round of an election is nearly unanimous if voters on a supermajority of peers vote the same way. (Note that this is a stronger condition than merely a supermajority of the voters, since some peers might not be voting.) If voter ever observes a nearly unanimous result in the previous round, then the vote in the current round will be unanimous. Clearly, once the election becomes unanimous, it will stay so. Thus we can end the election as soon as any event observes a nearly unanimous result the previous round.

Coins Under normal circumstances, this process will come to consensus quickly, but an adversary with sufficient control of the network can prevent it. Deterministically, the prob- lem is insurmountable [8], but, as usual, it can be solved with randomization. Every c rounds (a parameter at least d + 3), the election will employ a coin round: Every voter who sees a nearly unanimous result the previous round will continue to vote with the majority. However, the remaining voters will de- termine their votes using a coin flip. All the voters who saw a nearly unanimous result will certainly vote the same way, and eventually—by chance—the coin flippers will also vote that way. The following round, every voter will see a

unanimous result and the election will end.^5

Definition 2.8 (Voting) Suppose x is a round i witness and y is a round j witness, with i + d ≤ j. Then vote(x, y) (that is, y’s vote on x’s fame) and election(x, y, t, f ) (that is, the votes on x’s fame observed by y are t yeas and f nays) are defined simultaneously as follows:

ˆ If i + d = j then vote(x, y) is yes if x ≤ y, and no otherwise.

ˆ If i + d < j and (j − i) mod c 6 = 0 and election(x, y, t, f ), then vote(x, y) is yes if t ≥ f and no otherwise.

ˆ If i + d < j and (j − i) mod c = 0 and election(x, y, t, f ), then

vote(x, y) =

yes t > 2 / 3 · N no f > 2 / 3 · N coin(y) otherwise

ˆ If i + d < j, then election(x, y, t, f ) holds if and only if:

W = {round j − 1 witnesses w such that w  y} t = |{w ∈ W | vote(x, w) = yes}| f = |{w ∈ W | vote(x, w) = no}|

In the above definition, coin(y) is a pseudo-random coin flip computed by drawing a bit from the middle of a cryp- tographic hash of y. It is important that the coin flip is pseudo-random, not truly random, so that other peers can reproduce it.

Definition 2.9 (Decision) Suppose x is a round i witness and y is a round j witness, where i + d < j and j is not a coin round (that is, j − i mod c 6 = 0). Suppose further that election(x, y, t, f ). Then y decides β on x’s fame (written decide(x, y, β)), if t > 2 / 3 · N and β = yes, or if f > 2 / 3 · N and β = no.

The outcome of the election is determined as soon as any peer decides, but other peers might not realize it right away.

2.4 Consensus

For the algorithm to work, we require four properties:

  1. Decisions are pervasive: once one peer decides some- one’s fame, that decision propagates to every other peer. (Corollary 2.11.)
  2. Every round will have at least one famous witness. (Theorem 2.13.)
  3. Late arrivals are not famous: if a witness is not well disseminated within d+1 rounds (the earliest a decision can be made), it will not be famous. (Corollary 2.15.)
  4. Termination: eventually every witness will have its fame decided. (Theorem 2.17.)

Lemma 2.10 (Decision-Vote Consistency) Suppose w, x, and y are witnesses, where x and y belong to the same round. If decide(w, x, β) and vote(w, y) = β′^ then β = β′.

(^5) This is an important theoretical property, but as a practical mat- ter, in the unlikely event an adversary has enough control over the network to force coin rounds, it will be able to grind the algorithm to a halt for rounds exponential in the number of peers.

Proof Let j be the round of x and y. Observe that vote(w, y) is given by the second case of the def- inition of voting. Unpacking the definitions, let election(w, x, t, f ) and election(w, y, t′, f ′). Let Vz = {round j − 1 witnesses v such that v  z}. Suppose β = yes. (The other case is similar.) Then |T | > 2 / 3 · N where T = {v ∈ Vx | vote(w, v) = yes}. Thus T is a supermajor set. By Lemma 2.4, Vy is also a supermajor set. Observe that T and Vy are both sets of round j − 1 witnesses. Any two supermajorities of the same set have a majority in common. Thus a majority of Vy agrees with T , but T all vote yes. Hence t′^ > f ′^ so β′^ = yes.

Note that the proof illustrates why decisions cannot be made in coin rounds. In a coin round, y would have to see a supermajority to determine its vote, not merely a majority, and we cannot guarantee a supermajority. Thus the lemma would fail to hold.

Corollary 2.11 (Propagation) Suppose x makes a deci- sion on w. Then in every round after x’s, except coin rounds, every witness decides the same way as x did. Proof Sketch Let j be the round of x. By Lemma 2.10, every witness in round j votes β. It is easy to see that unanimity persists. Thus every witness in any round after j decides β, unless it is prohibited from doing so because it is a coin round.

An easy corollary is that all decisions agree:

Corollary 2.12 (Consistency) Suppose decide(w, x, β) and decide(w, y, β′). Then β = β′. Proof Let z be a witness in a later round than x and y that is not a coin round. (Such a witness exists by Lemma 2.7.) By Corollary 2.11, decide(w, z, β) and decide(w, z, β′). Hence β = β′.

Theorem 2.13 (Existence) Every round has at least one famous witness. Proof If S is a set of events, define backward(j, S) = {w | w is a round j witness and ∃v ∈ S. w  v}. Suppose S is an inhabited set of round k witnesses and j < k. By Lemma 2.4, 2 / 3 · N < |backward(j, S)| ≤ N. Let i be arbitrary, and let z be an arbitrary witness in round i + d + 2, then let:

S 3 = {z} S 2 = backward(i + d + 1, S 3 ) S 1 = backward(i + d, S 2 ) S 0 = backward(i, S 1 )

Now consider a bipartite graph between S 0 and S 1 , where there is an edge between x ∈ S 0 and y ∈ S 1 if x ≤ y. Since strongly-seeing implies ancestor, Lemma 2.4 tells us that every event in S 1 is the terminus of more than (^2) / 3 · N edges. Thus there are over 2 / 3 · N · |S 1 | edges total. Since there are at most N events in S 0 , by the pigeonhole principle there is at least one event in S 0 that is the origin

Definition 2.18 Suppose x is an event. The round x is received by the network is the earliest round i for which all the round i unique famous witnesses are descendants of x.

2.6 The Consensus Timestamp

Suppose x is an event that is received in round i. We com- pute the consensus timestamp for x as the median of the timestamps assigned to x by the unique famous witnesses of round i. (If there is an even number of unique famous witnesses, we take the median to be the smaller of the two central elements. This provides the useful property that the consensus timestamp is the timestamp from some particular peer.) Suppose y is a round i unique famous witness. The times- tamp y assigns to x is the timestamp of the earliest z such that x ≤ z v y. Note that z certainly exists, since x ≤ y, and that z is uniquely defined since the self-ancestors of y are totally ordered.

2.7 The Consensus Order

We can now define the consensus order:

Definition 2.19 Suppose x and y are events. Let i and i′ be the rounds x and y are received by the network. Let t and t′^ be the consensus timestamps of x and y. Then x precedes y in the consensus order if:

ˆ i < i′, or

ˆ i = i′^ and t < t′, or

ˆ i = i′^ and t = t′^ and x is less than y using the arbitrary comparison used to select unique famous witnesses.

It is clear that the consensus order is a total order. Since all peers can agree on the unique famous witnesses, they can all agree on the consensus order. Finally, the order is immutable: the unique famous witnesses do not change once determined, and their ancestries never change either.

3 Formalization

Our work builds on lessons learned from a previous effort to verify the Hashgraph consensus algorithm by Gregory Malecha and Ryan Wisnesky. In that earlier effort the al- gorithm was expressed by implementing it as a function in Gallina (the Coq specification language). This allowed the code to be directly executed within Coq, and it was thought that such code could be more easily related to the actual code in the commercial Hashgraph implementation, Hedera. However, the specification as a Gallina implementation was challenging to work with. Although the effort did not hit a show-stopping problem, the concreteness of the imple- mentation made it clumsy to work with. Moreover, express- ing the algorithm using recursive functions, rather than in- ductive relations, meant that one was denied nice induction principles. In this work we started over with new definitions, mak- ing events and other objects of interest abstract, and using inductive relations for most definitions. This allowed for streamlined proofs that usually closely resemble the human- language proofs, and nice induction principles in most cases. (An important exception, induction over votes, is discussed in Section 3.4.)

The axioms that define hashgraphs are just 258 lines. This is the trusted part of the development, apart from Coq itself. The full proof is 14 thousand lines of Coq (version 8.9.1), including comments and whitespace. It takes 25 seconds to check using a single core of a 1.8 GHz Intel Core i5. Not all of these lines are allocated to matters that are conceptu- ally interesting: the largest and third-largest files (2.6k lines between them) are dedicated to defining and establishing properties of the cardinalities of sets, and medians. We will discuss changes we made from the original algo- rithm in Baird [2], and then touch on interesting points that arose during the formalization. The survey here will not be complete; the complete development is available at:

cs.cmu.edu/~crary/papers/2020/hashgraph-formal.tgz

3.1 Changes from the original algorithm As typically happens when formalizing a human-language proof, we did uncover a few errors, but they were minor and easily corrected.^7 These corrections are already reflected in Section 2:

  1. The original definition of strongly-sees was a bit differ- ent: it said that y strongly sees x if x E z E y (for all z in some supermajor set). But that definition didn’t provide the “stickiness” property of Lemma 2.2 (that is, x  y ≤ w implies x  w) since w might observe a fork that y does not.
  2. Because of that change, strongly-seeing does not nec- essary imply seeing. The original rule for first-round voting required that for y to vote yes on x, y must see x and not merely be a descendant of x. But that meant that y strongly seeing x was not enough for y to vote yes for x, which breaks the proof of the existence of famous witnesses (Theorem 2.13).
  3. Originally, when a peer had multiple famous witnesses, instead of choosing one to consider unique, none of them were. But then it was not obvious that unique famous witnesses always exist.

In addition to these changes, we added a careful proof of Progress (Lemma 2.7). Also, a trivial difference is our first round is 0, instead of 1. This is preferable so every natural number is a round number.

3.2 Peers and Events

To illustrate the abstract style we used to formalize the al- gorithm, these are definitions of peers and events:

Parameter peer : Type.

Axiom peer_eq_dec : forall (a b : peer), {a = b} + {a <> b}.

The axiom states that it is decidable whether two peers are the same. This is a good example of the sort of uncontro- versial mathematical assumption we alluded to in Section 2. A typical human-language proof would not bother to make such an assumption explicit. (^7) These errors pertain to the batch-mode algorithm discussed here, not to the online algorithm that the Hedera implementation is based on. We discuss some of the differences in Section 5. For example, the online algorithm defines strongly seeing somewhat differently.

Parameter number_peers : nat.

Axiom number_of_peers : cardinality (@every peer) number_peers.

Axiom number_peers_minimum : number_peers >= 2.

There exists a natural number that is the number of peers, and that number is at least two. (In the preceding we called it N .) The code “@every peer” denotes the set of all peers.

Parameter honest : peer -> Prop.

Axiom supermajority_honest : supermajority honest every.

The set of honest peers is a supermajority of the set of all peers.

Parameter event : Type.

Axiom event_eq_dec : forall (e f : event), {e = f} + {e <> f}.

Parameter creator : event -> peer.

The equality of events is decidable, and every event has a creator.

Parameter parents : event -> event -> event -> Prop.

Axiom parents_fun : forall e e’ f f’ g, parents e f g -> parents e’ f’ g -> e = e’ /\ f = f’.

Axiom parents_creator : forall e f g, parents e f g -> creator e = creator g.

We write parents e f g when e and f are the self-parent and other-parent of g. The axioms say parents are uniquely defined, and the self-parent has the same creator as the event.

Definition initial (e : event) : Prop := ~ exists f g, parents f g e.

Axiom initial_decide : forall e, initial e / exists f g, parents f g e.

An initial event is one without parents, and it is decidable whether an event is initial.

Inductive parent : event -> event -> Prop := | parent1 {e f g} : parents e f g -> parent e g

| parent2 {e f g} : parents e f g -> parent f g.

Definition self_parent (e f : event) : Prop := exists g, parents e g f.

Axiom parent_well_founded : well_founded parent.

We say parent x y when x is either parent of y, and self_parent x y when x is the self-parent of y. We as- sume that the parent relation is well-founded, which means we can do induction using that relation. (In classical logic, that is equivalent to saying there are no infinite descending chains.) From that assumption, we can show that the self- parent, strict ancestor, and strict self-ancestor relations are also well-founded.

3.3 Rounds In Baird [2] the definitions of rounds and witnesses are mu- tually dependent. As here, a witness was the first event created by a peer in a round. Unlike here, to advance to the next round an event would need to strongly see many witnesses in the current round, while we require it only to strongly see many events in the current round. It is not hard to see that the definitions are equivalent, but our version has the virtue that rounds can be defined without reference to witnesses. Our formalization of rounds then is:

Inductive round : nat -> event -> Prop := | round_initial {x} : initial x -> round 0 x

| round_advance {x y z m n A} : parents y z x -> round m y -> round n z -> supermajority A every -> (forall a, A a -> exists w, creator w = a /\ stsees w x /\ round (max m n) w) -> round (S (max m n)) x.

Definition election (V : event -> bool -> Prop) (n : nat) (y : event) (t f : nat) := exists T F, cardinality (fun w => elector n w y) (t + f) /\ cardinality T t /\ cardinality F f /\ (forall w, T w -> elector n w y /\ V w true) /\ (forall w, F w -> elector n w y /\ V w false)

We existentially quantify over two sets T and F , where the intention is that T is the yeas and F the nays. The final two conjuncts check that every element of T (F ) is indeed an elector and votes yes (no). The previous two conjuncts check that the cardinalities of T and F are t and f. Finally, the first conjunct ensures that we are not miss- ing any votes: If we assume that V does not allow a single witness to vote both ways (which vote s x will not), it fol- lows that T and F are disjoint. Thus, in order to check that every vote is accounted for, we need only check that there are t + f electors total. The remaining two cases of vote implement coin rounds. They call election in the same manner as above, in order to find out whether a supermajority already exists.

(* coin round but supermajority exists *) | vote_coin_super {s x y m n t f} {v : bool} : rwitness m x -> rwitness n y -> m < n -> (n - m) mod coin_freq = 0 -> election (vote s x) (pred n) y t f -> (if v then t else f)

two_thirds number_peers -> vote s x y v

(* coin round and no supermajority exists *) | vote_coin {s x y m n t f} : rwitness m x -> rwitness n y -> m < n -> (n - m) mod coin_freq = 0 -> election (vote s x) (pred n) y t f -> t <= two_thirds number_peers -> f <= two_thirds number_peers -> vote s x y (coin y s)

In the final case, coin y s gives y’s pseudo-random coin flip.

Induction Although Coq accepts the definition of vote, since all its recursive occurrences are positive, the definition is still too complicated for Coq to give it a useful induction principle. It does, however, provide a useful case-analysis principle. Thus, Coq essentially promises that vote is a fixed point, but not a least fixed point. This is inconvenient, because there are many times one would like to do induction over votes. Fortunately, we can work around the problem. The recursive instances of vote always deal with strict ancestors of the vote in question, so one can employ well-founded induction using the strict- ancestor relation. Within that induction, one can then do

a case analysis over the vote in question. This provides the power of the induction principle that one would have liked Coq to provide automatically.

3.5 Worlds

We use worlds to talk about potentially incompatible evo- lutions of the hashgraph. (The term is motivated by the use of the term in Kripke models.) In a modest loosening of the rules from our informal presentation, we allow that an event x might have two distinct self-children y and z, even if x’s creator is honest, provided that y and z exist only in distinct futures. However, y and z can never coexist in the same future (again, if the creator is honest). That is, two events in the same world cannot form a fork on an honest peer. Thus, a world is a set of events that is closed under an- cestor, and contains no forks:^9

Definition fork (e f : event) : Prop := creator e = creator f /\ ~ e $= f /\ ~ f $= e.

Record world : Type := mk_world { member : event -> Prop;

world_closed : forall x y, x @= y -> member y -> member x;

world_forks : forall a, honest a -> ~ exists e f, member e /\ member f /
fork e f /\ creator e = a }.

Here @= means ancestor (≤), and $= means self-ancestor (v). Many facts rely only on the events themselves, not any worlds they inhabit, but some require a world assump- tion. For example, consider the strongly seeing lemma (Lemma 2.3):

Lemma strongly_seeing : forall W x y v w, member W v -> member W w -> fork x y -> stsees x v -> stsees y w -> False.

Recall that, in the proof, we obtained events z and z′, sharing the same honest creator, where x E z ≤ v and y E z′^ ≤ w. We concluded that either z v z′^ or z′^ v z, since otherwise z and z′^ would constitute a fork on a hon- est peer. But in the formalization, forks are possible—even on an honest peer—if the sides of the fork belong to differ- ent futures. Requiring v and w (and therefore z and z′) to belong to the same world rules that out. (^9) Note that nothing requires a world to contain all the events, even at a particular point in time. Thus, for example, we can also use worlds to express the knowledge that a particular peer has about the hashgraph.

3.6 Pseudo-probability

The first element in our treatment of pseudo-probability is a sample space. A point in the sample space determines the outcome of every random or nondeterministic action, as well as the behavior of the adversary. However, unlike a true treatment of probability, we do not establish a measure for the sample space and compute probabilities. Instead, we will simply exclude any point in the sample space in which something happens that (informally speaking) has discrete probability zero. Specifically, we exclude any point that vi- olates the probability assumption that was given informally in Section 2.4.1 and formally by eventual_agreement below. This is formalized as the type sample, which one can think of as the type of all points in the sample space that are not being excluded. Since a point in the sample space determines everything that takes place, and specifically determines what events get created, a sample determines a world. We call this the global world determined by that sample.

global : sample -> world

For now we can think of global as primitive, but once we develop some more machinery, we can actually define it. At this point we can state the termination theorem (The- orem 2.17):

Theorem fame_consensus : forall s x, member (global s) x -> witness x -> exists y v, member (global s) y /\ decision s x y v.

If s is a sample, and x is a witness that gets created in the timeline resulting from s, then there exists some y from the same timeline, such that y makes a decision on x. Recall that termination relied on a good coins lemma (Lemma 2.16), which we can state thus:

Lemma good_coins : forall s i x, rwitness i x -> exists j y t f b, i < j /\ (j - i) mod coin_freq = 0 /\ member (global s) y /\ rwitness j y /\ election (vote s x) (pred j) y t f /\ ((t >= f /\ b = true) / (f > t /\ b = false)) /\ forall w, member (global s) w -> rwitness j w -> honest (creator w) -> coin w s = b.

3.6.1 Eventual agreement

Good coins depends in turn on the probability assumption. Before we can state it, we need a little more machinery. The probability assumption says that eventually all coins will agree with a target, provided the target is specified using only information available earlier. We get this notion of “earlier” from spawn order, defined by:

Axiom spawn_inj : forall s i j, spawn s i = spawn s j -> i = j.

Axiom spawn_parent : forall s x i, parent x (spawn s i) -> exists j, x = spawn s j /\ j < i.

Axiom spawn_forks : forall s i j, honest (creator (spawn s i)) -> fork (spawn s i) (spawn s j) -> False.

Axiom honest_peers_sync : forall s i a b, honest a -> honest b -> a <> b -> exists j k, i <= j /\ j <= k /\ creator (spawn s j) = a /\ creator (spawn s k) = b /\ spawn s j @ spawn s k.

Axiom no_orphans : forall x, exists s i, x = spawn s i.

Figure 2: Spawn order axioms

spawn : sample -> nat -> event

Suppose s is a point in the sample space. Then there exists a set S of all the events that will be created in the world s determines. (In order words, S contains all the elements of global s.) Then sort S according to the order the events are created in real time to obtain x 0 , x 1 , x 2 ,.. .. Then we define spawn s i = xi. Obviously, the “real time” ordering cannot be used by any participant, it is used only in reasoning about the algorithm. Several axioms (appearing in Figure 2) govern spawn or- der: (1) No event spawns more than once. (2) An event’s parents spawn before it does. The next two axioms are gen- eral rules of hashgraphs that are convenient to formalize in terms of spawn order: (3) Honest peers do not create forks. (4) Every honest peer eventually communicates with every other honest peer. (5) Finally, it is convenient to exclude any event that is part of no future. We can define the global world global s using spawn order as the set of all events x such that exists i, spawn s i = x. The spawn_parent axiom pro- vides the world_closed specification, and spawn_forks pro- vides world_forks.

To define the eventual agreement axiom, we need to for- malize the notion of a target depending only on earlier infor- mation. We will say that two samples are similar up to the ith spawn if their first i spawned events are the same, and they give the same coin flip for all of them except possibly the last:

  • We cannot permanently blacklist peers who cre- ate a fork, since this would require retaining in- formation about them indefinitely. Instead we introduce a consistent way of establishing prior- ity between the forked events, and one can only “see” the higher priority event. This is sufficient to reestablish Lemma 2.3, since the heart of the proof was the construction of an impossible event that sees both sides of a fork, and that remains impossible. This development is complete.
  • Since the participants of the network change over time, we need a way to deal with changing weights. (When a participant leaves the network, we can view that as its weight going to zero.) This is future work, although a prerequisite (having weights at all) is already done. The main compli- cation is ensuring that all peers always agree on all the weights, when the weights are determined by previous transactions.

ˆ The algorithm includes some operations that are ex- pensive to perform and that we want to avoid as much as possible. A good example is strongly seeing, which requires one to count all the different peers one can pass through between one event and another. That involves exploring many different paths. However, one can show that one can limit oneself to exploring certain canonical paths without sacrificing any key properties. A version incorporating this and other optimizations is complete.

In addition, one would like to establish the fairness theo- rem for d = 1. This is an important area for research, since d = 1 is preferable (faster consensus) but provably honest timestamps are also desirable.

References

[1] Leemon Baird. Personal communication.

[2] Leemon Baird. The Swirlds Hashgraph consensus algo- rithm: Fair, fast, Byzantine fault tolerance. Technical Report SWIRLDS-TR-2016-01, Swirlds Inc., May 2016.

[3] Leemon Baird, Mance Harmon, and Paul Madsen. Hedera: A public Hashgraph network & governing council. White paper at https://www.hedera.com/ hh-whitepaper-v2.0-17Sep19.pdf, August 2019.

[4] Leemon Baird and Atul Luykx. The Hashgraph pro- tocol: Efficient asynchronous BFT for high-throughput distributed ledgers. In IEEE International Conference on Omni-layer Intelligent Systems (COINS), 2020. To appear.

[5] Bruno Barras, Samuel Boutin, Cristina Cornes, Ju- dica¨el Courant, Jean-Christophe Filliˆatre, Eduardo Gim´enez, Hugo Herbelin, G´erard Huet, C´esar Mu˜noz, Chetan Murthy, Catherine Parent, Christine Paulin- Mohring, Amokrane Sa¨ıbi, and Benjamin Werner. The Coq Proof Assistant Reference Manual. INRIA- Rocquencourt, CNRS and ENS Lyon, 1996.

[6] Miguel Castro and Barbara Liskov. Practical Byzan- tine fault tolerance. In Third Symposium on Operat- ing Systems Design and Implementation, New Orleans, Louisiana, February 1999.

[7] Sisi Duan, Michael K. Reiter, and Haibin Zhang. BEAT: Asynchronous BFT made practical. In ACM SIGSAC Conference on Computer and Communica- tions Security, January 2018.

[8] Michael J. Fischer, Nancy A. Lynch, and Michael S. Paterson. Impossibility of distributed consensus with one faulty process. Journal of the ACM, 32(2):374–382, April 1985.

[9] Leslie Lamport, Robert Shostak, and Marshall Pease. The Byzantine generals problem. ACM Transactions on Programming Languages and Systems, 4(3), July

[10] Andrew Miller, Yu Xia, Kyle Croman, Elaine Shi, and Dawn Song. The honey badger of BFT protocols. In ACM SIGSAC Conference on Computer and Commu- nications Security, pages 31–42, October 2016.

[11] Satoshi Nakamoto. Bitcoin: A peer-to-peer electronic cash system. Disseminated to The Cryptography Mail- ing List, November 2008.

[12] Marshall Pease, Robert Shostak, and Leslie Lamport. Reaching agreement in the presence of faults. Journal of the ACM, 27(2), April 1980.

[13] Fred B. Schneider. Implementing fault-tolerant services using the state machine approach: A tutorial. ACM Computing Surveys, 22(4), December 1990.

[14] Visa Corporation. Visa Inc. at a glance. Marketing document at https://usa.visa. com/dam/VCOM/download/corporate/media/ visa-fact-sheet-Jun2015.pdf, 2015. Retrieved July 2020.

[15] Visa Corporation. Visa fact sheet. Marketing document at https://usa.visa.com/dam/VCOM/ download/corporate/media/visanet-technology/ aboutvisafactsheet.pdf, 2020. Retrieved July 2020.