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

TxVM: A New Design for Blockchain Transactions

TxVM: A New Design for Blockchain Transactions

These are the slides from the talk I gave at the Stanford Blockchain Conference about TxVM, a smart contract language we designed at Chain.

Cathie Yun

January 24, 2018
Tweet

More Decks by Cathie Yun

Other Decks in Programming

Transcript

  1. Introducing TxVM Cathie Yun, Software Engineer J A N U

    A R Y 2 5 , 2 0 1 8
  2. Chain builds ledger services for financial institutions. Underlying technology: transactions

    on a blockchain. Supports high transaction volumes, issued assets, and smart contracts. Background
  3. Bitcoin Existing approaches Ethereum Two popular blockchains use different models

    for transactions and contracts.
  4. Transactions and contracts are declarative. Bitcoin version lock time outpoint

    sequence signature inputs outpoint sequence signature outpoint sequence signature amount outputs amount script script version lock time outpoint sequence signature inputs outpoint sequence signature outpoint sequence signature amount outputs amount
  5. Programs are simple predicates. Resulting state is known before publication.

    Bitcoin version lock time outpoint sequence signature inputs outpoint sequence signature outpoint sequence signature amount outputs amount script utxo set script
  6. Transactions and contracts are imperative. Ethereum nonce gas price data

    destination amount signature start gas
  7. Contracts can call other contracts. Resulting state is unknown until

    tx is published. Ethereum nonce gas price data destination amount signature start gas deployed contracts
  8. BTC Introducing TxVM EVM TxVM deterministic & isolated expressive language

    safe environment ✔ ✔ ✔ ✔ ✔ ✔ ✘ ✘ ✘
  9. Transaction is the program: executes contracts, controls value flow and

    provides signatures. TxVM version runlimit program
  10. Executing the program produces a deterministic transaction log. TxVM version

    runlimit program input transaction log input input output output utxo set
  11. First class values and contracts as a part of the

    VM type system. TxVM 1. Values and contracts have constrained operations that preserve a "law of conservation” 2. Values and contracts must be cleared from the VM by the end of execution.
  12. Example ride-sharing transaction First-class Values 1. Operations preserve "law of

    conservation” 2. Objects must be cleared from the VM by the end
  13. Example ride-sharing transaction rider $15 First-class Values 1. Operations preserve

    "law of conservation” 2. All objects must be cleared from the VM
  14. Example ride-sharing transaction rider $15 $15 First-class Values 1. Operations

    preserve "law of conservation” 2. All objects must be cleared from the VM
  15. Example ride-sharing transaction $15 $15 $5 $10 First-class Values rider

    1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  16. Example ride-sharing transaction company $5 driver $15 $15 $5 $10

    $10 First-class Values rider 1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  17. Example ride-sharing transaction company $5 driver $15 $15 $5 $10

    $10 First-class Values ✔ ✔ rider 1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  18. Impossible application violating rule #1 First-class Values 1. Operations preserve

    "law of conservation” 2. All objects must be cleared from the VM
  19. rider $5 First-class Values Impossible application violating rule #1 1.

    Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  20. $5 $5 First-class Values Impossible application violating rule #1 rider

    1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  21. $5 $5 $2 $1 First-class Values ✘ Impossible application violating

    rule #1 rider 1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  22. Invalid transaction violating rule #2 First-class Values 1. Operations preserve

    "law of conservation” 2. All objects must be cleared from the VM
  23. rider $5 First-class Values Invalid transaction violating rule #2 1.

    Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  24. $5 $5 First-class Values Invalid transaction violating rule #2 rider

    1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  25. $5 First-class Values Invalid transaction violating rule #2 $5 $1

    $2 $2 rider 1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  26. $5 First-class Values Invalid transaction violating rule #2 $5 $1

    $2 $2 company $1 driver $2 rider 1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  27. $5 First-class Values Invalid transaction violating rule #2 $5 $1

    $2 $2 company $1 driver $2 ✘ rider 1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  28. $5 First-class Values Invalid transaction violating rule #2 $5 $1

    $2 $2 rider 1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  29. $5 First-class Values Invalid transaction violating rule #2 $5 $1

    $2 $2 rider company $1 driver $2 driver $2 ✔ ✔ 1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  30. TxVM internals 30 1 VM parts stacks tx log runlimit

    code
  31. TxVM internals 31 1 VM parts 2 VM rules stacks

    tx log runlimit code empty stacks tx is finalized runlimit not exceeded no failures
  32. TxVM internals 32 1 VM parts 2 VM rules 3

    Blockchain updates stacks tx log runlimit code empty stacks tx is finalized runlimit not exceeded no failures all effects in tx log remove inputs add outputs
  33. TxVM walkthrough 33 {Alice’s $10} input call {Bob’s $5} input

    call merge_values [Carol’s acc] contract call finalize <signatures>... call Alice’s $10 Alice’s $5 Carol’s account
  34. TxVM walkthrough 34 {Alice’s $10} input call {Bob’s $5} input

    call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log Alice’s $10 Alice’s $5 Carol’s account
  35. Claim and open an input 35 {Alice’s $10} input call

    {Bob’s $5} input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log $10 Alice's contract Alice’s $10 Alice’s $5 Carol’s account Input $10
  36. Claim a second input 36 {Alice’s $10} input call {Bob’s

    $5} input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log $10 Alice's contract $5 Alice's contract Alice’s $10 Alice’s $5 Carol’s account Input $5 Input $10
  37. Merge and split values 37 {Alice’s $10} input call {Bob’s

    $5} input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log Alice's contract $15 Alice's contract Alice’s $10 Alice’s $5 Carol’s account Input $5 Input $10
  38. Lock value in a new contract 38 {Alice’s $10} input

    call {Bob’s $5} input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log Alice's contract Alice's contract Alice’s $10 Alice’s $5 Carol’s account Input $5 Input $10 Output $15
  39. Freeze modifications, compute transaction ID 39 {Alice’s $10} input call

    {Bob’s $5} input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log Alice's contract Alice's contract Alice’s $10 Alice’s $5 Carol’s account Input $5 Input $10 Output $15 Tx ID
  40. Clear remaining contracts 40 {Alice’s $10} input call {Bob’s $5}

    input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log Alice's contract Alice's contract Input $5 Input $10 Alice’s $10 Alice’s $5 Carol’s account Output $15 Tx ID
  41. TxVM recap 41 {Alice’s $10} input call {Bob’s $5} input

    call merge_values [Carol’s acc] contract call finalize <signatures>... call Declared inputs Value flow New outputs Freeze tx log Clear remaining contracts Alice’s $10 Alice’s $5 Carol’s account
  42. Diving into contracts 42 {Alice’s $10} input call {Bob’s $5}

    input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log Alice's contract Alice's contract Alice’s $10 Alice’s $5 Carol’s account Input $5 Input $10 Output $15 Tx ID C1 C3 C2
  43. txid <Alice’s pubkey> get_sig checksig verify Signature contract Checks a

    simple signature on transaction ID. Get the Tx ID
 as calculated from 
 the finalized tx log Clear contract if valid, fail VM if invalid C1 Get Alice’s
 signature
  44. Diving into contracts 44 {Alice’s $10} input call {Bob’s $5}

    input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log Alice's contract Alice's contract Alice’s $10 Alice’s $5 Carol’s account Input $5 Input $10 Output $15 Tx ID C1 C3 C2
  45. Unspent output contract Unlocks the value and defers a checksig

    contract. <$10> put_value [txid <Alice’s pubkey> get_sig checksig verify] put_contract C2
  46. Unspent output contract C2 C1 Unlocks the value and defers

    a checksig contract. txid <Alice’s pubkey> get_sig checksig verify C1 <$10> put_value 
 [ ] put_contract txvm stack
  47. Unspent output contract Release the $10 value Unlocks the value

    and defers a checksig contract. <$10> put_value 
 [ ] put_contract C2 C1 $10 txvm stack
  48. Unspent output contract Release the checksig contract Unlocks the value

    and defers a checksig contract. C2 C1 $10 txvm stack Alice's contract <$10> put_value 
 [ ] put_contract
  49. Diving into contracts 49 {Alice’s $10} input call {Bob’s $5}

    input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log Alice's contract Alice's contract Alice’s $10 Alice’s $5 Carol’s account Input $5 Input $10 Output $15 Tx ID C1 C3 C2
  50. New output contract Locks the value and creates an output.

    get_value [put_value [txid <pubkey> get_sig checksig verify] put_contract] output C3
  51. New output contract Locks the value and creates an output.

    get_value
 [ ]output C3 C2 [put_value [txid <pubkey> get_sig checksig verify] put_contract] C2
  52. New output contract Locks the value and creates an output.

    $15 txvm stack get_value
 [ ]output C3 C2 tx log Input $5 Input $10
  53. New output contract Locks the value and creates an output.

    txvm stack get_value
 [ ]output C3 C2 tx log Input $5 Input $10 Receive the value to be locked $15
  54. New output contract Locks the value and creates an output.

    txvm stack get_value
 [ ]output C3 C2 tx log Input $5 Input $10 Output contract C2 with $15 value Output $15
  55. Diving into contracts 55 {Alice’s $10} input call {Bob’s $5}

    input call merge_values [Carol’s acc] contract call finalize <signatures>... call stack tx log Alice's contract Alice's contract Alice’s $10 Alice’s $5 Carol’s account Input $5 Input $10 Output $15 Tx ID C1 C3 C2
  56. TxVM instruction set 56

  57. • TxVM is a new model for blockchain transactions. •

    Borrows good parts from both Bitcoin and Ethereum. • Powerful abstractions: first-class values and contracts. • Safe and straightforward language for writing smart contracts. • Open source & whitepaper soon. Conclusion
  58. Cathie Yun 58 [email protected] [email protected] Bob Glickstein @danrobinson @oleganza Oleg

    Andreev Dan Robinson