Slide 1

Slide 1 text

Smart Contracts @ Ethereum By Vineet Kumar Singh Innovation Lead, Citi Innovation Lab HyperLedger Corda

Slide 2

Slide 2 text

Smart Contracts @ Ethereum By Vineet Kumar Singh Innovation Lead, Citi Innovation Lab HyperLedger Corda

Slide 3

Slide 3 text

Contracts don't make anything possible that was previously impossible, but rather, they allow you to solve common problems in a way that minimizes trust. Minimal trust often makes things more convenient by allowing human judgements to be taken out of the loop, thus allowing complete automation*. *https://en.bitcoin.it/wiki/Contract

Slide 4

Slide 4 text

Decentralized provable execution of logic. A smart contract’s state is stored on the public blockchain. A smart contract program is executed by a network of miners who reach consensus on the outcome of the execution, and update the contract’s state on the blockchain accordingly. Users can send money or data to a contract; or receive money or data from a contract

Slide 5

Slide 5 text

Block i Block i+1 Block i+2 Block i+3 Block i+4 Mined Block Code Storage Miners Contracts Users Turing Compatible Smart Contracts Compatible Blockchains Data Money Blockchain

Slide 6

Slide 6 text

Contract Development Solidity, Serpent, LLL Contract Interaction WEB3 Javascript Module

Slide 7

Slide 7 text

Contract Development Key Concepts

Slide 8

Slide 8 text

Solidity Contracts ● State Variables ● Functions ● Function Modifiers ● Events ● Structs ● Enum Types Contracts in Solidity are similar to Classes in Object Oriented Languages.

Slide 9

Slide 9 text

State Variables contract SimpleStorage { uint storedData; // State variable // ... } ● external ● public ● internal ● private

Slide 10

Slide 10 text

Functions contract SimpleAuction { function bid() { // Function // ... } }

Slide 11

Slide 11 text

Function Modifiers contract Purchase { address public seller; modifier onlySeller() { // Modifier if (msg.sender != seller) throw; _ } function abort() onlySeller { // Modifier usage // ... } }

Slide 12

Slide 12 text

Events contract SimpleAuction { event HighestBidIncreased(address bidder, uint amount); // Event function bid() { // ... HighestBidIncreased(msg.sender, msg.value); // Triggering event } }

Slide 13

Slide 13 text

Structs contract Ballot { struct Voter { // Struct uint weight; bool voted; address delegate; uint vote; } }

Slide 14

Slide 14 text

Enums contract Purchase { enum State { Created, Locked, Inactive } // Enum }

Slide 15

Slide 15 text

Walkthrough: Escrow Contract Selling goods over the internet without any trusted third party

Slide 16

Slide 16 text

Bob Alice 1. Buyer is scammer ??

Slide 17

Slide 17 text

Bob Alice Buyer is scammer ??

Slide 18

Slide 18 text

Alice Buyer is scammer ?? ??

Slide 19

Slide 19 text

Bob Alice 2. Seller is scammer ??

Slide 20

Slide 20 text

Bob Alice 2. Seller is scammer ??

Slide 21

Slide 21 text

Bob 2. Seller is scammer ?? ??

Slide 22

Slide 22 text

Bob Alice Use an Escrow third Party Eve

Slide 23

Slide 23 text

Bob Alice Use an Escrow Third Party Eve

Slide 24

Slide 24 text

Bob Alice Use an Escrow Third Party ?? ??

Slide 25

Slide 25 text

Bob Alice Two Party Escrow original idea Oleg Andreev

Slide 26

Slide 26 text

Bob Alice Two Party Escrow Seller puts 2x amount

Slide 27

Slide 27 text

Bob Alice Two Party Escrow Buyer puts amount + deposit

Slide 28

Slide 28 text

Bob Alice Two Party Escrow Buyer puts amount + deposit

Slide 29

Slide 29 text

Bob Alice Two Party Escrow Buyer Confirms: Received Buyer gets deposit, Seller gets deposit + sale

Slide 30

Slide 30 text

Bob Alice Two Party Escrow Buyer unhappy with goods Received Seller refunds or money in escrow until they resolve

Slide 31

Slide 31 text

Code

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Web3 API’s

Slide 35

Slide 35 text

Directory Structure

Slide 36

Slide 36 text

Checking for the RPC Connection to Local Node

Slide 37

Slide 37 text

Compiling the Solidity Contract

Slide 38

Slide 38 text

Deploying Contract To Blockchain

Slide 39

Slide 39 text

Secure Contract Principles... ● Error in encoding state machine. ● Failing to use cryptography. ● Misaligned Incentives. Ethereum Specific Mistakes ● Call stack bug ● Blockhash bug ● Not checking return value of sender.send();

Slide 40

Slide 40 text

Thank You