Slide 1

Slide 1 text

Blockchains & Server side Swift Alex Tran Qui ([email protected]) Swift Usergroup Netherlands, 30th January 2018

Slide 2

Slide 2 text

Monetisation and ownership management of digital content using blockchain technology https://katalysis.io

Slide 3

Slide 3 text

Tech stack Katalysis libraries Zewo Server side Swift libraries Ethereum Smart Contract Blockchain

Slide 4

Slide 4 text

Blockchain • Peer to peer system secured by Crypto and Consensus Algorithms • Enables Transactions between untrusted participants • Underlying technology to Bitcoin, Ethereum

Slide 5

Slide 5 text

Signing

Slide 6

Slide 6 text

State Engine

Slide 7

Slide 7 text

Consensus over P2P

Slide 8

Slide 8 text

Blockchain node State Engine Consensus Engine Signature based authentication • Secured by crypto algorithms (hashing and signing) • State engine stores transactions and possibly code and an execution environment • Proof of Work (PoW), Proof of Stake (PoS), …

Slide 9

Slide 9 text

Datastore with following properties: • Immutability = “very difficult” to change history • Transparency amongst participants • Decentralised • Pseudonymity

Slide 10

Slide 10 text

Ethereum Smart Contracts • https://ethereum.org • Ethereum Virtual Machine (EVM) • Storage of data AND code in the State Engine • EVM language is a JS like language called Solidity

Slide 11

Slide 11 text

“Smart Contracts” EVM

Slide 12

Slide 12 text

Blockchain node State Engine Consensus Engine Signature based authentication Great monolithic node =>

Slide 13

Slide 13 text

Tendermint • Toolkit for building blockchains • tendermint/ethermint: fully Ethereum compatible node, either public or private • https://github.com/tendermint/ethermint/ • https://tendermint.com

Slide 14

Slide 14 text

Tendermint Ethermint Tendermint Custom State Engine Tendermint or

Slide 15

Slide 15 text

Tendermint Written in Go.

Slide 16

Slide 16 text

Zewo

Slide 17

Slide 17 text

Zewo Paulo Faria

Slide 18

Slide 18 text

Zewo Lightweight libraries for web application in Swift

Slide 19

Slide 19 text

Zewo

Slide 20

Slide 20 text

Zewo “Don’t communicate by sharing memory. Share memory by communicating.” Rob Pike (co-designer of Go)

Slide 21

Slide 21 text

Zewo Coroutines instead of Multi-threading

Slide 22

Slide 22 text

Zewo/Venice Coroutines in Swift zewo.github.io/Venice/ Wraps libdill.org libdill.org/structured-concurrency.html

Slide 23

Slide 23 text

libdill • Structured concurrency (coroutine nesting) • Coroutines run on a single CPU core • Coroutines must yield control to achieve concurrency • Blocking functions automatically yield

Slide 24

Slide 24 text

Zewo/Venice func testWakeUpWithChannels() throws { let channel = try Channel() let group = Coroutine.Group() func send(_ value: Int, after delay: Duration) throws { try Coroutine.wakeUp(delay.fromNow()) try channel.send(value, deadline: .never) } try group.addCoroutine(body: { try send(111, after: 30.milliseconds) }) try group.addCoroutine(body: { try send(222, after: 40.milliseconds) }) try group.addCoroutine(body: { try send(333, after: 10.milliseconds) }) try group.addCoroutine(body: { try send(444, after: 20.milliseconds) }) XCTAssert(try channel.receive(deadline: .never) == 333) XCTAssert(try channel.receive(deadline: .never) == 444) XCTAssert(try channel.receive(deadline: .never) == 111) XCTAssert(try channel.receive(deadline: .never) == 222) group.cancel() }

Slide 25

Slide 25 text

Katalysis libraries Problem: interact with a blockchain node from Swift Solutions: • EthereumBlockchain Swift library: Ethereum node compliant JSON-RPC calls, including transaction generation and signing. • ABCISwift library: Tendermint ABCIServer allowing the use of the underlying Consensus Engine.

Slide 26

Slide 26 text

Ethereum Blockchain library Ethermint Tendermint Communicate to an Ethereum compatible node (web3.js)

Slide 27

Slide 27 text

Ethereum Blockchain library import EthereumKeys import EthereumBlockchain func run() { do { let priv = [UInt8](repeating: 0x46, count: 32) let key = EthereumKey(seed:priv)! let ebc = EthereumBlockchain("http://localhost:8545/", key) let to = try? Address(bytes:[UInt8](repeating: 0x35, count: 20)) let tx = TransactionRequest(to: to, value: 100) let txHash = try ebc.transact(tx) print("Transaction hash: \(txHash)") } catch let error { print ("\(error)") } }

Slide 28

Slide 28 text

ABCISwift library Custom State Engine Tendermint Communicate directly to a Consensus Engine (ABCIClient)

Slide 29

Slide 29 text

ABCISwift library // ABCI apps should comply to the following protocol public protocol ABCIApplication { func initChain(_ validators: [Validator]) func info(_ version: String) -> ResponseInfo func echo(_ message: String) -> ResponseEcho func flush() func setOption(_ key: String, _ value: String) -> ResponseSetOption func deliverTx(_ tx: Data) -> Result func checkTx(_ tx: Data) -> Result func query(_ q: Query) -> ResponseQuery func beginBlock(_ hash: Data, _ header: Header) func endBlock(_ height: UInt64) -> ResponseEndBlock func commit() -> Result }

Slide 30

Slide 30 text

Katalysis libraries Current Status: • Most building blocks (EthereumKey, RPL, Crypto algos, …) are already open sourced, work with Swift 4.0.x • Earlier implementation of the EthereumBlockchain libraries (BurrowBlockchain) are open sourced • Open Sourcing EthereumBlockchain and ABCISwift libraries is on the roadmap. Talk to us if you are interested.

Slide 31

Slide 31 text

Katalysis libraries https://gitlab.com/katalysis

Slide 32

Slide 32 text

Recap https://gitlab.com/katalysis https://github.com/Zewo https://ethereum.org, https://tendermint.com

Slide 33

Slide 33 text

We’re Hiring! Alex Tran Qui ([email protected])

Slide 34

Slide 34 text

Questions? @katalysis_io [email protected] https://katalysis.io