You are on page 1of 43

nt l e

Ge Introduction to Blockchains
Orfeas Stefanos Thyfronitis Litos
PhD in Cryptography and Blockchains
University of Edinburgh
11/10/2019

1
Outline

Why it works

Smart contracts

Types, ideas and the future

TM

2
Part I

Why it works, or a Bitcoin primer

3
What is a Blockchain?


distributed,

append-only,

transaction ledger

4
What is a Blockchain?

Created by Kirman
from the Noun Project

Created by Pablo Rozenberg


from the Noun Project

Created by Kirman Created by Pablo Rozenberg


from the Noun Project

rom the Noun Project

Created by Pablo Rozenberg


from the Noun Project

Created by Pablo Rozenberg


from the Noun Project

5
Transactions

Alice Bob
tx
1 BTC 1 BTC

6
Transactions

Input Output
Alice Bob
tx
1 BTC 1 BTC

7
Transaction Graph

8
Many inputs

9
Many outputs

10
Unspent Transaction Outputs (UTXO)

11
Bob has 2 BTC

Bob
1 BTC

Bob
1 BTC
12
Bob pays 1 BTC to Alice

Bob
1 BTC

Bob Bob Alice


1 BTC 1 BTC 1 BTC
13
New UTXO

Bob
1 BTC

Alice
1 BTC
14
Block


Contains

transactions

metadata

Has unique parent
15
Blockchain

16
Blockchain

History of all transactions


17
Blockchain

tip
18
Mining (a.k.a. writing history)


Only valid transactions?

Proof of Work? 19
Mining (a.k.a. writing history)


Only valid transactions! new tip

Proof of Work! 20
Hash function

ε 01

ab 10
bb 11
baa
n-bit
strings integers

21
Hash function
easy
One way: hard
ε 01

ab 10
bb 11
baa
n-bit
strings integers
Collision free: rare
22
Hash function
easy
One way: Bitcoin uses SHA256, e.g.:
hard
ε 01
SHA256( 598324 ) =
ab 10
bb 11
baa 0000000000000000000
d7819fc59c65ca6f3e8f73c
n-bit 6eeadf538aa874a31341fb
strings integers
Collision free: rare
23
Proof of work
def hasProofOfWork(block):
if hasManyLeadingZeroes(SHA256(block)):
return True
return False

Valid blocks need energy



can’t spam blocks 24
Forks

25
Forks

Protocol says:

Choose longest fork

If equal, choose random

26
Nice properties

if honest mining power > 50%,



Liveness: a new tx will enter the chain

Persistence: Old blocks won’t change

Garay, Kiayias, Leonardos. "The bitcoin backbone protocol: Analysis and


applications." Annual International Conference on the Theory and Applications of
Cryptographic Techniques. Springer, Berlin, Heidelberg, 2015. 27
Part II

Smart Contracts: Programmable money

28
Remember transactions?

Alice Bob
tx
1 coin 1 coin

29
Now add some code!

if (Alice gives 1 coin


Alice and Bob
block height > 10)
then
1 coin give Bob 1 coin 1 coin

30
Example 1: Flip a coin

Bob repeat no_operation


1 coin until
(Alice gives 1 coin
and winner
Bob gives 1 coin)

winner = 2 coins
random(Alice, Bob)
Alice give winner 2 coins
1 coin
31
Example 1: Flip a coin

Bob repeat no_operation


1 coin until
(Alice gives 1 coin
and winner
Bob gives 1 coin)

winner = 2 coins
random(Alice, Bob)
Alice give winner 2 coins
1 coin
Don’t use this contract in real life! 32
Example 2: King of the Hill

top = 0
king = null
while (true)
if (user gives x coins
and
x > top)
give king top coins
king = user
top = x

Don’t use this contract in real life! 33


Still too hard

A fast way to lose your (and others’)


Smart Contracts: Programmable money

Very easy to make mistakes

TheDAO

Parity wallet

Smart contract languages not (yet) safe
34
Part III
V

Types of blockchains, applications and the future

V Xchain
V TM

35
Cryptokitties

Cute kitties that live on Ethereum!

36
MakerDao

Decentralised stablecoin

On Ethereum

1 Dai = 1 USD

Overcollateralised by floating “Maker”

37
Types of blockchains


Permissioned vs Permissionless V


Proof of Work vs Proof of Stake V


Private vs Transparent TM
V

38
Scalability issue

: 7 txs/sec
: 20,000 txs/sec
Problem: too much redundancy

39
Candidate Solution

Payment Channels! (e.g. Lightning, )



1 tx on-chain to open channel

Unlimited off-chain txs

1 tx on-chain to close channel

40
Crosschain transactions

Move coins to another chain


E.g. use bitcoins in Ethereum contracts

41
Interconnected blockchains

Specialised blockchains
Separation of duties
Related: Sharding

42
Questions?
Credits:

Blockchain by Pablo Rozenberg from the Noun Project

43

You might also like