Skip to content

Latest commit

 

History

History
1060 lines (642 loc) · 25.2 KB

File metadata and controls

1060 lines (642 loc) · 25.2 KB

Blockchain, DApps, and Blockstack

Basic concepts to get started



Wifi Info

Network: cubantech

Password: meet-ups


Outline

  • Replicated state machines (a.k.a RSM)
  • Infrastructure, management and admin tools
  • Relation betwen RSM and Blockchain
  • Execution rules and consensus
  • General Theory of DApps
  • Blockstack overview
  • Blockchain-independent DApp RSM with VirtualChain

Notes about Bitcoin P2P network in-between


State Machines - States


State Machines - Inputs


State Machines - Transition


The scalability problem

--

Stats of the Bitcoin blockchain


Distributed services as state machines

  • Fault tolerance beyond single-node processors
  • Replicas of a single server executed on separate processors
  • Protocols for client interactions with replicas
  • Physical and electrical isolation for independent server failures
  • Let's assume deterministic state machine
    • ... even if Turing complete is possible

The State Machine Approach

  • Deploy replicas of the software
  • Receive client requests (i.e. inputs)
  • Order the inputs
  • Execute SM transition over and over
  • Monitor replicas for differences in State or Output

The State Machine Approach

Deploy software to multiple nodes

docker.cuban.tech

--

State of CM - Q1 2017


The State Machine Approach

  • Deploy replicas of the software
  • Receive client requests (i.e. inputs)
  • Order the inputs
  • Execute SM transition over and over
  • Monitor replicas for differences in State or Output

The State Machine Approach

Receive client requests
  • Multiple solutions
  • e.g. Bitcoin transactions

--

Bitcoin - Anatomy of transactions

Important meta-data (except coinbase transactions)

  • Transaction (global) ID
  • Version number (protocol evolution)
  • Locktime
    • Earliest time TX can be added to the block chain
    • Time-locked transactions only valid in the future
    • Cancellations

--

Bitcoin - Anatomy of transactions

Inputs and outputs

  • Output(s) : Implicit array index
    • Amount (satoshis)
    • Pubkey script ( Unlock to spend )
  • Input(s)
    • Spent output (Transaction ID + Output index)
    • Sequence number (related to locktime)
    • Signature script (params to unlock Pubkey script)

Bitcoin is a public distributed ledger.

--

Bitcoin - Sample transaction

blocktrail.com

--

Bitcoin - Sending transactions

Pay-To-Public-Key-Hash (P2PKH) setup

  • ECDSA secp256k1 (elliptic) curve
    • Deterministic public key (hash) generation

--

Bitcoin - Sending transactions

Pay-To-Script-Hash (P2SH) setup

--

Bitcoin - Sending transactions

Finalize TX

  • Sender creates UTXO with PubKey script
    • ... using the public key hash of the receiver
  • Sender broadcasts transaction (P2P network)
  • Miners add it to a block (... more details later ...)
  • Wallet : UTXO amount as spendable balance

--

Bitcoin - Spending P2PKH outputs

  • Lookup transaction ID and index for UTXO
  • Sender creates TX input and also add:
    • Sequence number
    • Signature & PubKey (script params)

--

Bitcoin - Spending P2SH outputs

  • Lookup transaction ID and index for UTXO
  • Sender creates TX input and also add:
    • Sequence number
    • Signature & PubKey (script params)

--

Bitcoin - Spending outputs

Last steps
  • Sender prepares UTXO for recipient (as before)
  • Sender broadcasts transaction (P2P network)
  • Miners add it to a block
    • Script validation ! ( A-ha! )
  • Wallet : Update balance

--

Bitcoin - Standard P2PKH public script

Execution stack timeline


P2P network

A very peculiar monster

--

P2P network

Peer discovery - Bitcon seed DNS
;; QUESTION SECTION
;seed.bitcoin.sipa.be       IN  A

;; ANSWER SECTION
seed.bitcoin.sipa.be.   60  IN  A   192.0.2.113
seed.bitcoin.sipa.be.   60  IN  A   198.51.100.231
seed.bitcoin.sipa.be.   60  IN  A   203.0.113.183
  • Connect to port 8333 (mainnet) or 18333 (testnet)
  • Followed by addr messages announcing addresses of peers

--

P2P network

Connecting to peers
  • Send version message
    • local version number, block, and current time
  • Peer responds with its own version message
  • Send getaddr and receive addr of new peers (discovery)

--

P2P network

Transaction broadcasting
  • Send inv message to a peer.
  • Wait for getdata message
  • Send transaction data in tx message
  • Peer forwards transactions to other peers
  • Full nodes keep track of unconfirmed transactions in memory pool

... to be continued ...


The State Machine Approach

  • Deploy replicas of the software
  • Receive client requests (i.e. inputs)
  • Order the inputs
  • Execute SM transition over and over
  • Monitor replicas for differences in State or Output

The State Machine Approach

Ordering of inputs
  • Mutiple solutions
  • Blockchain ?
  • Bitcoin transactions !

--

Bitcoin - Transaction spending

Causal ordering : Chain of ownership


The State Machine Approach

  • Deploy replicas of the software
  • Receive client requests (i.e. inputs)
  • Order the inputs
  • Execute SM transition over and over
  • Monitor replicas for differences in State or Output

The State Machine Approach

Execute the state machine

  • Execute inputs in the chosen order on each replica

--

Bitcoin - Transaction propagation


Bitcoin blockchain

Design goals
  • Public ledger
    • Ordered and timestamped transactions
  • Storage distributed over Bitcoin full nodes
  • Protect against

--

Bitcoin blockchain

Overview

--

Bitcoin block header

  • Version : 4 bytes
  • Previous block header hash : 32 bytes
  • Merkle root hash : 32 bytes
  • Time : 4 bytes
  • nBits : 4 bytes
  • nonce : 4 bytes

--

Bitcoin Block 493387

blocktrail.com

--

Bitcoin Block 493387 - Transactions

Coinbase transaction comes first


Proofs

  • Metric
    • Prove legitimate interest, irreversibility
    • Make decisions about changes in a DApp
  • Modifying past blocks harder than adding new ones
  • Common examples
    • Proof of work (PoW)
    • Proof of stake (PoS)
    • Proof of space (PoSpace)
    • Proof of collaboration (PoC)
    • Proof of replication (PoR)
  • Can be used in parallel

--

Proof of work

  • Driver : Amount of computational work (CPU, GPU, NPU, ...) that contributed to the operation of the DApp.
  • Resource intense (power, cooling, ...)
  • The mechanism for establishing consensus through POW is commonly called mining.

Bitcoin uses that approach for its day-to-day operation.

--

Proof of stake

  • Driver : new coins according to number of coins (stake) you hold
  • May be abused by those who hold enough coins.
  • Usually combined with other proof

OmniLayer is based on the POS mechanism.

--

Proof of capacity

  • Driver : allocation of non-trivial amounts of memory or storage needed to solve a challenge (memory-hard functions).
  • Greener alternative to PoW

PoStorage is used in PermaCoin, SpaceMint, BurstCoin

--

Proof of collaboration

  • Collaboratively Validating Nodes (in short CVNs)
    • Decide what node creates next block
    • Approve CVN by digitally signing a piece of data containing winner's ID
    • With required signatures gather TX and create new block
  • No reward (new money) for block creation (small fee)
  • Power consumption is low (CVNs on a Raspberry3)

FairCoin (fork of Bitcoin 0.12) implements PoC since July 18th 2017


Merkle tree - Prunning transactions

Operating modes : SPV clients vs full node


P2P network (contd.)

Initial Block Download
  • First run : Node only contains block 0
  • Choose remote peer (a.k.a sync node)
  • Download from block 1 to current tip of sync node's best block chain
    • Blocks-first (up until version 0.9.3)
    • Headers-first (from 0.10.0 onwards)

Bitcoin mining

  • Add new blocks to the block chain
  • Make transation history hard to modify
  • Strategies
    • Solo mining
    • Pooled mining

Bitcoin mining - Solo mining

  • Miner generates new blocks on his own
  • Completely claims block reward and transaction fees
  • Large payments
  • Higher variance (longer time between them)

Bitcoin mining - Pooled mining

  • Group of miners pool resources with other miners
  • Find bocks more often at easier bits targets
  • Proceeds shared amongst miners
    • Correlated to relative hash power PoW
  • Small payments
  • Lower variance (i.e. shorter time between payments)

--

SlushPool

slushpool.com/home/

Minted coins : +1M BTC mined since Dec 2010. ZCASH since Apr 20th 2017

--

SlushPool

Hash rate

--

SlushPool

Hash rate distribution

--

Bitmain - AntMiner

bitmaintech.com

Minted coins : BTC

--

Bitmain - AntPool

bitmaintech.com

--

BTCC Pool

pool.btcc.com

Minted coins : BTC


Bitcoin mining hardware

Installed capacity - 2017/11/13
![](img/btc.hashrate.20171113.png)
  • 6.4 EHash/s , 80,704,290.84 PFLOPS
  • 10,000 metric tonnes of hardware. Enough material to build another Eiffel tower.

--

Bitcoin mining hardware - Energy

Application specific integrated circuits, a.k.a. ASICs

--

Energy consumption of Bitcoin PoW

... according to BitcoinEnergyConsumption.com

  • Projected to be comparable to Denmark's in 2020

P2P network (contd.)

Block broadcasting - Unsolicited Push
  • Miner includes mined block in new block message
  • Miner sends message to its full nodes peers

since version 0.12.0

--

P2P network

Block broadcasting - Standard Block Relay
  • Standard method
  • Miner sends inv message to all (SPV and full node) peers
    • Includes inventory referring to the block
  • BF peergetdata requesting the full block
    • Miner ⇒ block message
  • HF peergetheaders (few headers in best block chain)
    • Miner ⇒ headers message
  • SPV clientsgetdata requesting a Merkle block
    • Miner ⇒ merkleblock followed by some tx messages

since version 0.12.0

--

P2P network

Block broadcasting - Direct Headers Announcement
  • Used if peer signals with sendheaders during handshake
  • Miner sends headers message fror new block
  • HF peer ⇒ Partial validation and sends getdata
  • Miner ⇒ block or merkleblock

since version 0.12.0


The State Machine Approach

  • Deploy replicas of the software
  • Receive client requests (i.e. inputs)
  • Order the inputs
  • Execute SM transition over and over
  • Monitor replicas for differences in State or Output

The State Machine Approach

Sending outputs
  • Each replica generates output
    • Non faulty replicas will always produce same output
  • Faulty outputs filtered out
    • Consensus
  • Correct output sent back to client

--

Consensus


Bitcoin - Nakamoto consensus

Occasional vs Extended Forking

  • Simultaneous blocks mined, nodes choose winner
  • Peers prefer forks with stronger PoW
    • longest fork
    • highest block height : distance to block 0

--

Bitcoin - Nakamoto consensus

Soft fork

  • When ?
    • Quite often e.g. concurrent miners
    • Upgraded consensus rules reject formerly valid blocks
      • UASF flag day vs MASF hash rate majority signalling

--

Bitcoin - Nakamoto consensus

Soft fork resolution
  • Eliminate (stale and orphan) blocks in low PoW forks
  • Iterate over transactions in stale and orphan blocks
    • discard it if TX belongs in another block of highest PoW fork
    • move it back to TX mempool otherwise
      • to be included in a future block by this miner
      • (optionally?) broadcast to the P2P network

--

Bitcoin - Nakamoto consensus

Hard forks

  • When?
    • Extend blockchain to prevent third-party 51% attack
    • Upgraded consensus accept formerly rejected blocks
    • Network partition

--

Bitcoin - Corollaries of hard forks

  • Warning in getnetworkinfo and run -alertnotify command if set.
    • +6 blocks PoW than best valid chain
    • Repetition of block and TX with version numbers higher than expected consensus
  • Coinbase transaction may be spent only after 100 blocks
  • SPV clients may contact different full nodes
    • discard chains with weaker PoW

Bitcoin - Client balance

Wallet software : Add up UTXO to determine balance


Fault tolerance (in theory)

  • Tolerance for F random independent failures
    • memory errors, hard-drive crash, ...
    • Requires 2F + 1 replicas
  • Failed replica can stop without generating outputs
    • Only F + 1 replicas required
    • ... no existing systems achieve this limit
  • Byzantine failures
    • random, spurious faults ⇒ 2F + 1
    • malicious, intelligent attacks ⇒ 3F + 1

--

Bitcoin node

Minimum requirements
  • Desktop or laptop (Windows, Mac OS X, or Linux)
  • 125 GB of HDD space, 2 GB RAM
  • Broadband Internet with upload ≥ 400 Kbps (50 KB/s)
    • Unmetered connection, or high upload limits, respect upload limits
    • +100 GB IBD
    • ≈ 20 gigabytes download a month
    • +200 GB upload a month
  • +6 hours a day with full node running
  • +8 connections and active sync peers

--

Bitcoin node

Most ordinary folks should NOT be running a full node. We need full nodes that are always on, have more than 8 connections (if you have only 8 then you are part of the problem, not part of the solution), and have a high-bandwidth connection to the Internet.

Gavin Andresen, Bitcoin Foundation’s Chief Scientist, in Reddit post


General Theory of DApps


Definition of a DApp - Open source

  • It must operate autonomously
  • No entity controlling the majority of its tokens
  • Data and records in a public, decentralized block chain.

e.g. Bitcoin apps are open-source, no entity controls Bitcoin and its records are open and public.


Definition of a DApp - Generation of tokens

  • The purpose of a token is to allow access to the DApp application.
  • Must generate tokens according to a standard algorithm
    • Possibly distribute tokens at the beginning of operation
  • Tokens must be necessary for the use of the application
  • Contribution from users rewarded by payment in the application's tokens.

e.g. Bitcoin generates bitcoins (tokens) with a predetermined algorithm that cannot be changed. Tokens are necessary for Bitcoin to function. Bitcoin miners are rewarded with bitcoins for their contributions in securing the Bitcoin network.


Definition of a DApp - Consensus

  • Protocol may be adapted in response to
    • proposed improvements
    • market feedback
  • Changes decided by majority consensus of its users.

e.g. All changes to Bitcoin must be approved by a majority consensus of its users through the proof-of-work mechanism.


Classification of DApps - Type I

According to use of blockchain
  • They have their own block chain.

Bitcoin, Litecoin and other alt-coins


Classification of DApps - Type II

According to use of blockchain
  • Use the block chain of a type I decentralized application.
  • They are protocols
    • Tokens that are necessary for their function.

OmniLayer (formerly Master Protocol) and Blockstack are examples of type II decentralized application.

--

DApps type II

Bitcoin null data transactions
  • Embed additional data in DApp type I transactions
  • Bitcoin OP_RETURN code
    • Provably prune-able outputs
    • Bitcoin miners will have the option to prune those data

Blockstack is a type II DApp


Classification of DApps - Type III

According to use of blockchain
  • They use the protocol of a type II decentralized application.
  • They are protocols and have tokens that are necessary for their function.

Omni (formerly Mastercoin), and Blockstack apps are examples of type III decentralized applications.


Foundational steps of a DApp

  • Publication of whitepaper
  • Distribution of initial tokens
  • Delegation of ownership

Sections of the DApp whitepaper

  • Intentions and goals of the DApp
  • Plans for token distribution
  • Mechanism for establishing consensus
  • Oversight of the DApp
  • Management of developer bounties
  • Technical description of the DApp

Distributing tokens - Mining

  • Tokens are distributed to those who contribute most work to the operation of a DApp.

Taking Bitcoin as an example, bitcoins are distributed through a predetermined algorithm to the miners that verify transactions and maintain the Bitcoin block chain.


Distributing tokens - Fund raising

  • Tokens are distributed to those who fund the initial development of the DApp.

Taking the Master Protocol as an example, Mastercoins were initially distributed to those who sent bitcoins to a given address at the rate of 100 Mastercoins per bitcoin sent. The bitcoins collected were then used to fund the development of applications that promoted the development of the Master Protocol.


Distributing tokens - Development

  • Tokens are generated using a predefined mechanism and are only available for the development of the DApp.

In addition to its fund-raising mechanism, the Master Protocol used the collaboration mechanism to fund its future development. Some Mastercoins are distributed via a community-driven bounty system based on the PoS mechanism.


Blockstack


Why Blockstack ?

The Internet is +40 years old now

  • Critical services offline by attacks like DDoS on DNS servers
  • Implicit trust e.g. [TurkTrust CA issued false security certificates for Google](http: //cnet.co/2oArU6O)
  • Desktop to cloud creates SPoF e.g. [Yahoo! losing data for 500M people](http: //nyti.ms/2oAqn0G.)

--

Why Blockstack ?

Ryan Shea, Blockstack co-founder


What is Blockstack?

  • A New Internet for Decentralized Applications
  • Open source
  • Re-decentralize the Internet
  • Users own their data

--

Trust-to-trust design principle

Muneeb Ali, Blockstack CTO


Blockstack goals

  • Decentralized Naming & Discovery
    • Register and use human-readable names
    • Discover network resources without trusting any remote parties
  • Decentralized Storage
    • Store data without revealing it to any remote parties.
  • Comparable Performance

Blockstack - Key decisions

  • Survive Failures of Underlying Blockchains
  • Keep Complexity and Logic Outside of Blockchains
    • opposite to NameCoin, Ethereum, etc ...
  • Scalable Index for Global Data

Blockstack architecture


Blockstack layers

  • Virtual blockchain, on top of Bitcoin blockchain
  • Atlas, a peer-network
    • Global index for discovery information
  • Gaia, decentralized storage system

Users do not need to trust any data layer


Blockstack - Blockchain layer

DApp type II

--

Blockstack - Nameops transactions

--

Sample Blockstack null data transaction

NAME_REGISTRATION bluestack.id


Blockstack - Virtualchain layer

Why?
  • Fork*-consistent RSMs on existing blockchains
  • Fork detection & recovery
  • Cross-chain migration
    • Reasons for Blockstack to migrate from Namecoin to Bitcoin

--

Blockstack - Virtualchain layer

... according to Muneeb Ali, Blockstack CTO

--

Blockstack - Virtualchain

Filtering and ordering OP_RETURN TXs
![](img/bsk-virtual-blockchain.png)

Blockstack apps - Explorer and AppStore


Blockstack apps - iTunes clone


Blockstack apps - Afia


Blockstack apps - Casa


Wrapping Up