Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Smart Contracts That Learn

414 views

Published on

An overview of combining blockchain with machine learning

Published in: Technology
  • Be the first to comment

Smart Contracts That Learn

  1. 1. Smart Contracts that Learn Mike Slinn April 3, 2018 Global Blockchain Conference
  2. 2. cryptocourses.tech
  3. 3. About Mike Slinn • Distinguished engineer • Contributor to Ethereum Java and Scala libraries • Operates ScalaCourses.com • Publisher of Java / Node.js Ethereum courses (www.cryptocourses.tech) • Author of EmpathyWorks (artificial personality) • Expert witness • Twitter: mslinn
  4. 4. Key Facts about Mike Slinn • Focuses on generating business value by applying people, process and technology • Wrote 3 books on distributed computing • Created hundreds of online lectures on advanced computing concepts • Uses many computer languages (“polyglot”)
  5. 5. In 10 Years (2028)
  6. 6. The most popular language or framework used to write smart contracts in 10 years probably has not been conceived of yet. -- Mike Slinn, March 3, 2018 --
  7. 7. Machine Learning & Smart Contracts • Machine learning (ML) will be commonly used with smart contracts in 10 years. • Highly specialized languages will evolve to define and verify contracts in various industries. • ML will have features added to guarantee deterministic results for decentralized apps. • Security will surely have to improve
  8. 8. Espionage • In 10 years time corporate and nation/state espionage will include: o Sabotaging training data o Spoofing smart contract events o Seeding smart contract templates with security weaknesses
  9. 9. Newspaper Style Key Takeaways
  10. 10. Dogma and ideology are not good for business Dial Back the Koolaid
  11. 11. Confession Onchain smart contracts cannot actually learn However, these can learn: • User interfaces for on-chain distributed applications (ĐApps) • Oracles • Gateway contracts • Off-chain smart contracts (systems integrated via json- rpc)
  12. 12. On/Off Chain Computation Geth Parity etc
  13. 13. Beware Non-Deterministic Behavior • Blockchain requires determinism for consensus • An AI-driven product may not have deterministic behavior and may produce counter-intuitive results • A personalized recommender system may produce different results for a user action after learning additional preferences
  14. 14. ML is Currently Offchain ML is currently centralized offchain, because significant computation and storage are required • Centralized, offchain processes can respond to onchain events and initiate activity via json-rpc or IPC to Ethereum clients • ML likely not decentralized for several years
  15. 15. ‘Decentralization’ is Misleading • Decentralization uses consensus before output is accepted from multiple EVMs, which then leads to transactions. • Centralization does not use consensus; note that the web3 definition of centralization includes distributed applications that employ DNS with geolocation routing and failover.
  16. 16. Security Issues • Discussion later in this talk o Features/Complexity versus Security o Solidity is misnamed
  17. 17. Solidity is Not Required • Centralization is optional • System integration strategies o ML systems can indirectly interact with the blockchain using json-rpc or IPC to an Ethereum client such as geth or Parity o Native apps can combine ML with blockchain • Application decentralization is optional • Solidity is optional
  18. 18. Issues With Solidity: • Primitive type system. • Compiler bugs (more surely exist). • Few software tools available. • Expensive to work with. • Very expensive to maintain. • Shelf life for this technology will be short.
  19. 19. Avoid Solidity If Possible • Write the smart contract in the language of your choice, and use json-rpc calls as desired. • Resulting code will be well understood by all. • Audits will be more reliable. • Costs will be much less using a common language instead of Solidity. • Talent will be much easier to find.
  20. 20. Ethereum Is Not Symmetric • Onchain smart contracts are distributed and use consensus • Offchain smart contracts (using Ethereum clients) are centralized and do not use consensus • This will likely evolve over the next several years
  21. 21. Transpiling • Process of converting a program written in one language into another language. • Solidity could be transpiled to json-rpc calls from node.js and JVM languages (Java, Scala, JRuby, Jython, Groovy, etc). • … but don’t bother because you endure all the problems with Solidity and get none of the benefits of native contracts
  22. 22. Use Cases With Architecture Diagrams
  23. 23. Self-Optimizing Contracts • Optimize transactions for greatest margin, minimal waste, constant deal flow, or other criteria • Results would improve over time • This is an onchain example
  24. 24. Genetic algorithms Evolution strategies Evolutionary programming Simulated annealing Gaussian adaptation Hill climbing Swarm intelligence Integer linear programming
  25. 25. Fraudulent Event Detection • Smart contracts currently act on all events • Fraud detection often employs machine learning • Incorporating ML into smart contracts could make them resistant to fraud • This is an onchain example
  26. 26. Automated Customer Service Agents • Chatbots and voice interfaces (Alexa) • Much more natural to use • Can be built into devices • This is an onchain example
  27. 27. Geth Parity etc
  28. 28. Medical Diagnosis Expert System • Smart contract mediates access to an expert system (oracle, incorporates machine learning) • Accepts anonymous patient data • Passes data to an expert system that performs analysis • Returns diagnostic results • Charges for the service • This is an offchain example
  29. 29. Geth Parity etc
  30. 30. Supply Chain • SOLIDITY IS NOT REQUIRED • Native application (JVM, .NET, C++, whatever) uses json-rpc to interact with the blockchain • Solidity could be transpiled to json-rpc calls, but don’t bother as previously discussed • This is an offchain example
  31. 31. Supply Chain Node.js Java Scala Jython JRuby C C++ C# F# Geth Parity etc
  32. 32. Contracts
  33. 33. Traditional Contracts… • Outline the terms of a relationship • According to a specific jurisdiction • So that the specified government can enforce the terms
  34. 34. Smart Contracts… • Enable rule-based autonomous actions in response to events. • Work within and between organizations and the rest of society, world-wide.
  35. 35. Smart Contracts Threaten Tradition • Enforce a relationship with cryptographic code • Without regard to the jurisdiction of any government
  36. 36. System Integration • Collecting inputs and outputs to smart contracts requires system integration. • Approaches to system integration vary widely according to the nature of the input sources, output destinations, volumes of data, required reliability, fairness (near-constant latency), etc.
  37. 37. Smart Contracts … • Also known as cryptocontracts • Are computer programs • Directly control the transfer of blockchain-based digital currencies or assets • Define the rules and penalties for an agreement • Might automatically enforce those obligations
  38. 38. Smart Contract Capabilities Manage relationship between parties by: • Maintaining virtual ledgers • Reading/writing arbitrary on-chain data • Reading/writing off-chain data • Forwarding events to other contracts • Acting as a software library
  39. 39. Smart Contract Requirements • Observability • Verifiability • Privity • Enforceability
  40. 40. Oracles • Smart contracts need oracles to resolve details that cannot be precisely known at the time the contract is written. • Oracles provide reference information for smart contracts. • An oracle is a REST API connected to a data source. • Using oracles generally decreases security
  41. 41. Smart Contract Platforms • Bitcoin • Cardano (eventually) • DFinity • EOSIO • Ethereum • Hyperledger • Lisk • Pact on Kadena • NEO • Quorum • Qtum • RSK • Stratis • Wanchain
  42. 42. Ethereum Virtual Machine (EVM) • Deterministic. • Each Ethereum node has an EVM instance. • EVM has a similar execution model to both the Java and the .NET virtual machines. • All these VMs are stack machines executing bytecode. • EVM adds storage and its bytecode is more suited for contracts.
  43. 43. Viable Smart Contract Languages All compile to EVM byte code except Chaincode • AxLang • Chaincode (Hyperledger) • LLL • Pact (Kadena) • Solidity
  44. 44. Solidity
  45. 45. Solidity • Solidity contracts are difficult to secure. • Formal verification could help. • Most Solidity contracts ignore security recommendations. • Solidity’s support for types is rather primitive.
  46. 46. Better On-Chain Language Support
  47. 47. AxLang
  48. 48. AxLang • Smart contract language designed to support formal verification. • Cross-compiled Scala DSL for Ethereum • Designed to scale • Not yet ready
  49. 49. Pact / Kadena • Functional, interpreted Lisp-like syntax • Features type inference • Similar to database stored procedures in an online transaction processing (OLTP) system • Not Turing complete • Runs on the Kadena blockchain
  50. 50. json-rpc (Off-Chain apps)
  51. 51. json-rpc • Popular communications protocol • Communicates between off-chain applications and an Ethereum client
  52. 52. Some json-rpc Libraries • web3.js – for node.js o Can also transpile Solidity to JavaScript • web3j – for Java • Can also transpile Solidity to Java • web3j-scala – for Scala o (I wrote this one) o Idiomatic Scala wrapper around web3j
  53. 53. Learning
  54. 54. How do Computers Learn? • Trial and error with feedback • Training
  55. 55. Types of Machine Learning Classifier systems Reinforcement Representation Rule-based Similarity and metric Sparse dictionary Support vector machines Association rule Artificial neural networks Bayesian networks Clustering Decision tree Deep Genetic algorithms Inductive logic programming
  56. 56. How Might Smart Contracts Learn? • “Learning” computation must occur off-chain • Enforced by the Ethereum fee structure
  57. 57. Machine Learning Applications Machine perception, including computer vision and object recognition Optimization and metaheuristic Recommendation systems Robot locomotion (autonomy) Sentiment analysis Speech and handwriting recognition Structural health monitoring Syntactic pattern recognition User behavior analytics Translation Automated theorem proving Adaptive websites Bioinformatics Classifying DNA sequences Detecting credit-card fraud General game playing Information retrieval Internet fraud detection Insurance Linguistics Medical diagnosis
  58. 58. Caution
  59. 59. Security / Complexity Tradeoff
  60. 60. Solidity and Security • Contracts written in Solidity are difficult to make secure. o Formal verification could help. • Solidity’s support for types is primitive
  61. 61. Security Cannot Be Retrofitted • Secure systems can only be designed that way from the start o Trying to secure an existing platform can only give marginal improvements • Need orders of magnitude of improvements to smart contract security o Not possible without a fresh start
  62. 62. cryptocourses.tech
  63. 63. Thank you! Questions? Mike Slinn mslinn@micronauticsresearch.com 650-678-2285

×