Lecture on 22 January 2019
CAP Theorem
Byzantines General Problem
Blockchain for Beginners
Elective course from the Faculty of Information Technology, Thai - Nichi Institute of Technology, Bangkok for undergraduate students.
#BlockchainTNI2018
Blockchain Technology - Week 10 - CAP Teorem, Byzantines General Problem
1. Blockchain Technology
Week 10
Unit IV – CAP Theorem, Byzantines General Problem
Ferdin Joe John Joseph, PhD
Faculty of Information Technology
Thai-Nichi Institute of Technology, Bangkok
Venue: D603
2. Week 10 – Unit IV
Agenda
• CAP Theorem
• Byzantines General Problem
Faculty of Information Technology, Thai-Nichi Institute of
Technology
2
4. Features
• Symmetrical
• Key length of 57,000 to 200,000 bits
• No delimitation in number system
• Insensitive to factorize
• No semantics in cipher
Faculty of Information Technology, Thai-Nichi Institute of
Technology
4
7. Applications
• All applications of Banking
• Defense Technologies
• Telecommunication
• Health
• Plagiarism Protection
• Satellite Communication
Faculty of Information Technology, Thai-Nichi Institute of
Technology
7
9. CAP Theorem
• Also known as Brewer’s Theorem
• Named after Computer Scientist Erik Brewer in 2002
Faculty of Information Technology, Thai-Nichi Institute of
Technology
9
10. Theorem
• A distributed database can provide any two out of the three
gurantees only among those stated below.
1. Consistency: Every read receives the most recent write or an error
2. Availability: Every request receives a (non-error) response –
without the guarantee that it contains the most recent write
3. Partition tolerance: The system continues to operate despite an
arbitrary number of messages being dropped (or delayed) by the
network between nodes
Faculty of Information Technology, Thai-Nichi Institute of
Technology
10
12. CAP Expanded
Faculty of Information Technology, Thai-Nichi Institute of
Technology
12
C: Consistency – At any given time, all nodes in the network have
exactly the same (most recent) value.
13. CAP Expanded
• A: Availability – Every request to the network receives a response,
though without any guarantee that returned data is the most recent.
Faculty of Information Technology, Thai-Nichi Institute of
Technology
13
14. CAP Expanded
• P: Partition tolerance – The network continues to operate, even if an
arbitrary number of nodes are failing.
Faculty of Information Technology, Thai-Nichi Institute of
Technology
14
15. CAP Theorem Applied
• Due to the nature of distributed data stores (such as blockchain),
Partition tolerance is a given fact; there will always be
failing/unreachable nodes in the network (not least because of the
unstable nature of the internet). CAP Theorem states that one has to
choose between C (Consistency) or A (Availability) when in the
presence of P (Partition):
Faculty of Information Technology, Thai-Nichi Institute of
Technology
15
16. Availability + Partition Tolerance
• Every request to the network receives a response, even if the
network cannot guarantee it is up to date due to network partitioning
(failing nodes).
• Choosing Availability over Consistency for a world-wide distributed
system will make it highly available, but its data will be out of date for
99.99% of the time. Furthermore, no-one will be able to guarantee
that the data returned is in fact the most recent.
Faculty of Information Technology, Thai-Nichi Institute of
Technology
16
17. Availability + Partition Tolerance
Faculty of Information Technology, Thai-Nichi Institute of
Technology
17
18. Consistency + Partition Tolerance
• The system will return an error or a time-out if particular information
cannot be guaranteed to be up to date due to network partitioning
(failing nodes).
• Choosing Consistency over Availability for a world-wide distributed
system will make it highly accurate, but it will most likely be
unavailable for 99.99% of the time.
Faculty of Information Technology, Thai-Nichi Institute of
Technology
18
19. Consistency + Partition Tolerance
Faculty of Information Technology, Thai-Nichi Institute of
Technology
19
20. Does Blockchain Violate CAP Theorem ?
• NO
• Those interested in blockchain, opt for AP (Availability + Partition) +
Strong/Eventual Consistency.
• This doesn’t mean Consistency used to the fullest.
Faculty of Information Technology, Thai-Nichi Institute of
Technology
20
23. Byzantine - History
• Byzantine Empire, the eastern half of the Roman Empire, which
survived for a thousand years after the western half had crumbled
into various feudal kingdoms and which finally fell to Ottoman Turkish
onslaughts in 1453.
Faculty of Information Technology, Thai-Nichi Institute of
Technology
23
24. Scenario
• Imagine that the grand Eastern Roman empire aka Byzantine empire
has decided to capture a city.
• The Byzantine army has completely encircled the city. The army has
many divisions and each division has a general.
• The generals communicate between each as well as between all
lieutenants within their division only through messengers.
Faculty of Information Technology, Thai-Nichi Institute of
Technology
24
26. Faculty of Information Technology, Thai-Nichi Institute of
Technology
26
Commander
Lieutenant 1 Lieutenant 2
“attack”“attack”
“He said ‘retreat’”
Lieutenant 2 is corrupt and consensus cannot be reached.
27. Faculty of Information Technology, Thai-Nichi Institute of
Technology
27
Commander
Lieutenant 1 Lieutenant 2
“retreat”“attack”
“He said ‘retreat’”
Commander is corrupt and consensus cannot be reached.
28. Faculty of Information Technology, Thai-Nichi Institute of
Technology
28
Commander
Lieutenant 1 Lieutenant 2 Lieutenant 3
“attack” “attack” “attack”
“attack” “retreat”
29. Faculty of Information Technology, Thai-Nichi Institute of
Technology
29
Commander
Lieutenant 1 Lieutenant 2 Lieutenant 3
“attack” “retreat” “not sure”
“attack” “not sure”
“retreat” “retreat”
“attack”
“not sure”
30. How it applies to Blockchain
• Consensus Mechanism as it follows distributed mechanism
• In blockchain network, there is no commander
• Each node becomes a lieutenant and fall under equal hierarchy
Faculty of Information Technology, Thai-Nichi Institute of
Technology
30
31. How it applies to Blockchain
• All participating nodes have to agree upon every message that is
transmitted between the nodes.
• If a group of nodes is corrupt or the message that they transmit is
corrupt then still the network as a whole should not be affected by it
and should resist this ‘Attack’.
• In short, the network in its entirety has to agree upon every message
transmitted in the network. This agreement is called as consensus.
Faculty of Information Technology, Thai-Nichi Institute of
Technology
31
32. Practical Byzantine Fault Tolerance (PBFT)
• Faster
• Handle n Byzantine faults in a system with 3n+1 nodes
Faculty of Information Technology, Thai-Nichi Institute of
Technology
32
33. PBFT Process
Request Preprepare Prepare Commit Reply
Faculty of Information Technology, Thai-Nichi Institute of
Technology
33
34. PBFT by example
Faculty of Information Technology, Thai-Nichi Institute of
Technology
34
Client Alpha
Bravo
Delta
Charlie
35. PBFT REQUEST
Faculty of Information Technology, Thai-Nichi Institute of
Technology
35
Client Alpha
Bravo
Delta
Charlie
36. PBFT REQUEST
Faculty of Information Technology, Thai-Nichi Institute of
Technology
36
Client Alpha
Bravo
Delta
Charlie
37. PBFT PRE PREPARE
Faculty of Information Technology, Thai-Nichi Institute of
Technology
37
Client Alpha
Bravo
Delta
Charlie
38. PBFT PREPARE
Faculty of Information Technology, Thai-Nichi Institute of
Technology
38
Client Alpha
Bravo
Delta
Charlie
39. PBFT PREPARE
Faculty of Information Technology, Thai-Nichi Institute of
Technology
39
Client Alpha
Bravo
Delta
Charlie
40. PBFT COMMIT
Faculty of Information Technology, Thai-Nichi Institute of
Technology
40
Client Alpha
Bravo
Delta
Charlie
41. PBFT REPLY
Faculty of Information Technology, Thai-Nichi Institute of
Technology
41
Client Alpha
Bravo
Delta
Charlie
42. PBFT
Request Preprepare Prepare Commit Reply
Faculty of Information Technology, Thai-Nichi Institute of
Technology
42
Client
Alpha
Bravo
Delta
Charlie
43. PBFT
Request Preprepare Prepare Commit Reply
Faculty of Information Technology, Thai-Nichi Institute of
Technology
43
Client
Alpha
Bravo
Delta
Charlie
44. PBFT
Request Preprepare Prepare Commit Reply
Faculty of Information Technology, Thai-Nichi Institute of
Technology
44
Client
Alpha
Bravo
Delta
Charlie
45. PBFT
Request Preprepare Prepare Commit Reply
Faculty of Information Technology, Thai-Nichi Institute of
Technology
45
Client
Alpha
Bravo
Delta
Charlie
46. PBFT
Request Preprepare Prepare Commit Reply
Faculty of Information Technology, Thai-Nichi Institute of
Technology
46
Client
Alpha
Bravo
Delta
Charlie
47. Next Week
• Peer to Peer Networking
• Distributed Computing
Faculty of Information Technology, Thai-Nichi Institute of
Technology
47