Vous êtes sur la page 1sur 51

Corda Workshop

Introduction to Blockchain & Related Technologies


Dr. Dennis Y. W. Liu
Department of Computing, The Hong Kong Polytechnic University
Workshops Outline
Date Time Topics
8/3/2018 (Thu) 7:30 – 9:30pm - Introduction to Blockchain and related
technologies
17/3/2018 (Sat) 2:00 – 5:00pm - Introduction to Corda
- Experiencing the Programming Environment
- Experience the IOU (I Owe yoU) case in Corda
22/3/2018 (Thu) 6:30 – 9:30pm - Coding in Corda – States, Contracts and
Transaction
29/3/2018 (Thu) 6:30 – 9:30pm - Coding in Corda – Flows, Nodes and Web API
- Blockchain Cases/Projects
12/4/2018 (Thu) 7:30 – 9:30pm - Corda Test (Candidates passing the test will be
conferred a certificate issued by Hong Kong
Blockchain Society)

1
Speakers
› Dr. Lawrence Ma
– President of the Hong Kong Blockchain Society and CEO of
eMALI.IO Limited

› Dr. Dennis Y. W. Liu


– Teaching Fellow, Department of Computing, The Hong Kong
Polytechnic University

2
Agenda
› “I Owe yoU” (IOU) scenario
› What is Blockchain?
› Blockchain Applications
› Technical Challenges
› Blockchain Technologies

3
Imagine… I have some money.
How can I manage
my expense
properly?

Dennis

4
OK. I create my
ledger to record my
earnings and
spending.

Dennis

5
Dennis’ ledger

Salary: $10000 (28 Feb 2018)


Breakfast: $50 (3 Mar 2018)
Movie: $200 (4 Mar 2018)
Online game items: $100 (5 Mar 2018)
Book: $300 (6 Mar 2018)

6
Today…

Please lend me $1000.

Dennis You
7
Dennis’ ledger

Salary: $10000 (28 Feb 2018)


Breakfast: $50 (3 Mar 2018)
Movie: $200 (4 Mar 2018)
Online game items: $100 (5 Mar 2018)
Book: $300 (6 Mar 2018)
Lend to “You”: $1000 (8 Mar 2018)

8
Please repay $1000 to me
by this month. I have
recorded it to my ledger.

OK! Please remind me.

Dennis You
9
At the end of this month…

Please repay $3000 to me.

What? Should it be $1000?


Let me see your ledger.
Dennis You
10
At the end of this month…

No. My ledger says it is


$3000. You see.
…#@$

Dennis You
11
Dennis’ ledger

Salary: $10000 (28 Feb 2018)


Breakfast: $50 (3 Mar 2018)
Movie: $200 (4 Mar 2018)
Online game items: $100 (5 Mar 2018)
Book: $300 (6 Mar 2018)
Lend to “You”: $3000 (8 Mar 2018)

12
The Ultimate Problem in Information Security

Source: https://www.tcpvid.com/establish-know-like-trust/

13
Security Requirements
› Integrity
– It includes both the correctness and the trustworthiness of the
data
› Availability
– The ability to use the information or resource desired
› Others?
– The C.I.A. model?

14
There are many transactions

Dennis’ ledger

Salary: $10000 (28 Feb 2018)


Breakfast: $50 (3 Mar 2018)
Movie: $200 (4 Mar 2018)
Online game items: $100 (5
Mar 2018)
Book: $300 (6 Mar 2018)

Who should
Lend to “You”: $3000 (8 Mar
2018)

maintain the
ledger?

15
Proposed Solution

Maintain a public
ledger to record all
transactions. How?

16
Public Ledger
Public ledger

Dennis owes
A $1000
B owes C
$1000
C owes A
$400
D owes B
$123

17
Blockchain
› Originally proposed by “Satoshi Nakamoto” in 2008
– Paper: “Bitcoin: A Peer-to-Peer Electronic Cash System”
– Open sourced in Jan 2009
› Used extensively in cryptocurrency like Bitcoin
› But the core concepts can be extended to applications in
which there are numerous transactions
– Receive cash in payment of an invoice owed by a customer
– Submit tax return to the government
– Sell electricity back to utility company

18
Blockchain – A high-level view
› A chain of blocks
– Essentially a data structure in computer science
› Linked List?
› Block
– Contain information that are to be recorded in the ledger
– E.g., Who are involved? What did they do? What information are
involved?
› Chain
– The blocks are “linked” or “tied” together to indicate the
relationship of the blocks
– The whole chain forms the ledger

19
A block is tied to
previous block
Blockchain – A high level view

Block 1 Block 2 Block 3 Block 4

Each block
contains data

20
Blockchain – A more in-depth view

Block 1 Block 2 Block 3 Block 4

Block 1 Block 2 Block 3

Each block contains a


“fingerprint” of the
previous block. This
ensures integrity. 21
Block Fingerprint
› The “fingerprint” is a hash value of the previous block
› The hash value is generated by hash functions
› Hash functions
– condenses arbitrary message (the block information) to a fixed
size (e.g., 160, 256, 512 bits)
– produces a fingerprint of the message
– assumed to be public

22
Requirements for Hash Functions
1. It can be applied to any sized message M
2. It produces fixed-length output h
3. It is easy to compute h = H(M) for any message M
4. Given h is infeasible to find x s.t. H(x) = h
– one-way property
5. Given x, it is infeasible to find y s.t. H(y) = H(x)
– weak collision resistance
6. It is infeasible to find any x, y s.t. H(y) = H(x)
– strong collision resistance
Practical Implementations of Hash Functions
› Secure Hash Algorithm (SHA-1)
– 160-bit output

24
Generating a SHA-1 hash value
› https://support.microsoft.com/en-us/help/841290

25
Blockchain – A more in-depth view

Block 4
Block 2 Block 3
Block 1 (Tx5, Tx6,
(Tx2, Tx3) (Tx4)
(Tx1) Tx7)
6653a7d4 2fe398f1e 96498cdc
1a5af825e bced1660 5a5ebd62
4b08e63e 87362626 5b6c13c2
5b234629 241b95efe 3c8bb20fc
ce294be aab407 cd96583

Each block contains a hash of the previous


block. This ensures integrity.

Note: Tx - Transaction 26
What if someone tries to modify an existing
record?

Block 4
Block 2 Block 3
Block 1 (Tx5, Tx6,
(Tx2’, Tx3) (Tx4)
(Tx1) Tx7)
6653a7d4 2fe398f1e 96498cdc
1a5af825e bced1660 5a5ebd62
4b08e63e 87362626 5b6c13c2
5b234629 241b95efe 3c8bb20fc
ce294be aab407 cd96583

627907f4dca1446096b9f3c078cc5ef2ffbb3092
The hash stored in Block 3 does not match with that of
block 2 and thus the modification is detected.

27
What if someone tries to modify an existing
record?
› The attacker has to compute the subsequent blocks’
hashes, starting from Block 2.
› To increase the difficulty of forging the blocks, the hash
begins with a number of zero bits.
– The average work required is exponential in the number of zero
bits required and can be verified by executing a single hash.
› E.g., 0000000000a1446096b9f3c078cc5ef2ffbb3092
– If a majority of CPU power is controlled by honest participates of
the chain, the honest chain will grow much faster than the forged
chain.

28
Blockchain: Distributed
Node

Node

Node
Node

Each node stores a


copy of the
blockchain

29
Nonce
› Since the data in a block is fixed, a Nonce (number) is
included in a block to make sure the output hash satisfies
the leading zero(s) requirement.
– Called “mining” in cryptocurrency
› Choose the Nonce randomly or increment the previous
Nonce by 1 and hash the block again.

30
How to maintain a consistent view?

Block 4
Block 2 Block 3
Block 1 (Tx5, Tx6,
(Tx2, Tx3) (Tx4)
(Tx1) Tx7)
6653a7d4 2fe398f1e 96498cdc
1a5af825e bced1660 5a5ebd62
4b08e63e 87362626 5b6c13c2
5b234629 241b95efe 3c8bb20fc
ce294be aab407 cd96583

Block 2
Block 1 Longest chain rule:
(Tx2’, Tx3)
(Tx1) This is the “real” blockchain.
627907f4
dca14460
96b9f3c07
8cc5ef2ffb
b3092 31
Blockchain – Security Revisited
› Recall the ledger example, we require:
› Integrity
– Malicious changes to the ledger is not possible
 Blockchain makes sure the blocks are related to each other by
using cryptographic hash functions
› Availability
– All nodes share the same copy of the ledger
 Blockchain allows nodes to have a copy of it, and examine and
verify the data stored in the chain.

32
Blockchain Applications – Cryptocurrency
› Bitcoin
› First decentralized cryptocurrency
– Peer-to-peer, transactions take place between users directly
– Transactions are verified by network nodes and recorded in a
public ledger
› Original application of Blockchain in “Satoshi Nakamoto”
‘s paper

33
There are over 1000 cryptocurrencies now...

34
Sources: https://coinmarketcap.com/all/views/all/
Blockchain Applications – DLT in Banks
› Project Ubin: Central Bank Digital Money using Distributed
Ledger Technology
› Singapore Monetary Authority (MAS) develops a
dedicated blockchain trading platform with the goal of
building a financial blockchain ecosystem on its platform
› The platform connects multiple banks and MAS to
achieve "cross-bank, cross-industry and cross-border"
transactions
› Details: http://www.mas.gov.sg/Singapore-Financial-
Centre/Smart-Financial-Centre/Project-Ubin.aspx
Other Applications
Application Property Problems Solved
Insurance Claim Untampered global history Multiple version of data,
Double claim
Trade Finance Data Transparency Risk due to lack of information
about customer

Automated compliance System Self-Management Lack of trust to execute contract

Self-sovereign identity Centralized control

Clearing and settlement No trusted party High transaction cost


Technical Challenges
› Efficiency
– Bitcoin can only handle 7 transactions/second
› https://blockchain.info/charts/transactions-per-second
– Hyperledger Fabric 1.0 can handle 1000 transactions/second
– VISA – 2000 transactions/second with a peak capacity of 56,
000 transactions/second
– Alibaba’s peak capability is 325,000 transactions/second
› Limited size
– Blockchain is NOT a database replacement (yet)
› Privacy
Privacy Issues
› The entire sequence of transactions is recorded on the
Blockchain
› Sender Identity (address, or pseudonym)
› Receiver Identity (address, or pseudonym)
› Transaction Amount
› Unlinkability
Blockchain Technologies – UTXO
› Bitcoin uses the UTXO model
› Stands for Unspent Transaction Output
› Only unspent outputs can be used as inputs to a
transaction.
– All the outputs form the current state of all information in the
universe
› When a transaction takes place, inputs are deleted and
outputs are created as new UTXOs that may then be
consumed in future transactions.

39
UTXO
› In the Bitcoin network,
› A UTXO is the amount that is transferred to a Bitcoin address
during a transaction.
› Received amounts (UTXOs) are used individually during a
transaction and new outputs are created
– one for the receiver and,
– if applicable, one for the amount that is left over (change output).
› The amount sent to the recipient becomes a new UTXO in the
recipient’s address while the change output becomes a new
UTXO in the sender’s address that may be used in a future
transaction.

40
UTXO
› Example

Block Input Output Amount Signature

18  PKAlice 12.5 N/A

19  PKBob 12.5 N/A

20  PKTom 12.5 N/A

20 18 PKBob 10
Alice
20 18 PKAlice 2.5

41
Blockchain Technologies – Merkle Tree
› A Merkle tree is a hash-based data structure
› It is a tree structure in which each leaf node is a hash of
data, and each non-leaf node is a hash of its children.

42
Source: https://brilliant.org/wiki/merkle-tree/
Blockchain Technologies – Merkle Tree
› Spent transaction should be removed to save disk space
› But still we need the transaction data for future
verifications
› Thanks to the one-way and weak collision resistant
properties of hash functions, we can store the hash of the
transaction data only
› Refer to the example in the next slide

43
44
Blockchain Technologies – Smart Contract
› a.k.a. Distributed Applications
(DAPP)
› Coined by Nick Szabo
› Code, but not document!
› Computer code is like a contract
if money received == $8
&& the button pressed is "Diet Coke"
then release Diet_Coke

45
Smart Contract – Example

46
Smart Contract
› If blockchains give us distributed trustworthy storage,
then smart contracts give us distributed trustworthy
calculations
› The code stored and synchronized in blockchain, which is
triggered by user initialized special transaction, and
– executed concurrently by consensus nodes

47
Key Players
› Open-source community
– Ethereum
› Oldest open source public blockchain started in 2013
– Hyperledger
› Hosted by the Linux foundation since 2016
› Members include IBM, Intel
– Corda
› Released since end of 2016
› Developed by R3, an enterprise software firm working with over 100 banks,
financial institutions, regulators, trade associations, professional services
firms and technology companies
– and more: https://medium.com/blockchain-blog/17-
blockchain-platforms-a-brief-introduction-e07273185a0b
Coming up next week
› Introduction to Corda
› Experiencing the Programming Environment in Corda
› Experience the IOU (I Owe yoU) case in Corda

49
Pre-reading
› Corda Introduction
– https://www.corda.net/wp-content/uploads/2017/10/Corda-
Solution-Guide.pdf
› Intro white paper
– https://docs.corda.net/_static/corda-introductory-
whitepaper.pdf
› Technical white paper
– https://docs.corda.net/_static/corda-technical-whitepaper.pdf
› IDE Installation and setup
– https://docs.corda.net/getting-set-up.html

50

Vous aimerez peut-être aussi