The Science of the Blockchain
Roger Wattenhofer
Copyright c 2016 by Roger Wattenhofer
First Edition 2016
Inverted Forest Publishing
ISBN-13 978-1522751830
ISBN-10 1522751831
Preface
When hanging out with colleagues from financial technology (Fin-
Tech), you cannot help but notice that the so-called blockchain is
all the rage, almost as important as the Internet. Some FinTech
colleagues seem to understand the blockchain as a magic piece of
code that allows the participants of a distributed system to agree
on a common view of the system, to track changes in the system.
In the distributed systems community, agreement techniques have
been known long before cryptocurrencies such as Bitcoin (where
the term blockchain is borrowed) emerged. Various concepts and
protocols exist, each with its own advantages and disadvantages.
The idea of this book is to give a scientifically precise overview
of the most interesting approaches that have emerged in the past
few decades. If you are a developer (in FinTech or not), this book
will help you to get a better understanding what is right and what
is wrong for your distributed system, what is possible and what is
not.
This Book
This book introduces the basic techniques when building fault-
tolerant distributed systems. We will present different protocols
and algorithms that allow for fault-tolerant operation, and we will
discuss practical systems that implement these techniques.
The book presents the main ideas independently from each
other, each topic has its own chapter. Each chapter starts with an
introductory story that motivates the content of the chapter. Al-
gorithms, protocols and definitions are presented formally, so that
you know how to implement the ideas. Some insights are proved
in theorems, so that you learn why the concepts or algorithms are
correct, and what they can guarantee. Most of the other text is
iii
iv
presented as so-called remarks. These remarks discuss various in-
formal thoughts, and often set the stage for the next idea. However,
one will get the essence of each chapter even without reading any
of these remarks. Each chapter also discusses the history of the
ideas presented in the chapter, so that you can find the original
research.
In this book, we will see different models (and combinations of
models) that may make sense in different scenarios. The focus of
the book is on protocols and systems that matter in practice. In
other words, we do not discuss concepts because they are fun, but
because they are practically relevant.
Nevertheless, have fun!
Contents
1 Introduction
1.1 What are Distributed Systems? . . . . . . . . . . . .
1.2 Book Overview . . . . . . . . . . . . . . . . . . . . .
1
1
2
2 Fault-Tolerance & Paxos
2.1 Client/Server . . . . . . . . . . . . . . . . . . . . . .
2.2 Paxos
5
5
. . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Consensus
17
3.1 Two Friends . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Consensus . . . . . . . . . . . . . . . . . . . . . . . . 18
Impossibility of Consensus . . . . . . . . . . . . . . . 18
3.3
3.4 Randomized Consensus
. . . . . . . . . . . . . . . . 25
3.5 Shared Coin . . . . . . . . . . . . . . . . . . . . . . . 29
4 Byzantine Agreement
33
4.1 Validity . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.2 How Many Byzantine Nodes? . . . . . . . . . . . . . 35
4.3 The King Algorithm . . . . . . . . . . . . . . . . . . 38
. . . . . . . . . 40
4.4 Lower Bound on Number of Rounds
4.5 Asynchronous Byzantine Agreement
. . . . . . . . . 40
5 Authenticated Agreement
45
5.1 Agreement with Authentication . . . . . . . . . . . . 45
5.2 Zyzzyva . . . . . . . . . . . . . . . . . . . . . . . . . 47
6 Quorum Systems
61
6.1 Load and Work . . . . . . . . . . . . . . . . . . . . . 62
6.2 Grid Quorum Systems . . . . . . . . . . . . . . . . . 64
6.3 Fault Tolerance . . . . . . . . . . . . . . . . . . . . . 66
6.4 Byzantine Quorum Systems . . . . . . . . . . . . . . 70
v
vi
CONTENTS
7 Eventual Consistency & Bitcoin
77
7.1 Consistency, Availability and Partitions
. . . . . . . 78
7.2 Bitcoin . . . . . . . . . . . . . . . . . . . . . . . . . . 79
7.3 Smart Contracts
. . . . . . . . . . . . . . . . . . . . 87
7.4 Weak Consistency . . . . . . . . . . . . . . . . . . . 91
8 Distributed Storage
95
8.1 Consistent Hashing . . . . . . . . . . . . . . . . . . . 95
8.2 Hypercubic Networks . . . . . . . . . . . . . . . . . . 97
8.3 DHT & Churn . . . . . . . . . . . . . . . . . . . . . 105