Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Breathless Tour of Blockchain

A Breathless Tour of Blockchain

A short presentation introducing the key ideas behind practical blockchain technology, used to introduce a session on blockchain at the SPA2017 conference.

6facddda8e4536c0b0bfbdaf45e50675?s=128

Eoin Woods

June 28, 2017
Tweet

Transcript

  1. A Breathless Tour of Blockchain Eoin Woods Nick Rozanski Endava

    ICBC Standard 1 licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
  2. Agenda • What is Blockchain? • Blockchain as an Architectural

    Element • Applications for Blockchain • Programming the Blockchain • Summary 2
  3. What is Blockchain? 3

  4. What is Blockchain? • The enabling technology of Bitcoin •

    A distributed database without a controlling authority • An auditable database with provable lineage • A way to collaborate with principals you do not trust • Trust and storage mechanism for cryptocurrencies • A possible architectural component for highly distributed and reliable Internet-scale systems 4
  5. What is Blockchain? Some Terms cryptocurrency implemented using a blockchain

    cryptographic Implementation of a distributed ledger Distributed Ledger fully replicated append- only shared data store which achieves trust without a central authority Smart Contract code stored in the ledger executed when preconditions met to manipulate ledger state 6
  6. What is Blockchain? Bitcoin network example Miners Bob Alice 7

  7. 8 Blockchain Operation Banks seek the key to blockchain -

    Financial Times
  8. What is Blockchain? Blockchain structure Transaction 1 Transaction 2 Transaction

    3 Block Hash Prev Block Hash Transaction 4 Transaction 5 Transaction 6 Block Hash Prev Block Hash Transaction 7 Transaction 8 Transaction 9 Block Hash Prev Block Hash Transaction 10 • Public keys used to identify participants • Bitcoin addresses identify participants in a transaction (derived from PK) • Cryptographic hashes used to ensure integrity 9
  9. What is Blockchain? Consensus Q. How do we know the

    information on the chain is correct? A. Because everyone agrees – this is “consensus” Blockchains use different types but “proof of work” is common • To create (“mine”) a block you need to solve a hard problem • If you don’t solve the problem then peers will reject your block • Thus forging the blockchain would require a huge amount of work to get your fraudulent blocks accepted (“impossible” without 51% of capacity) Other common models are “proof of stake” and “proof of membership” 10
  10. What is Blockchain? What blockchains exist? A lot of blockchain

    implementations exist. A small sample of them are: Bitcoin 2009 Cryptocurrency Litecoin 2011 Cryptocurrency Ripple 2012 Blockchain payment and settlement system Chain 2014 Enterprise blockchain Ethereum 2015 Blockchain dapp platform Hyperledger 2015 Linux Foundation open source blockchain projects R3 Corda 2016 Distributed ledger for the financial industry Multichain 2017 Enterprise blockchain 11
  11. Cryptocurrencies 7 cryptocurrencies have a market cap of > $1B!

    Bitcoin market cap is $47B. source: coinmarketcap.com 12
  12. What is Blockchain being Used For? Trade Settlement and FX

    Transactions digital ledger that tracks and protects valuable assets verifiable supply chains post-trade processing Keybase Identity management verified data Georgia government records supply chain efficiency 13
  13. Blockchain in Finance Huge interest from institutions, utilities and regulators

    14
  14. Exercise: Browse a blockchain blockchain.info Most public blockchains have a

    range of associated web based “explorers” • For Bitcoin we’ll use blockchain.info • For Ethereum we’ll use etherscan.io etherscan.io 15 github.com/eoinwoods/spacoin
  15. Exercise: Explore a blockchain 5 minute exercise to look at

    blockchain content • The WannaCry ransomware attackers have 3 bitcoin wallets: • 13AM4VW2dhxYgXeQepoHkHSQuy6NgaEb94 • 115p7UMMngoj1pMvkpHijcRdfJNXj6LrLn • 12t9YDPgwueZ9NyMgw519p7AA8isjr6SMw • Use blockchain.info to find out how much they have collected in ransom so far • Hint: there are 10-8 satoshis in a bitcoin and blockchain.info returns most values in satoshis, so multiply by 0.00000001 to get BTC) 16
  16. Blockchain as an Architectural Element 17

  17. Characteristics of a Blockchain Ledger • Distributed, replicated database •

    Distribution via a p2p model (no master) • Consensus model used to ensure integrity • Append only immutable store • Highly fault tolerant • Eventually consistent 18
  18. Adding Smart Contracts • Smart contracts are code which is

    stored on a blockchain and executed by the blockchain virtual machine • Smart contract languages vary from very primitive (Bitcoin) to Turing- complete languages (Go on IBM Hyperledger, Solidity on Ethereum) • Programming and execution models vary by platform • We’re going to use Ethereum Solidity as our example in this session 19
  19. Example: Ethereum Solidity Smart Contract contract Coin { // The

    keyword "public" makes those variables readable from outside. address public minter; mapping (address => uint) public balances; // Events allow light clients to react on changes efficiently. event Sent(address from, address to, uint amount); // This is the constructor whose code is run only when the contract is created. function Coin() { minter = msg.sender; } function mint(address receiver, uint amount) { if (msg.sender != minter) return; balances[receiver] += amount; } function send(address receiver, uint amount) { if (balances[msg.sender] < amount) return; balances[msg.sender] -= amount; balances[receiver] += amount; Sent(msg.sender, receiver, amount); } } 20 We’ll get to the details a little later …
  20. Quality Properties of a Distributed Ledger Positive Qualities • Immutability

    once written • Security (integrity, non- repudiation, availability) • High fault-tolerance • No single control or trust point • Embedded immutable logic • Dynamic, evolving Negative Qualities • (very) eventual consistency • computationally expensive (generally) • Limited query model • Lack of privacy • lack of throughput scalability (generally – 10s txn/sec) • Lacking maturity 21
  21. Aside: Storing Data • Blockchains don’t necessarily store large amounts

    of data well • Some (Bitcoin) optimised for many small transactions • Solution is to store large data items in immutable storage and reference from blockchain • IPFS and Swarm best known 22
  22. Integrating Blockchain Blockchain Application (Dapp) Conventional Application Blockchain (e.g. Ethereum)

    Immutable Storage (e.g. Swarm, IPFS) object references queries, transactions, smart contract invocations 23
  23. Exercise: Applying Blockchain • What could you use blockchain for?

    • Could be at work or an idea to change the world! • What problems would it solve or introduce? Recap • distributed, highly reliable, auditable, immutable database, not requiring trust between participants • smart contracts can embed computation in it • but slow, eventually consistent, limited queries 24
  24. Programming Blockchain 25

  25. Smart Contracts • The “programming” bit of blockchain technology •

    Code that is held in the blockchain and executed by the runtime environment when certain conditions become true (e.g. a transaction occurs) • Any participant can add a smart contract to a blockchain (for a fee) • A smart contract usually mutates the state of the blockchain (e.g. by adding another transaction to it) • Transforms blockchain from a passive database to a dynamic system • A bit like triggers and stored procedures in RDBMS 26
  26. Bitcoin “Script” • Very simple “FORTH-like” virtual machine • Constrained

    programming model of “locking” and ”unlocking” scripts • Locking script (“scriptPubKey”) defines constraints to execute the transaction • Unlocking script (“scriptSig”) satisfies the constraints to allow execution • Small number of “op codes” for use in scripts. Example Lock: OP_DUP OP_HASH160 <payee pub key hash> OP_EQUAL OP_CHECKSIG Unlock: <payee signature> <payee pub key> 27
  27. Bitcoin “Script” <payee signature> <payee pub key> OP_DUP OP_HASH160 <payee

    pub key hash> OP_EQUAL OP_CHECKSIG Stack based execution: <payee pub key> <payee signature> <payee pub key> <payee pub key> <payee signature> <payee pub key hash> <payee pub key> <payee signature> <payee pub key hash> <payee pub key hash> <payee pub key> <payee signature> <payee pub key> <payee signature> (Push 2 arguments) OP_DUP OP_HASH160 (Push argument) OP_EQUAL (= T) OP_CHECKSIG (= T) 28
  28. Ethereum Solidity • Most popular contract language for Ethereum •

    Syntax quite similar to JavaScript (but statically typed language) • Turing complete, object-oriented language • Inheritance and user-defined types • Compiles to bytecode that runs on the EVM • Emerging development eco-system of frameworks and tools 29
  29. Ethereum Solidity contract Coin { // The keyword "public" makes

    those variables readable from outside. address public minter; mapping (address => uint) public balances; // Events allow light clients to react on changes efficiently. event Sent(address from, address to, uint amount); // This is the constructor whose code is run only when the contract is created. function Coin() { minter = msg.sender; } function mint(address receiver, uint amount) { if (msg.sender != minter) return; balances[receiver] += amount; } function send(address receiver, uint amount) { if (balances[msg.sender] < amount) return; balances[msg.sender] -= amount; balances[receiver] += amount; Sent(msg.sender, receiver, amount); } } Contract Typed state Event for log (and callback) Functions to operate on state 30
  30. Solidity & Ethereum Development Ecosystem Geth Eth Pyethapp Mist Nodes

    & Browsers Web3.js Web3J Netereum API Libraries Ethereum Studio Solidity Browser Development Tools 31
  31. Demo: Programming Blockchain • Solidity code and the “Sol” compiler

    • Writing and unit testing a simple Solidity contract using “Truffle” • Deploying a compiled contract to a local test network 32
  32. Summary 33

  33. Key Concepts Distributed Ledgers Blockchains Smart Contracts 34

  34. What is Blockchain? • A novel type of distributed database

    • Append-only, auditable, fault tolerant, secure by design • Slow and high-latency by accident • Many blockchains (and distributed ledgers) can host “smart contract” code to provide secure computations 35
  35. Some Applications • Value transfers – securities clearing, payments •

    Verifiable records – property registers, supply chains, loyalty points • Identity – verifiable personal or corporate identity, passports • Verifiable Storage – immutable, secure storage and sharing • Decentralised Notary – prove existence of digital asset at time • Currencies – Bitcoin, Ether, Litecoin and friends 36
  36. To Find Out more • Bitcoin – bitcoin.org • Ethereum

    – ethereum.org • Solidity - solidity.readthedocs.io • Truffle - truffleframework.com • Embark - github.com/iurimatias/embark-framework • Dapp - dapp.readthedocs.io • IPFS – ipfs.io • Swarm - swarm-gateways.net • News – coindesk.com, cryptoinsider.com (and many others) 37
  37. Eoin Woods Endava eoin.woods@endava.com Thank You Nick Rozanski ICBC Standard

    nick@rozanski.org 38