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

Ethereum with little caffeine

Ethereum with little caffeine

Ronak Kogta

August 05, 2017
Tweet

More Decks by Ronak Kogta

Other Decks in Technology

Transcript

  1. Agenda • Blockchain as World Computer • What is Ethereum

    ? • Smart contracts and applications • Writing your first contract • Research Problems
  2. Blockchains and its crudest definition It's a platform that allows

    a software package that contains business logic and user data to sit in the cloud. A copy of this cloud is replicated by millions of computers around the world to keep code/ data integrity. The user interface is an open source project that communicates with the software package in the cloud. To incentivize people to replicate this software package to be maintained you pay them with a digital currency. Rick Tuinenburg
  3. Blockchains and its crudest definition The value of digital currency

    is determined by the popularity of the entire platform. Early adopters gain the most if the platform becomes a success. What makes this platform unique is that the business logic / data cannot be taken down or changed unless multiple anonymous developers around the world agree to do so. This makes it so authorities cannot take down software or data they don't like. Some use cases are: legal public records (deeds, court cases records, fictitious business names, etc) Rick Tuinenburg
  4. Proof of Work Coin Blockchain Dapp ASIC Transaction Contract Miner

    Ledger Pools Crypto Sign Hash Commitment Consensus Exchange Technically we should know…
  5. Blockchain as world computer f(x)=? f(x)=y f(x) = y ?

    f(x) = y ? f(x)=y Consensus Computer
  6. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton
  7. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored
  8. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored Ubiquitous
  9. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored Ubiquitous Verifiable and Auditable
  10. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored Ubiquitous Verifiable and Auditable Guarantees
  11. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored Ubiquitous Verifiable and Auditable Atomicity Guarantees
  12. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored Ubiquitous Verifiable and Auditable Atomicity Immortality Guarantees
  13. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored Ubiquitous Verifiable and Auditable Atomicity Immortality Immutable Code Guarantees
  14. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored Ubiquitous Verifiable and Auditable Atomicity Immortality Immutable Code Synchrony Guarantees
  15. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored Ubiquitous Verifiable and Auditable Atomicity Immortality Immutable Code Synchrony Provenance Guarantees
  16. Decentralised Computer Ethereum Truly a 1950s computer Not always
 decisive

    Expansive to use Slow
 (5-1000x) Truly a global singleton Cannot fail, be stopped or censored Ubiquitous Verifiable and Auditable Atomicity Immortality Immutable Code Synchrony Provenance Permanence Guarantees
  17. Ethereum (Just another blockchain) • Blockchain is a decentralised ledger

    of trust. – Rather than currency, you can use the ledger for kind of applications which require trust
  18. Ethereum (Just another blockchain) • Blockchain is a decentralised ledger

    of trust. – Rather than currency, you can use the ledger for kind of applications which require trust – For e.g. Notary, writing a will, or decentralised
  19. Ethereum (Just another blockchain) • Blockchain is a decentralised ledger

    of trust. – Rather than currency, you can use the ledger for kind of applications which require trust – For e.g. Notary, writing a will, or decentralised I. Craiglist , Uber, Zomato …
  20. Ethereum (Just another blockchain) • Blockchain is a decentralised ledger

    of trust. – Rather than currency, you can use the ledger for kind of applications which require trust – For e.g. Notary, writing a will, or decentralised I. Craiglist , Uber, Zomato … II. Ebay, Amazon, Uber …
  21. Ethereum (Just another blockchain) • Blockchain is a decentralised ledger

    of trust. – Rather than currency, you can use the ledger for kind of applications which require trust – For e.g. Notary, writing a will, or decentralised I. Craiglist , Uber, Zomato … II. Ebay, Amazon, Uber … • The way to do it is to write programs which are called “Smart Contracts”
  22. Ethereum (Just another blockchain) • Blockchain is a decentralised ledger

    of trust. – Rather than currency, you can use the ledger for kind of applications which require trust – For e.g. Notary, writing a will, or decentralised I. Craiglist , Uber, Zomato … II. Ebay, Amazon, Uber … • The way to do it is to write programs which are called “Smart Contracts” • Ethereum can also be used to do normal ether transactions.
  23. Ethereum (Just another blockchain) • Blockchain is a decentralised ledger

    of trust. – Rather than currency, you can use the ledger for kind of applications which require trust – For e.g. Notary, writing a will, or decentralised I. Craiglist , Uber, Zomato … II. Ebay, Amazon, Uber … • The way to do it is to write programs which are called “Smart Contracts” • Ethereum can also be used to do normal ether transactions. Matchmakers
  24. Ethereum Programming Model Bob does not believe in Spiderman, but

    Alice does Alice bets that if she is in danger, Spiderman will protect her.
  25. Ethereum Programming Model Bob does not believe in Spiderman, but

    Alice does Alice bets that if she is in danger, Spiderman will protect her. Spiderman morally wants to help everybody, if he can.
 Because with great power comes great responsibility.
  26. Ethereum Programming Model Bob does not believe in Spiderman, but

    Alice does Alice bets that if she is in danger, Spiderman will protect her. Spiderman morally wants to help everybody, if he can.
 Because with great power comes great responsibility. Alice does not trust Bob, and needs to ensure that they both hold 
 their end of bargains after the bet is done.
  27. Ethereum Programming Model Bob does not believe in Spiderman, but

    Alice does Alice bets that if she is in danger, Spiderman will protect her. Spiderman morally wants to help everybody, if he can.
 Because with great power comes great responsibility. Alice does not trust Bob, and needs to ensure that they both hold 
 their end of bargains after the bet is done. Spiderman is unaware of this bet, and just webbing his way around.
  28. Ethereum Programming Model Contract Persistent Msg Store $$$ Program Logic

    ?? $$$ Msg • Contract = Code + State • Turing Complete
  29. Ethereum Programming Model Contract Persistent Msg Store $$$ Program Logic

    ?? $$$ Msg • Contract = Code + State • Turing Complete • Self-Executing and enforcing
  30. Ethereum Programming Model Contract Persistent Msg Store $$$ Program Logic

    ?? $$$ Msg • Contract = Code + State • Turing Complete • Self-Executing and enforcing
  31. Ethereum Programming Model Contract Persistent Msg Store $$$ Program Logic

    ?? $$$ Msg • Contract = Code + State • Turing Complete • Self-Executing and enforcing are submitted as transactions in 
 blockchain.
  32. Ethereum Programming Model Contract Persistent Msg Store $$$ Program Logic

    ?? $$$ Msg • Contract = Code + State • Turing Complete • Self-Executing and enforcing are submitted as transactions in 
 blockchain. - Can send eth to other accounts
  33. Ethereum Programming Model Contract Persistent Msg Store $$$ Program Logic

    ?? $$$ Msg • Contract = Code + State • Turing Complete • Self-Executing and enforcing are submitted as transactions in 
 blockchain. - Can send eth to other accounts - Read/write from storage
  34. Ethereum Programming Model Contract Persistent Msg Store $$$ Program Logic

    ?? $$$ Msg • Contract = Code + State • Turing Complete • Self-Executing and enforcing are submitted as transactions in 
 blockchain. - Can send eth to other accounts - Read/write from storage - Invoke function calls to other contracts
  35. Ethereum Programming Model Contract Persistent Msg Store $$$ Program Logic

    ?? $$$ Msg • Contract = Code + State • Turing Complete • Self-Executing and enforcing are submitted as transactions in 
 blockchain. - Can send eth to other accounts - Read/write from storage - Invoke function calls to other contracts - Create other contracts
  36. Contract Workflow Your Contract 60606040526040516102503 80380610250833981016040 528........ What others see


    in blockchain PUSH 60 PUSH 40 MSTORE PUSH 0 CALLDATALOAD ..... Disassembler output
  37. Transactions • nonce (anti-replay-attack or transaction counter) • to (destination

    address) • value (amount of ETH to send) • data (readable by contract code) • gasprice (amount of ether per unit gas) • startgas (maximum gas consumable) • v, r, s (ECDSA signature values)
  38. How to Create a Contract? • Submit a transaction to

    the blockchain – nonce: previous nonce + 1 – to: empty – value: value sent to the new contract – data: contains the code of the contract – gasprice (amount of ether per unit gas) – startgas (maximum gas consumable) – v, r, s (ECDSA signature values) • If tx is successful – Returns the address of the new contract
  39. How to Interact With a Contract? • Submit a transaction

    to the blockchain – nonce: previous nonce + 1 – to: contract address – value: value sent to the new contract – data: data supposed to be read by the contract – gasprice (amount of ether per unit gas) – startgas (maximum gas consumable) – v, r, s (ECDSA signature values) • If tx is successful – Returns outputs from the contract (if applicable)
  40. Ethereum Frameworks Serpent Solidity Lower Level Language Ethereum VM Bytecode

    Stack Language (Like python) (Like javascript) (Function and macros
 like scheme) (Defined in Ethereum
 yellow paper) *Slide from Andrew Miller
  41. Blockchain State Address Balance (BTC) 0x123456… 10 0x1a2b3f… 1 0xab123d…

    1.1 Bitcoin's state consists of key value mapping of addresses to account balance
  42. Blockchain State Address Balance (BTC) 0x123456… 10 0x1a2b3f… 1 0xab123d…

    1.1 Ethereum’s state consists of key value mapping addresses to account objects Address Object 0x123456… X 0x1a2b3f… Y 0xab123d… Z Bitcoin's state consists of key value mapping of addresses to account balance
  43. Blockchain State Address Balance (BTC) 0x123456… 10 0x1a2b3f… 1 0xab123d…

    1.1 Ethereum’s state consists of key value mapping addresses to account objects Address Object 0x123456… X 0x1a2b3f… Y 0xab123d… Z Bitcoin's state consists of key value mapping of addresses to account balance Blockchain != Blockchain State
  44. EVM Program Counter Computes preamble
 computation for transaction Rolls back

    the
 transaction, if it fails Ethereum State Transition
  45. EVM Program Counter Computes preamble
 computation for transaction Commits the


    transaction
 if success Rolls back the
 transaction, if it fails Ethereum State Transition
  46. EVM Program Counter Computes preamble
 computation for transaction Commits the


    transaction
 if success Rolls back the
 transaction, if it fails Ethereum State Transition 1 Syntax checking transaction.
  47. EVM Program Counter Computes preamble
 computation for transaction Commits the


    transaction
 if success Rolls back the
 transaction, if it fails Ethereum State Transition 1 Syntax checking transaction. 2 Computing preamble transaction fee.
  48. EVM Program Counter Computes preamble
 computation for transaction Commits the


    transaction
 if success Rolls back the
 transaction, if it fails Ethereum State Transition 1 Syntax checking transaction. 2 Computing preamble transaction fee. 3 Initialise the gas payment.
  49. EVM Program Counter Computes preamble
 computation for transaction Commits the


    transaction
 if success Rolls back the
 transaction, if it fails Ethereum State Transition 1 Syntax checking transaction. 2 Computing preamble transaction fee. 3 Initialise the gas payment. 4 Transfer the amount from sender to receiver.
  50. EVM Program Counter Computes preamble
 computation for transaction Commits the


    transaction
 if success Rolls back the
 transaction, if it fails Ethereum State Transition 1 Syntax checking transaction. 2 Computing preamble transaction fee. 3 Initialise the gas payment. 4 Transfer the amount from sender to receiver. 5 Throw error, when sender account does not have sufficient ether, and roll back transaction.
  51. EVM Program Counter Computes preamble
 computation for transaction Commits the


    transaction
 if success Rolls back the
 transaction, if it fails Ethereum State Transition 1 Syntax checking transaction. 2 Computing preamble transaction fee. 3 Initialise the gas payment. 4 Transfer the amount from sender to receiver. 5 Throw error, when sender account does not have sufficient ether, and roll back transaction. 6 For any other error, send the gas fee to sender
  52. Account Object • Every account object contains 4 pieces of

    data: – Nonce – Balance – Code hash (code = empty string for normal accounts) – Storage trie root
  53. Account Object • Every account object contains 4 pieces of

    data: – Nonce – Balance – Code hash (code = empty string for normal accounts) – Storage trie root
  54. Tx-n Tx-1 Block Mining Miners Tx-2 Block A set of

    TXs Previous block New State Root Receipt Root Nonce
  55. Tx-n Tx-1 Block Mining Miners Tx-2 Block A set of

    TXs Previous block New State Root Receipt Root Nonce
  56. Tx-n Tx-1 Block Mining Miners Tx-2 Block A set of

    TXs Previous block New State Root Receipt Root Nonce Verify transactions & execute all code to update the state
  57. Tx-n Tx-1 Block Mining Miners Tx-2 Block A set of

    TXs Previous block New State Root Receipt Root Nonce SHA3(Block) < D Verify transactions & execute all code to update the state
  58. Tx-n Tx-1 Block Mining Miners Tx-2 Block A set of

    TXs Previous block New State Root Receipt Root Nonce SHA3(Block) < D Broadcast Block Verify transactions & execute all code to update the state
  59. Code execution • Every (full) node on the blockchain processes

    every transaction and stores the entire state P6 P5 P4 P3 P2 P1
  60. Code execution • Every (full) node on the blockchain processes

    every transaction and stores the entire state P6 P5 P4 P3 P2 P1 This is a new block! I’m a leader
  61. Code execution • Every (full) node on the blockchain processes

    every transaction and stores the entire state P6 P5 P4 P3 P2 P1 This is a new block! I’m a leader This is a new block! This is a new block! This is a new block! This is a new block! This is a new block!
  62. Dos Attack Vector • Halting problem – Cannot tell whether

    or not a program will run infinitely – A malicious miner can DoS attack full nodes by including lots of computation in their txs • Full nodes attacked when verifying the block uint i = 1; while (i++ > 0) { donothing(); }
  63. Solution: Gas • Charge fee per computational step (“gas”) –

    Special gas fees for operations that take up storage
  64. Solution: Gas • Charge fee per computational step (“gas”) –

    Special gas fees for operations that take up storage
  65. Solution: Gas • Charge fee per computational step (“gas”) –

    Special gas fees for operations that take up storage
  66. Sender has to pay for the gas • gasprice: amount

    of ether per unit gas • startgas: maximum gas consumable – If startgas is less than needed • Out of gas exception, revert the state as if the TX has never happened • Sender still pays all the gas • TX fee = gasprice * consumedgas • Gas limit: similar to block size limit in Bitcoin – Total gas spent by all transactions in a block < Gas Limit
  67. What are Smart Contracts ? A smart contract is a

    computer program executed in a secure environment that directly controls digital assets
  68. Properties of Smart Contracts • Correctness of execution – The

    execution is done correctly, is not tampered • Integrity of code and data • Optional properties – Confidentiality of code and data – Verifiability of execution – Availability for the programs running inside Security Property
  69. Properties of Smart Contracts • Correctness of execution – The

    execution is done correctly, is not tampered • Integrity of code and data • Optional properties – Confidentiality of code and data – Verifiability of execution – Availability for the programs running inside Security Property Servers secured
 by trusted 
 hardware.
 (Intel SGX)
  70. Properties of Smart Contracts • A broad category – Domain

    name – Website – Money – Anything tokenisable (e.g. gold, silver, stock share etc) – Game items – Network bandwidth, computation cycles Digital Assets
  71. Properties of Smart Contracts • Requires parties to pay collateral

    before participating. • Use oracles (external trusted third parties) • Use network (miners are ready to do your work for a good incentive) • Cryptography 1. Commitments 2. Digital signatures 3. Merkle trees and authenticated data structures Technical aspects of smart contract
  72. Example: escrow service for exchange A B E X A

    B E A B E I won’t give you Y Y
  73. Example: escrow service for exchange A B E X A

    B E A B E I won’t give you Y Y
  74. Example: escrow service for exchange A B E X A

    B E A B E I won’t give you Y Y A B E A B E X X
  75. Example: multisig • Require M of N “owners” to agree

    in order for a particular digital asset to be transferred – Individual use cases • eg. two-factor authentication – Intra-organizational use cases
  76. Research Problems • How to write secure and correct contracts

    ? Need tools like Oyente • Can define your secure ethereum client based on yellow paper
  77. Research Problems • How to write secure and correct contracts

    ? Need tools like Oyente • Can define your secure ethereum client based on yellow paper • Can define programming languages like rust for smart contracts.
  78. Research Problems • How to write secure and correct contracts

    ? Need tools like Oyente • Can define your secure ethereum client based on yellow paper • Can define programming languages like rust for smart contracts. • Scaling Issues ?
  79. Research Problems • How to write secure and correct contracts

    ? Need tools like Oyente • Can define your secure ethereum client based on yellow paper • Can define programming languages like rust for smart contracts. • Scaling Issues ? • Sharding
  80. Research Problems • How to write secure and correct contracts

    ? Need tools like Oyente • Can define your secure ethereum client based on yellow paper • Can define programming languages like rust for smart contracts. • Scaling Issues ? • Sharding • State channels
  81. Research Problems • How to write secure and correct contracts

    ? Need tools like Oyente • Can define your secure ethereum client based on yellow paper • Can define programming languages like rust for smart contracts. • Scaling Issues ? • Sharding • State channels • Privacy Issues (Ring signatures, ZK-SNARKS and Hawk)
  82. Research Problems • How to write secure and correct contracts

    ? Need tools like Oyente • Can define your secure ethereum client based on yellow paper • Can define programming languages like rust for smart contracts. • Scaling Issues ? • Sharding • State channels • Privacy Issues (Ring signatures, ZK-SNARKS and Hawk) • Ethereum Virtual machine and improvement in language models
  83. Research Problems • How to write secure and correct contracts

    ? Need tools like Oyente • Can define your secure ethereum client based on yellow paper • Can define programming languages like rust for smart contracts. • Scaling Issues ? • Sharding • State channels • Privacy Issues (Ring signatures, ZK-SNARKS and Hawk) • Ethereum Virtual machine and improvement in language models • Proof of work/stake model for x86_64 which is gpu and asic resistant
  84. Research Problems • How to write secure and correct contracts

    ? Need tools like Oyente • Can define your secure ethereum client based on yellow paper • Can define programming languages like rust for smart contracts. • Scaling Issues ? • Sharding • State channels • Privacy Issues (Ring signatures, ZK-SNARKS and Hawk) • Ethereum Virtual machine and improvement in language models • Proof of work/stake model for x86_64 which is gpu and asic resistant • Defining decentralised pools and exchanges and relays (eg. Smart pool and BTC relay)
  85. Research Problems • Role of algorithmic incentives(game theory) in cryptocurrency

    • Transaction in blockchain = mining reward + mining fee + private cost function
  86. Research Problems • Role of algorithmic incentives(game theory) in cryptocurrency

    • Transaction in blockchain = mining reward + mining fee + private cost function • Multi-Agents are involved like miners, type of transactions etc.
  87. Research Problems • Role of algorithmic incentives(game theory) in cryptocurrency

    • Transaction in blockchain = mining reward + mining fee + private cost function • Multi-Agents are involved like miners, type of transactions etc. • Can we define a model to calculate the costs for a particular contract or at least provide some guarantee.
  88. Research Problems • Role of algorithmic incentives(game theory) in cryptocurrency

    • Transaction in blockchain = mining reward + mining fee + private cost function • Multi-Agents are involved like miners, type of transactions etc. • Can we define a model to calculate the costs for a particular contract or at least provide some guarantee. • Can do various studies of economics in crypto-regime
  89. Research Problems • Role of algorithmic incentives(game theory) in cryptocurrency

    • Transaction in blockchain = mining reward + mining fee + private cost function • Multi-Agents are involved like miners, type of transactions etc. • Can we define a model to calculate the costs for a particular contract or at least provide some guarantee. • Can do various studies of economics in crypto-regime • Behavioural economic models
  90. Research Problems • Role of algorithmic incentives(game theory) in cryptocurrency

    • Transaction in blockchain = mining reward + mining fee + private cost function • Multi-Agents are involved like miners, type of transactions etc. • Can we define a model to calculate the costs for a particular contract or at least provide some guarantee. • Can do various studies of economics in crypto-regime • Behavioural economic models • Selfish Agents
  91. Research Problems • Role of algorithmic incentives(game theory) in cryptocurrency

    • Transaction in blockchain = mining reward + mining fee + private cost function • Multi-Agents are involved like miners, type of transactions etc. • Can we define a model to calculate the costs for a particular contract or at least provide some guarantee. • Can do various studies of economics in crypto-regime • Behavioural economic models • Selfish Agents • Coordinated choices
  92. Research Problems • Role of algorithmic incentives(game theory) in cryptocurrency

    • Transaction in blockchain = mining reward + mining fee + private cost function • Multi-Agents are involved like miners, type of transactions etc. • Can we define a model to calculate the costs for a particular contract or at least provide some guarantee. • Can do various studies of economics in crypto-regime • Behavioural economic models • Selfish Agents • Coordinated choices • How a blackmail would happen, what would be protocols for heist, Can there be a morality check on contracts
  93. Research Problems • Role of algorithmic incentives(game theory) in cryptocurrency

    • Transaction in blockchain = mining reward + mining fee + private cost function • Multi-Agents are involved like miners, type of transactions etc. • Can we define a model to calculate the costs for a particular contract or at least provide some guarantee. • Can do various studies of economics in crypto-regime • Behavioural economic models • Selfish Agents • Coordinated choices • How a blackmail would happen, what would be protocols for heist, Can there be a morality check on contracts https://github.com/ethereum/research/wiki/Problems