FITE3011 Distributed Ledger and Blockchain: Lecture 1 Introduction
FITE3011 Distributed Ledger and Blockchain: Lecture 1 Introduction
2
Course Structure Lectures/tutorials
Assignments Examination
•3
+ ~34 lecture/tutorial hours
+ ~ 6-9 lab hours
Consultation hours
Emails
Discussion forum
4
Schedule Lectures will be delivered in both F2F and
online. Tutorials are delivered in online mode
only. Please refer to schedule on Moodle.
› Lecture/Tutorial
– Tuesday 4:30 – 6:20
– Friday 5:30 – 6:20
› TA’s Consultation (Zoom, Tuesday 2:30 – 3:30)
– https://hku.zoom.us/j/91402128397?pwd=bUtGVm5vM1F1KzN
5T2hqbnptWm02UT09
– Meeting ID: 914 0212 8397
– Password: 473013
› Allen’s Consultation (Zoom /CB409)
– Friday 1:30 – 3:30
u Refer to moodle page for any changes/announcements.
5
What to learn in this course?
CLO1. [Technical foundation]
Identify key components behind the design of a
distributed ledger (and blockchain) and evaluate different
designs/solutions for implementing a distributed ledger.
CLO2. [Applications and programming]
Understand the types of applications that best fit the
model of distributed ledger; program applications and
smart contracts on some popular platforms.
CLO3. [Cryptocurrency and related issues]
Understand the technologies behind different
cryptocurrencies, their applications, and related issues (e.g.
Regulations).
CLO4. [Limitations and extensions]
Understand the limitations, pros and cons of a distributive
ledger, possible enhancements to existing platforms, and
identify new applications.
Review of Cryptography
7
(i) Concept of public key, private key pairs
- Public key & private key always go in pairs (like
husband and wife)
- Each user has a pair of public and private key
Private Key Public Key
- To encrypt a
document to be
read by user Bob,
we need to use
Bob
Bob’s public key;
and only Bob’s
private key can
be used to
decrypt it.
11
(iii) Hash value (cryptographic hash)
Given any digital document (no matter how long it is), we
can generate a fingerprint of fixed length (e.g. 160 bits),
called hash value.
Q: Can you name some hash functions?
E.g. MD5, SHA1
13
** Important properties of hash function (must
satisfy) **
(i) Given a document D, computing the hash value of D,
H(D) is easy, but Given a hash value x, very difficult to
find a document D such that H(D) = x.
(i’) A variation of (i):
Find a document D such that H(D) starts with 10
0’s is also difficult!
14
Usage (fast and safe):
Given a document D,
(i) create a hash value of D, H(D)
(ii) sign on H(D) instead of D.
Remarks:
- H(D) guarantees D has not been modified.
- Signature on H(D) can claim the ownership of D
15
Challenge: Secure Hash Function?
2 3
x1
6 .. 7
𝐴:= 𝑥: = 4 . 5
xn
16
Challenge: Secure Hash Function?
17
A short summary (Usage of these techniques)
Internet
C’
Hackers
Devil
19
There are two things Alice want to do:
- Avoid the contract being modified
- Claim that she is the author
Q: What can she do?
C ‘ + hash(C ‘)
20
Q: How about this?
This is ok provided
(1) Company knows the sender is Alice (not Devil)
[Authentication].
(2) Company can check if hash value matches the
contract.
(3) Based on the signature, Company can confirm
the Contract is from Alice and nobody has
modified it.
21
Q: how about this:
“Contract C + Sign (C)”?
22
More on cryptographic primitives
Q: If we know A’s public key, is it impossible to compute
his private key even if you have tremendous amount of
computing resource?
A: It is possible: computationally secure only.
23
Q: There are many encryption/signature schemes, is it ok
to randomly pick one to use?
A: Yes.
24
Blockchain 101
25
What is a blockchain (in the context of
bitcoin or bank transactions for ease
understanding)?
Transaction example:
Deposit 15 coins to Alice
Or
Transfer 10 coins from Alice to Bob
Or
Transfer 6 coins from Bob to David
26
A transaction chain:
Authorization
Deposit 15 coins to Alice
28
Recall:
Hash of the
contract
29
Use cryptographic operations to build blockchain
1st attempt:
30
Use cryptographic operations to build blockchain
1st attempt:
$1 to D
Tr1: Tr2: Tr3:
A: $10 to B B: $5 to C A: $5 to D
A can recompute
the new hash and
the signature!
31
Hint:
Recall that hash can make things
difficult to change!
32
Modified version
Tr1: Tr2:
A: $10 to B B: $5 to C h3 = hash(Tr3+D2)
h1 = hash(Tr1) h2 = hash(Tr2+D1)
SignA(h1) SignB(h2) hi = hash(Tri+Di-1)
D1
33
(b) Who is going to maintain this chain and append
new Tr?
A: Everybody joining the scheme in the network
- Everybody tries to keep a copy of the chain
- When A has a new transaction, he broadcasts to
everyone. Everyone can check it to make sure it is valid
and tries to append it to the chain
34
Chaos?
In the beginning, assume every miner got the
same blockchain, but after a while, we may have:
Tr1: Tr2:
A: $10 to B B: $5 to D Double
h1 = hash(Tr1) h2 = hash(Tr2+D1) Spend
SignA(h1) SignB(h2)
36
A very simple rule, but it works:
Everybody follows the longest chain
37
Tr1:
Existing A: $10 to B
chain h1 = hash(Tr1)
SignA(h1)
Correct Fake
Tr2: Tr2’:
B: $5 to C B: $15 to C
h2 = hash(Tr2+D1) h2 = hash(Tr2’+D1)
SignA(h2) SignA(h2)
39
So, they make the addition of transaction difficult:
“Proof of work”: You work on it, you get reward!
h1 = hash(Tr1) h2 = hash(Tr2+D1)
SignA(h1) SignB(h2) hi = hash(Tri+Di-1)
D1
Requirement:
Q: How to find Add a random r to (Tr2+D1||r)
this r? such that the value of
hash(Tr2+D1||r) starts with n
No efficient
method => 0’s (n approx. = 75 now)
brute-force
e.g. hash() can be SHA-256
41
More questions to think about:
Q: If B transfers $100 to A, immediately A sees that
the transaction has been appended to the blockchain, can
A be sure that the money has been transferred
successfully.
42
More questions to think about:
Q: If B transfers $100 to A, immediately A sees that
the transaction has been appended to the blockchain, can
A be sure that the money has been transferred
successfully.
43
Last Q: How to protect privacy?
Tr1:
PKA: $10 to PKB
h1 = hash(Tr1)
SignRKA(h1)
44
Hey, then what is blockchain?
45
<Very high level: short summery> What is blockchain?
Can it be A
replaced by database X
system
A blockchain platform
Properties:
-Decentralized (no centralized authority (all users/miners))
-Immutability (no changes in records, guaranteed by crypto)
-Transparent (every one can check *all* transactions), ……
46
Q: Differences between a distributed system
and a decentralized system?
Distributed systems vs Decentralized systems
Whether it is
decentralized:
Who “own” and “make”
decisions for the system
47
E.g. Google
Q: Is it distributed? Yes
Q: Is it decentralized? No
Other examples:
- Cloud service providers, e.g. Amazon, Tencent?
Distributed system
Decentralized
system
49
Q: Why decentralized?
51
No
Database? X
Yes
Yes
Have a trusted authority High trans fee?
No Yes No
No
Involve > 2 entities? X
Yes
No (only a few)
Will all entities join?
Yes (majority) Yes
High freq?
No evaluate? Chain of custody,
Consider blockchain savings in proc, many-many? 52
Summary questions:
Q1
Which of the followings are the reasons for using blockchain technologies?
(a) There is no trusted authority.
(b) The transaction fee is too high.
(c) We want to ensure data availability.
(d) Because we require high transaction rate.
(e) All of the above.
Q2
How blockchain protect the identify of users? And how one
can show that he/she is the owner of the account to use the
bitcoin?
53
Q3:
How blockchain technology guarantees that no users can
easily modify the transactions without being noticed?
Q4:
Why miners need to solve a computational problem before
adding a new transaction to the blockchain?
Q5:
Why in the original blockchain system, we should follow the
longest chain?
54
Answers
Q1: (a), (b), (c).
56
Question: Where is the blockchain?
N Blockchain Network
P1 P2 P3
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
P Peer node
1 2 3 4 5 Blockchain
P4 P5 P6
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
Network
Tx1
Network
Tx1
Tx2 Tx1
Tx2
Tx1
P Peer node
Tx2
A2 Tx2
Tx3
Tx3 Tx4
P4 P5 P6
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 Blockchain
N
Peer node maintain a pool of transactions that have not been included in the blocks yet
Transactions Recording (3)
Client
A Application
P1 P2 P3
A1 Blockchain
N
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
Network
Tx1
Tx2
Tx2 Tx1
Tx2
P Peer node
A2 Tx3
Tx3
Tx4
P4 P5 P6
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 Blockchain
N
6
Tx1
Tx2
Tx3 Each peer node tries to create a new block that contains the transactions in its pool.
The peer node should also execute each transaction to ensure they are valid.
Transactions Recording (4)
Client
A Application
P1 P2 P3
A1 Blockchain
N
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
Network
6
Tx1
Tx2
Tx2 Tx1
Tx2
P Peer node
A2 Tx3
Tx3
Tx4
P4 P5 P6
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 Blockchain
N
6
Tx1
Tx2
Tx3 The peer node broadcast the newly found block to other peer node in the blockchain network.
Transactions Recording (5) Tx16
Tx2
Tx3 Client
A Application
P1 P2 P3
A1 Blockchain
N
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
Network
6
Tx1
Tx2
Tx2 Tx1
Tx2
P Peer node
A2 Tx3
Tx3
Tx4
P4 P5 P6
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 2 3 4 5 Blockchain
N
The peer node receiving the new block check the correctness of the block, which include
validating all transactions included in the block with respect to its local blockchain copy,
and append it to its own copy of the blockchain
Transactions Recording (6)
Client
A Application
P1 P2 P3
A1 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 Blockchain
N
Network
P Peer node
A2 Tx4
P4 P5 P6
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 Blockchain
N
Each peer node appends the new block and updates its own mempool