Blockchains, how do they work?

#5 Wrocław Blockchain Meetup

Tomasz Drwięga,

Parity Technologies

Introduction for developers

  • What is blockchain / blockchain technology?
  • Decentralization?
  • Consensus?
  • Incentives?
  • What is Bitcoin?
  • What is Ethereum?
  • Glossary

Client:
I need a global real estate registry!

You (developer):
What are the requirements?

Possible Actions:

  • transfer(from, to, property)
  • properties(who)

Example Interaction:

User X transfers property 5  to User Y

transfer(X, Y, 5)

 

Database

API

 

User X

User Y

User Z

 

Admin

Questions?

  • Who is allowed to transfer properties?
    Users between themselves.
    (they will need some credentials)
     
  • Can a property be owned by more than one user?
    Nope, a property has only one owner.
     
  • How to add new real estate?
    Not possible, hardcoded list at the start (genesis).


Database

API

 

User X

User Y

User Z

Authenticate

Enforce Rules

Persist State

Trusted Zone

The Platform

  • Authenticates the user
    (Do credentials match?)
  • Checks the rules
    (Does he own a property)
  • Does the transfer (atomicly)
  • Persists the new state
    (it can be later queried)

User

  • Sends a transfer requests
  • Adds credentials
  • "Trusts" The Platform to perform requested action

Client:
But I don't want to pay for any servers.

How can we build a platform without servers?

It needs to be distributed.


Database

API

 

User X

User Y

User Z

Authenticate

Enforce Rules

Persist State

Trusted Zone

Instead of this:

We need that:

User X

User Y

User Z

How to cover

The Platform responsibilities in a distributed system? 

  • Authenticate the user
  • Check the rules
  • Do the transfer
  • Persist the new state

A State Machine

State + Transitions

A State Machine

State + Transition

properties(A) = [5]
properties(B) = []

properties(A) = []
properties(B) = [5]

transfer(A, B, 5)
properties(A) = [5,7]
properties(B) = []
properties(C) = []


properties(A) = []
properties(B) = [5]
properties(C) = [7]


Day 1

Day 2

Transition
(list of transactions)

  1. transfer(A, B, 5)
  2. transfer(A, C, 7)

+
Transfers

+
Transfers

+
Transfers

Distributed Ledger

How to participate?

You connect to some peers and ask them for the latest state.

What if they lie/cheat?

You can ask them to give you a list of all state transitions and verify it on your own.

+
Transfers

+
Transfers

+
Transfers

State 1

State 2

State 3

=

=

State 1 + Transfers = State 2

State 2 + Transfers = State 3

State 3 + Transfers = ...

 

But sending all states over the network is not feasible...

One-way functions

e.g. Crypto... Hash Functions

      DATA
)
f(
= hash

Easy to computer `f`, but impossible* to revert.

Can be used as a checksum.

0x123456789
)
sha256(
= 0x6c4...3e6
  • hash(Genesis)
  • Transfers
  • hash(State 1)
  • hash(State 1)
  • Transfers
  • hash(State 2)
  • hash(State 2)
  • Transfers
  • hash(State 3)

Blockchain

What about

the transfers?

How can you verify that they were intended by owners?

Public-key cryptography

Authentication

Alice's Public Key

Alice's Private Key

Bob's Public Key

Bob's Private Key

Sign with Private

verify with Public

Alice's Private Key

Message

Signature

Sign with Private

verify with Public

Alice's Public Key

Message

Signature

Alice sent it!

That's a blockchain!

 ​transfer(A, B, 5)
 Alice's Sig
​ transfer(B, C, 5)
 Bob's Sig
 ​transfer(B, A, 5)
 Bob's Sig

Signed transactions packed together in blocks,

linked to each other to encode time-relations.

 hash(Genesis) = Parent Hash
 hash(Block 1) = Block Hash
 hash(Block 1) = Parent Hash
 hash(Block 2) = Block Hash
 hash(State 1)
 hash(State 2)
 hash(Block 2) = Parent Hash
 hash(State 2)
 hash(Block 3) = Block Hash
 Timestamp = 2017-05-18 13:45
 Timestamp = 2017-05-18 13:45
 Timestamp= 2017-05-18 13:45

Who creates new blocks?

If everyone can create them how do we know which one encodes "the truth"?

Consensus Mechanisms

  • Proof of Authority (centralized):
    • Only "the Choosen Ones" can submit new blocks
    • Alice submits even blocks, Bob submits odd ones
       
  • Proof of Work (decentralized):
    • The first one to solve a difficult math puzzle can submit a new block

Proof Of Work

We need a puzzle that is:

1. Trivial to validate

2. Difficult to compute

 ​transfer(B, A, 5)
 Bob's Sig
 hash(Block 1) = Parent Hash
 hash(Block 2) = Block Hash
 hash(State 2)
 Timestamp = 2017-05-18 13:45
 Puzzle Solution

Hash Functions

      DATA
)
f(
= hash
BlockHash
)
sha256(
= 0x000...
Nonce

Puzzle: Find a Nonce that hashed together with current block hash gives a hash starting with X zeros

Canonical Chain

​transfer(A, B, 5)
Alice's Sig
​transfer(B, C, 5)
Bob's Sig
​transfer(B, A, 5)
Bob's Sig
​transfer(B, C, 5)
Bob's Sig

Longest in some metric

Consensus ensures the blocks are produced in expected rate via

Difficulty Adjustment / Protocol Delays

Ok, so why would I ever waste my computing power to submit new blocks?

It's incentivized - You will earn money
(and it's called mining)

Summary

  • State + Transition = New State
  • Block = (State, Transactions)
  • Decentralized Consensus:
    • Who can submit a new block?
  • Nodes are broadcasting signed transactions
  • Miners are producing and broadcasting new blocks 
  • Nodes are processing new blocks and performing state transition

What is Bitcoin?

Bitcoin is the first public blockchain ever.

Block Time 10 minutes
Consensus Proof of Work - hashcash
State Account Balances of BTC / UTXO*
Transactions Value Transfers*
Launched 2009
Block Reward 12BTC (halving) ~ 21M total coins

What is Ethereum?

Ethereum is the World Computer

Block Time 14 seconds
Consensus Proof of Work - ethash*
State Arbitrary
Transactions Turing-complete / programmable
Launched 2015
Block Reward 5ETH (+uncles) ~ Unlimited coins

Why do we care about blockchains?

Trustless transactions between multiple parties.

Transactions without trust of a third party intermediary!

I'm most probably out of time 

So let's jump to glossary

List of important words

  • Genesis Block
  • Blockchain
  • Protocol
  • Consensus
  • Incentives
  • Miner
  • Hashing Power
  • Hard/Soft Fork
  • Canonical Chain
  • Chain re-org

Any questions?

  • Decentralization
  • Distributed Ledger
  • Bitcoin
  • UTXO
  • Ethereum / EVM
  • Smart Contracts
  • Altcoins
  • Tokens
  • Fiat currency

References

  • Alex Fisher - The web and "trustless"­ communications
    https://www.youtube.com/watch?v=7WyIms8YDVo

  • Dan Finlay - Intro to how ethereum works
    https://www.youtube.com/watch?v=-SMliFtoPn8

Intro to Ethereum

By Tomasz Drwięga

Intro to Ethereum

  • 746