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

A Developers View of Blockchain

A Developers View of Blockchain

This was one of the talks I gave in Finland.

Martin Beeby

June 12, 2018
Tweet

More Decks by Martin Beeby

Other Decks in Technology

Transcript

  1. Martin Beeby @thebeebs Transferring Money between them is now harder

    Easy to lose track of who owes what Lets build a database MONEY IS A PAIN
  2. Martin Beeby @thebeebs Martin Controls it Each cake sale is

    a transaction The seller tells martin about the transaction. He records it CREATE A DATABASE
  3. Martin Beeby @thebeebs Hard to keep in sync Hard to

    agree Hard to reach consensus PEOPLE COULD STILL DEFRAUD
  4. Martin Beeby @thebeebs ANTTON DONALD MARTIN KIM PUBLIC AND PRIVATES

    Private Key Private Key Private Key Private Key Address 1 Address 2 Address 3 Address 6 Address 5
  5. Martin Beeby @thebeebs Sender Amount Receiver Signed Address 1 5

    Address 2 110101010 Address 2 4 Address 3 010101010 Address 3 3 Address 1 010011010 TRANSACTIONS
  6. Martin Beeby @thebeebs Listen for transactions and validates them Order

    transactions into a block Creates and hashes blocks solving a maths problem related MINERS LISTEN FOR TRANSACTIONS Sender Receiver Signed Address 1 5 Address 2 110101010 Address 2 4 Address 3 010101010 Address 3 3 Address 1 010011010
  7. Martin Beeby @thebeebs Solve a complex problem involving the hashing

    of the block Would be very expensive to try and present incorrect blocks Miners on bitcoin spend huge sums of money on electric PROOF OF WORK Jargon: A Consensus Algorithm
  8. Martin Beeby @thebeebs Proof of Stake Proof of Elapsed Time

    Byzantine fault tolerant OTHER CONSENSUS ALGORITHM
  9. Martin Beeby @thebeebs HASHING In west Philadelphia born and raised

    on the play ground was where I spent most of my days. Chilling 446F09C5D7DB665A 851077054EBC7067 56E372A32C8753F0 428B6671CA6CE449 In west helsinki born and raised on the play ground was where I spent most of my days. Chilling 223E8E360399E82A C97B37A73FA1F532 071F03D8A174FA56 6D44F1770CC37D9A SHA256
  10. Martin Beeby @thebeebs Previous Hash of the block All the

    transactions to create a block Hash the block to create a unique Hash that represents everything YOU CANT CHANGE A BLOCK
  11. Martin Beeby @thebeebs A list of transactions grouped into blocks

    Blocks chained together by knowing the previous hash Nothing can be altered, the slightest modification would be obvious A BLOCK CHAIN IS Jargon: Merkle Tree
  12. Martin Beeby @thebeebs Gary decides to run an incentive. Every

    100th cake customer get a reward. Contract Int x AddAddress(address) x = x + 1; If (x =100){ address.transfer(reward) } A PSUEDO CONTRACT
  13. Martin Beeby @thebeebs The contract code is visible on the

    blockchain It can’t be changed by anyone All the calls are public and everyone can see the cake competition is fair ITS TRANSPARENT
  14. Martin Beeby @thebeebs Bitcoin is great when you have zero

    trust in the nodes If you have no trust Proof of Work is a good compromise But the electricity cost is the compromise LEVELS OF TRUST
  15. Martin Beeby @thebeebs You have trust and want to have

    decentralised consensus You want to see all the transitions and have distributed consensus You want to add and remove members. ENTERPRISE TRUST ISSUES CAN BE DIFFERENT
  16. Martin Beeby @thebeebs Private and Permissioned Membership Service Provider (MSP)

    Pluggable: MSP/Consensus/Ledger Format HYPERLEDGER FABRIC Channels
  17. Martin Beeby @thebeebs THE TUNA SUPPLY CHAIN From Sea to

    Table Lots of Fraud Could benefit from Transparency
  18. Martin Beeby @thebeebs TUNA SUPPLY CHAIN Sarah is the fisherman

    who sustainably and legally catches tuna. Regulators verify that the tuna has been legally/sustainably caught. Miriam is a restaurant owner who wants legal/sustainable tuna Carl is another restaurant owner fisherman Sarah can sell tuna to.
  19. Martin Beeby @thebeebs Sarah sells at different prices Privacy around

    deals Carl shouldn’t see Miriams price DEALS NEED TO BE PRIVATE
  20. Martin Beeby @thebeebs type Tuna struct { Vessel string ‘json:"vessel"’

    Datetime string ‘json:"datetime"’ Location string ‘json:"location"’ Holder string ‘json:"holder"’ } TUNA STRUCT
  21. Martin Beeby @thebeebs func (s *SmartContract) initLedger(APIstub shim.ChaincodeStubInterface) sc.Response {

    tuna := []Tuna{ Tuna{Vessel: "923F", Location: "67.0006, -70.5476", Timestamp: "1504054225", Holder: "Miriam"}, Tuna{Vessel: "M83T", Location: "91.2395, -49.4594", Timestamp: "1504057825", Holder: "Dave"}, Tuna{Vessel: "T012", Location: "58.0148, 59.01391", Timestamp: "1493517025", Holder: "Igor"}, Tuna{Vessel: "P490", Location: "-45.0945, 0.7949", Timestamp: "1496105425", Holder: "Amalea"}, Tuna{Vessel: "S439", Location: "-107.6043, 19.5003", Timestamp: "1493512301", Holder: "Rafa"}, Tuna{Vessel: "J205", Location: "-155.2304, -15.8723", Timestamp: "1494117101", Holder: "Shen"}, Tuna{Vessel: "S22L", Location: "103.8842, 22.1277", Timestamp: "1496104301", Holder: "Leila"}, Tuna{Vessel: "EI89", Location: "-132.3207, -34.0983", Timestamp: "1485066691", Holder: "Yuan"}, Tuna{Vessel: "129R", Location: "153.0054, 12.6429", Timestamp: "1485153091", Holder: "Carlo"}, Tuna{Vessel: "49W4", Location: "51.9435, 8.2735", Timestamp: "1487745091", Holder: "Fatima"}, } i := 0 for i < len(tuna) { fmt.Println("i is ", i) tunaAsBytes, _ := json.Marshal(tuna[i]) APIstub.PutState(strconv.Itoa(i+1), tunaAsBytes) fmt.Println("Added", tuna[i]) i = i + 1 } return shim.Success(nil) } INIT
  22. Martin Beeby @thebeebs func (s *SmartContract) Invoke(APIstub shim.ChaincodeStubInterface) sc.Response {

    // Retrieve the requested Smart Contract function and arguments function, args := APIstub.GetFunctionAndParameters() // Route to the appropriate handler function to interact with the ledger appropriately if function == "queryTuna" { return s.queryTuna(APIstub, args) } else if function == "initLedger" { return s.initLedger(APIstub) } else if function == "recordTuna" { return s.recordTuna(APIstub, args) } else if function == "queryAllTuna" { return s.queryAllTuna(APIstub) } else if function == "changeTunaHolder" { return s.changeTunaHolder(APIstub, args) } return shim.Error("Invalid Smart Contract function name.") } INVOKE
  23. Martin Beeby @thebeebs func (s *SmartContract) queryTuna(APIstub shim.ChaincodeStubInterface, args []string)

    sc.Response { if len(args) != 1 { return shim.Error("Incorrect number of arguments. Expecting 1") } tunaAsBytes, _ := APIstub.GetState(args[0]) if tunaAsBytes == nil { return shim.Error(“Could not locate tuna”) } return shim.Success(tunaAsBytes) } QUERYTUNA
  24. Martin Beeby @thebeebs RECORDTUNA func (s *SmartContract) recordTuna(APIstub shim.ChaincodeStubInterface, args

    []string) sc.Response { if len(args) != 5 { return shim.Error("Incorrect number of arguments. Expecting 5") } var tuna = Tuna{ Vessel: args[1], Location: args[2], Timestamp: args[3], Holder: args[4]} tunaAsBytes, _ := json.Marshal(tuna) err := APIstub.PutState(args[0], tunaAsBytes) if err != nil { return shim.Error(fmt.Sprintf("Failed to record tuna catch: %s", args[0])) } return shim.Success(nil) }
  25. Martin Beeby @thebeebs func (s *SmartContract) changeTunaHolder(APIstub shim.ChaincodeStubInterface, args []string)

    sc.Response { if len(args) != 2 { return shim.Error("Incorrect number of arguments. Expecting 2") } tunaAsBytes, _ := APIstub.GetState(args[0]) if tunaAsBytes != nil { return shim.Error("Could not locate tuna") } tuna := Tuna{} json.Unmarshal(tunaAsBytes, &tuna) // Normally check that the specified argument is a valid holder of tuna but here we are skipping this check for this example. tuna.Holder = args[1] tunaAsBytes, _ = json.Marshal(tuna) err := APIstub.PutState(args[0], tunaAsBytes) if err != nil { return shim.Error(fmt.Sprintf("Failed to change tuna holder: %s", args[0])) } return shim.Success(nil) } CHANGETUNAHOLDER
  26. Martin Beeby @thebeebs CALLING SOME CODE // changeTunaHolder - requires

    2 argument var request = { chaincodeId:’tuna-app’, fcn: 'changeTunaHolder', args: ['1', 'Alex'], chainId: 'mychannel', txId: tx_id }; return channel.sendTransactionProposal(request);
  27. @thebeebs 70 A RAIL BUSINESS NETWORK For a wooden trainset

    • SafetyInspectors • TrackInstallers • TimberSupplier • SignallingCompanies • ProjectOwners • Add/Edit/Delete All Assets • SellWood Transfers Ownership of Wood to an Installer • InstallTrack Adds Lat, Long to the track. Fires a new track event. • SignOffTrack Adds a SafetyCertificate and assigns it to the track • SignOffSignal Adds a SafetyCertificate and assigns it to the signal • Track • Signal • Wood • SafetyDocument Participants ASSETS Transactions
  28. @thebeebs Add Participants • SafetyInspectors Signal Safety LTD Track Safe

    LTD • TrackInstallers Tracks R US LTD Install Tracks PLC • TimberSupplier Tims Timber LTD • SignallingCompanies Signals and Stuff LTD • ProjectOwners LS1 LTD Participants
  29. @thebeebs 73 All Participants have THEIR own blockchain NODE TIMS

    TIMBER LTD LS1 LTD SIGNALS AND STUFF LTD TRACK SAFE LTD SIGNAL SAFETY LTD YOU CAN LIMIT WHAT THEY SEE
  30. @thebeebs Date, Time Entry TYPE Participant 2018-05-23 09:01:00 Add Asset

    TimsTimber LTD View record 2018-05-23 09:01:10 Add Asset TimsTimber LTD View Record 2018-05-23 09:01:20 Add Asset TimsTimber LTD View Record 2018-05-23 09:01:30 Add Asset TimsTimber LTD View Record 2018-05-23 09:01:40 ADD ASSET TimsTimber LTD View Record
  31. @thebeebs Date, Time Entry TYPE Participant 2018-05-23 09:20:10 InstallTrack Tracks

    R US LTD View record 2018-05-23 09:20:20 InstallTrack Tracks R US LTD View Record InstallTrack - Adds Lat, Long to the track. Fires a new track event
  32. @thebeebs Date, Time Entry TYPE Participant 2018-05-23 09:20:10 AddAsset SignOffTrack

    View record 2018-05-23 09:30:20 SIGNOFF SignOffTrack View Record
  33. @thebeebs Date, Time Entry TYPE Participant 2018-05-23 09:01:00 Add Asset

    TimsTimber LTD View record 2018-05-23 09:01:10 Add Asset TimsTimber LTD View Record 2018-05-23 09:01:20 Add Asset TimsTimber LTD View Record 2018-05-23 09:01:30 Add Asset TimsTimber LTD View Record 2018-05-23 09:01:40 ADD ASSET TimsTimber LTD View Record 2018-05-23 09:20:10 InstallTrack Tracks R US LTD View record 2018-05-23 09:20:20 InstallTrack Tracks R US LTD View Record 2018-05-23 09:20:10 AddAsset SignOffTrack View record 2018-05-23 09:30:20 SIGNOFF SignOffTrack View Record
  34. @thebeebs 84 NETWORK nodeSCAN live ON THE SAME CLOUD OR

    DIFFERENT ONES. ON PREM TIMS TIMBER LTD ORACLE LS1 LTD MICROSOFT SIGNALS AND STUFF LTD TRACK SAFE LTD ANY HYPERLEDGER IBM SIGNAL SAFETY LTD
  35. @thebeebs Multiple Use Cases Across Industries for Blockchain • Increase

    supply chain transparency • Reduction of counterfeit goods • Warranty management Retail & e-Commerce • Clearing and settlement • Domestic and cross-border payments • Loan origination and post-funding automation • Fraud prevention Finance • Supply chain finance • Track and trace ownership transfer • Compliance monitoring Logistics • Clinical trial management • Privacy and sharing of patient health records Healthcare • Asset management • Certification of renewable energy and emission allowances • Metering and billing Energy