Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g....

23
Smart Contracts Raymond Cheng Dawn Song Slides credits: Andrew Miller & Ari Juels

Transcript of Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g....

Page 1: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Smart ContractsRaymond Cheng

Dawn Song

Slides credits: Andrew Miller & Ari Juels

Page 2: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

• Currently #2 public cryptocurrency• Many of the top cryptocurrencies are implemented as

smart contracts on top of smart contract blockchains(e.g. Ethereum)

Page 3: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Ethereum may overtake Bitcoin in market cap

Source: coinmarketca

p

Page 4: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do
Page 5: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

What do we expect from contracts?

• Language to specify terms of the agreement• A way to specify your identity and consent• Enforcement and dispute resolution

Page 6: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

What is a smart contract?

• User-defined programs running on top of a blockchain• Smart contract simulates trusted third party with shared state.

Contracts

Code

Storage

Data

Users Money Decentralized Consensus (“Blockchain”)

Page 7: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

“Smart contracts”conceptualized by Szabo in 1994A smart contract is a computerized transaction protocol that executes the terms of a contract. The general objectives are to satisfy common contractual conditions (such as payment terms, liens, confidentiality, and even enforcement), minimize exceptions both malicious and accidental, and minimize the need for trusted intermediaries. Related economic goals include lowering fraud loss, arbitrations and enforcement costs, and other transaction costs.

-Nick Szabo “The Idea of Smart Contracts”

For example: Smart contract reassigns physical access to your car from you to your bank if you don’t make a payment

Page 8: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

$20,000 10 sharesGOOGL

GOOGL⇑ = $2000by 30 Sept 2019

Suppose Alice and Bob strike a deal…

Problem of Fair Exchange!

Page 9: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Smartcontract

$20,00010 shares GOOGL

$20,00010 sharesGOOGL

GOOGL = $2000By 30 Sept. 2019

Virtual trusted third-party (with public state)

Page 10: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Virtual trusted third-party (with public state)

$20,00010 shares GOOGL

$20,00010 sharesGOOGL

GOOGL = $2000By 30 Sept. 2019

Page 11: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Okay great, we want smart contracts, but why on blockchain?

Page 12: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Cryptocurrency Exchanges

Mt. Gox$10,000 1 BTC

$10,0001 BTC

BTC = $10000By 30 Sept. 2019

Page 13: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Okay great, we want smart contracts, but why on blockchain?

Page 14: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

#1: Smart contracts must enforce correct execution

Page 15: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Smart Contract Applications

• Tokens• Lotteries• Insurance• Supply-chain management• Marketplaces• Cryptocurrency exchanges• “Self-sovereign” identity management• Covenants• Sharing economy• And many more!

Page 16: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Token Smart Contracts

Init: balance[creator] = 1,000,000

Transfer($amt, from, to): Assert balance[from] ≥ $amtbalance[from] := balance[from] - $amtbalance[to] := balance[to] + $amt

Contract stores everyone’s balance

Transfer moves tokens fromone account to another

Page 17: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

#2: Transactions to smart contracts must beall-or-nothing

Page 18: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Lottery Smart Contract

Init: Tend := 7 June 2018, $ticket := 1 , pool := {}, pot := 0

TicketPurchase($amt, P): On receive $amt from party P:Assert $amt = $ticket, balance[P] ≥ $amtbalance[P] := balance[P] - $ticketpot := pot + $ticketpool := pool ⋃ P

Timer:If T > Tend thenW ∈R poolbalance[W] := balance[W] + pot

Contract stores the end time,ticket cost, current pool, and pot

If the party has enough money, add them to the pool and their money to

the pot

At the end, select a winner

Page 19: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

#3: Contracts are enforced by the blockchain

Page 20: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

FlightInsurance

Gimme a $100 policy

(Flight #1215, 17 May, Policy price: $1)

$100

Automated Insurance Contracts

$1

Page 21: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

#4: Contracts have an auditable history

Page 22: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Smart contract properties

• Guaranteed to execute correctly• Malicious miner cannot cheat

• Transactions are all-or-nothing• Autonomous: Enforced by network• Cannot be changed or stopped, even by its creator

• All data is stored on the blockchain• Auditable history

• Intuition: Smart contract simulates trusted third party with public state.

Page 23: Smart Contracts - GitHub Pages · smart contracts on top of smart contract blockchains (e.g. Ethereum) Ethereum may overtake Bitcoin in market cap Source: coinmarketca p. What do

Traditional contracts vs. smart contracts

Traditional Smart

Specification Natural language + “legalese”

Code

Identity & consent Signatures Digital signatures

Dispute resolution Judges, arbitrators Decentralized platform

Nullification By judges ????

Payment As specified built-in

Escrow Trusted third party built-in