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

TxVM: A New Design for Blockchain Transactions

Cathie Yun
January 24, 2018

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. Chain builds ledger services for financial institutions. Underlying technology: transactions

    on a blockchain. Supports high transaction volumes, issued assets, and smart contracts. Background
  2. 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
  3. 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
  4. 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
  5. BTC Introducing TxVM EVM TxVM deterministic & isolated expressive language

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

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

    runlimit program input transaction log input input output output utxo set
  8. 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.
  9. Example ride-sharing transaction First-class Values 1. Operations preserve "law of

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

    "law of conservation” 2. All objects must be cleared from the VM
  11. 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
  12. 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
  13. 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
  14. 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
  15. Impossible application violating rule #1 First-class Values 1. Operations preserve

    "law of conservation” 2. All objects must be cleared from the VM
  16. 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
  17. $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
  18. $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
  19. Invalid transaction violating rule #2 First-class Values 1. Operations preserve

    "law of conservation” 2. All objects must be cleared from the VM
  20. 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
  21. $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
  22. $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
  23. $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
  24. $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
  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 rider company $1 driver $2 driver $2 ✔ ✔ 1. Operations preserve "law of conservation” 2. All objects must be cleared from the VM
  27. TxVM internals 31 1 VM parts 2 VM rules stacks

    tx log runlimit code empty stacks tx is finalized runlimit not exceeded no failures
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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
  33. 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
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. 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
  42. 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
  43. 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
  44. 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
  45. 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
  46. New output contract Locks the value and creates an output.

    get_value [put_value [txid <pubkey> get_sig checksig verify] put_contract] output C3
  47. 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
  48. New output contract Locks the value and creates an output.

    $15 txvm stack get_value
 [ ]output C3 C2 tx log Input $5 Input $10
  49. 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
  50. 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
  51. 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
  52. • 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