Crypto Markets
Crypto Markets
consensus
Christian Cachin
(with Elli Androulaki, Angelo De Caro, Andreas Kind, Mike Osborne, Simon
Schubert, Alessandro Sorniotti, Marko Vukolic and many more)
June 2017
Connected markets
‣ Networks connect participants
– Customers, suppliers, banks, consumers
2
Ledger
‣ Ledger records all business activity as
transactions
– Databases
3
Multiple ledgers
Ledger ‣ Every party keeps its own
B
Bob Ledger ledger and state
C
Ledger ‣ Problems, incidents, faults
A Alice Charlie
‣ Diverging ledgers
Frank Dave
Ledger Ledger
Eve D
F
Ledger
E
4
Blockchain provides one virtual ledger
‣ One common trusted ledger
Bob
‣ Today often implemented by a
centralized intermediary
Alice Charlie
‣ Blockchain creates one single
One
ledger for all parties
Ledger
7
Blockchain scenario features
‣ A given task or problem, but no (central) trusted party available
8
Why blockchain now?
‣ Cryptography has been a key technology in the financial world for decades
– Payment networks, ATM security, smart cards, online banking ...
9
What is a blockchain?
10
When you get too many people talking
about the same thing it tends to clutter up
things.
11
A state machine
‣ Functionality F
– Operation o transforms a state s to new state s' and may generate a response r
r
o
(s', r) ← F(s, o)
s s'
‣ Validation condition
– Operation needs to be valid, in current state, according to a predicate P()
r
o
s s'
12
P(s,o) = TRUE
Blockchain state machine
‣ Append-only log
– Every operation o appends a "block" of valid transactions (tx) to the log
s s'
13
Example – The Bitcoin state machine
‣ Bitcoins are unforgeable bitstrings
– "Mined" by the protocol itself (see later)
14
Distributed p2p protocol to create a ledger
Nodes
produce
transactions
Nodes run a
o1 o2 o3 protocol to
construct the
s0 s1 s2 s3 ledger
15
Blockchain protocol features
‣ Only "valid" operations (transactions) are "executed"
16
Consensus
17
Three kinds of consensus for blockchain
‣ Decentralized / permissionless
– Bitcoin, Ethereum
‣ Somewhat decentralized
– Ripple, Stellar
‣ Consortium / permissioned
– BFT (Byzantine fault tolerance) consensus
18
Decentralized – Nakamoto consensus/Bitcoin
‣ Nodes prepare blocks
– List of transactions (tx)
– All tx valid
‣ Lottery race
– Solves a hard puzzle
– Selects a random
winner/leader
– Winner's operation/
block is executed and
"mines" a coin
‣ Protocol features
– Stability is a tradeoff between dissemination of new block (10s-20s) and mining rate
(new block on average every 10min)
– Decisions are not final ("wait until chain is 6 blocks longer before a tx is confirmed")
20
Decentralized – deployment
‣ Bitcoin
– Many (100s? 1000s?) of alt-coins and blockchains
‣ Ethereum
– First digital currency with general-purpose smart contract execution
21
Somewhat (de)centralized – Ripple, Stellar
‣ Nodes decide whom
to trust
– Validator nodes
‣ Quorum-like protocol
– Among different
heterogeneous
validators
‣ Consistent when
"enough" nodes in
path are trusted by
the nodes involved
in the transaction
22
Somewhat (de)centralized
‣ Every node designates other, well-connected nodes that it trusts
– Decentralization
‣ Open questions
– Relation to Byzantine quorum systems [MR98]
– How to formally specify properties
23
Consortium consensus (quorums & BFT)
‣ Designated set of
homogeneous
validator nodes
‣ BFT/Byzantine agreement
– Tolerates f-out-of-n faulty/
adversarial nodes
– Generalized quorums
‣ Tx sent to consensus
nodes
● Textbooks [CGR11]
– Many systems already provide crash tolerant consensus (Chubby, Zookeeper, etcd ...)
– Requires Ω(n2) communication (OK for 10-100 nodes, not > 1000s)
‣ HoneyBadgerBFT [MXC+16]
– Revisits practical randomized BFT [CKPS01], including amoritzation
26
More variations of consensus
‣ Bitcoin-NG [EGS+16]
– Bitcoin PoW elects a leader, it is responsible for ordering the next K tx
27
Scalability–performance tradeoff
M. Vukolic: The Quest for Scalable Blockchain Fabric: Proof-of-Work vs. BFT Replication.
28 Proc. iNetSec 2015, LNCS 9591.
Validation
29
Validation of transactions – PoW protocols
‣ Recall validation predicate P on state s and operation o: P(s, o)
‣ When a new block is propagated, all nodes must validate the block and its tx
– Simple for Bitcoin – verify digital signatures and that coins are unspent
– More complex and costly for Ethereum – re-run all the smart-contract code
30
Validation of transactions – BFT protocols
‣ Properties of ordinary Byzantine consensus
– Weak Validity: Suppose all nodes are correct: if all propose v, then a node may only
decide v; if a node decides v, then v was proposed by some node.
– Agreement: No two correct nodes decide differently.
– Termination: Every correct node eventually decides.
31
Public validation vs. private state
‣ So far everything on blockchain is public – where is privacy?
– In ZeroCash [BCG+14], blockchain holds committed coins and transfers use zero-
knowledge proofs (zk-SNARKS) validated by P
32
Security and privacy
‣ Transactional privacy
– Anonymity or pseudonymity through cryptographic tools
– Some is feasible today (e.g., anonymous credentials in IBM Identity Mixer)
‣ Contract privacy
– Distributed secure cryptographic computation on encrypted data
34
Hyperledger
‣ A Linux Foundation project – www.hyperledger.org
– Open-source collaboration, developing blockchain technologies for business
– Started in 2016: Hyperledger unites industry leaders to advance blockchain technology
– 135 members in Apr. '17
‣ Technical details
– Implemented in GO
– Runs smart contracts or "chaincode" within Docker containers
– Transactions Deploy new chaincode / Invoke an operation / Read state
– Implements consortium blockchain using traditional consensus (BFT, ZooKeeper)
39
Hyperledger Fabric V1
‣ Separate the functions of nodes into endorsers and consensus nodes
– Every chaincode may have different endorsers
– Endorsers have state, run tx, and validate tx for their chaincode
– Chaincode specifies endorsement policy
– Consensus nodes order endorsed and already-validated tx
– All peers apply all state changes in order, only for properly endorsed tx
‣ Consensus service
– Only communication
– Pub/sub messaging
– Ordering for endorsed tx
Consensus service
‣ State and hash chain only orders tx
are common
– State may be encrypted
41
Transactions in Fabric V1
‣ Client
– Produces a tx (operation) for some chaincode (smart contract)
‣ Submitter peer
– Execute/simulates tx with chaincode
– Records state values accessed, but does not change state readset/writeset
‣ Endorsing peer
– Re-executes tx with chaincode and verifies readset/writeset
– Endorses tx with a signature on readset/writeset
‣ Consensus service
– Receives endorsed tx, orders them, and outputs stream of "raw" tx (=atomic broadcast)
‣ All peers
– Disseminate tx stream from consensus service with p2p communication (gossip)
– Filter out the not properly endorsed tx, according to chaincode endorsement policy
– Execute state changes from readset/writeset of valid tx, in order
42
Transaction flow
43
Modular consensus in Fabric V1
‣ "Solo orderer"
– One host only, acting as specification during development (ideal functionality)
44
Conclusion
45
Conclusion
‣ Blockchain enables new trust models
– www.hyperledger.org
– www.ibm.com/blockchain/
– www.research.ibm.com/blockchain/
46
References
[AGK+15] P.-L. Aublin, R. Guerraoui, N. Knezevic, V. Quéma, M. Vukolic: The Next 700 BFT Protocols. ACM
TOCS, 32(4), 2015.
[BCG+14] E. Ben-Sasson, A. Chiesa, C. Garman, M. Green, I. Miers, E. Tromer, M. Virza: Zerocash:
Decentralized Anonymous Payments from Bitcoin. IEEE S&P 2014.
[CKPS01] C. Cachin, K. Kursawe, F. Petzold, V. Shoup: Secure and Efficient Asynchronous Broadcast
Protocols. CRYPTO 2001.
[CGR11] C. Cachin, R. Guerraoui, L. Rodrigues: Introduction to Reliable and Secure Distributed
Programming (2. ed.). Springer, 2011.
[CSV16] C. Cachin, S. Schubert, M. Vukolic: Non-determinism in Byzantine Fault-Tolerant Replication.
OPODIS 2016.
[CL02] M. Castro, B. Liskov: Practical Byzantine fault tolerance and proactive recovery. ACM TOCS, 20(4),
2002.
[DSW16] C. Decker, J. Seidel, R. Wattenhofer: Bitcoin meets strong consistency. ICDCN 2016.
[EGS+16] I. Eyal, A. Gencer, E.G. Sirer, R. van Renesse: Bitcoin-NG: A Scalable Blockchain Protocol. NSDI
2016.
47
References
[KMS+16] A. Kosba, A. Miller, E. Shi, Z. Wen, C. Papamanthou: Hawk: The Blockchain Model of
Cryptography and Privacy-Preserving Smart Contracts. IEEE S&P 2016.
[LNB+15] L. Luu, V. Narayanan, K. Baweja, C. Zheng, S. Gilbert, P. Saxena: A Secure Sharding Protocol For
Open Blockchains. ACM CCS 2016.
[MR98] D. Malkhi, M. Reiter: Byzantine Quorum Systems. Distributed Computing, 1998.
[MXC+16] A. Miller, Y. Xia, K. Croman, E. Shi, D. Song: The Honey Badger of BFT Protocols. ACM CCS 2016.
[V16] M. Vukolic: The Quest for Scalable Blockchain Fabric: Proof-of-Work vs. BFT Replication. LNCS 9591,
Proc. iNetSeC 2015.
48
Hyperledger Fabric references
‣ www.hyperledger.org
‣ Docs – hyperledger-fabric.readthedocs.io/en/latest/
‣ Designs – wiki.hyperledger.org/community/fabric-design-docs
‣ Architecture of V1 –
github.com/hyperledger/fabric/blob/master/proposals/r1/Next-Consensus-
Architecture-Proposal.md
‣ Code – github.com/hyperledger/fabric
49
50
Consensus?
51
Consensus?
52
Consensus?
53
Consensus?
54
Consensus?
55
Consensus?
56
Consensus?
57
58
Hyperledger Fabric details (v0.6-preview) / 1
‣ Platform-agnostic
– GO, gRPC over HTTP/2
‣ Peers
– Validating peers (all running consensus) and non-validating peers
‣ Transactions
– Deploy new chaincode / Invoke an operation / Read state
– Chaincode is arbitrary GO program running in a Docker container
59
Hyperledger Fabric details / 2
‣ Consensus in BFT model
– Modular architecture supports other consensus protocols
– Currently, Practical Byzantine Fault Tolerance (PBFT) [CL02]
– Non-determinism addressed by Sieve protocol [CSV16]
– Static membership in consensus group
60
Hyperledger Fabric details / 3
‣ Membership service issues certificates to peers
– Enrollment certificates (E-Cert, issued by E-CA)
● Assign identity to peer, gives permission to join and issue transactions
61
Hyperledger Fabric details (V0.6)
‣ Peers
– Validating peers (all running consensus) and non-validating peers
‣ Transactions
– Deploy new chaincode / Invoke an operation / Read state
– Chaincode is arbitrary GO program running in a Docker container
‣ If application is randomized
– For algorithmic purpose (Monte Carlo): use master-slave approach
– For cryptography and security functions: cryptographic verifiable random functions (VRF)
63