Share
Embed
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
Transcript
58 slides
-
Introducing TxVM Cathie Yun, Software Engineer J A N U
A R Y 2 5 , 2 0 1 8 -
Chain builds ledger services for financial institutions. Underlying technology: transactions
on a blockchain. Supports high transaction volumes, issued assets, and smart contracts. Background -
Bitcoin Existing approaches Ethereum Two popular blockchains use different models
for transactions and contracts. -
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 -
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 -
Transactions and contracts are imperative. Ethereum nonce gas price data
destination amount signature start gas -
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 -
BTC Introducing TxVM EVM TxVM deterministic & isolated expressive language
safe environment ✔ ✔ ✔ ✔ ✔ ✔ ✘ ✘ ✘ -
Transaction is the program: executes contracts, controls value flow and
provides signatures. TxVM version runlimit program -
Executing the program produces a deterministic transaction log. TxVM version
runlimit program input transaction log input input output output utxo set -
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. -
Example ride-sharing transaction First-class Values 1. Operations preserve "law of
conservation” 2. Objects must be cleared from the VM by the end -
Example ride-sharing transaction rider $15 First-class Values 1. Operations preserve
"law of conservation” 2. All objects must be cleared from the VM -
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 -
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 -
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 -
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 -
Impossible application violating rule #1 First-class Values 1. Operations preserve
"law of conservation” 2. All objects must be cleared from the VM -
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 -
$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 -
$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 -
Invalid transaction violating rule #2 First-class Values 1. Operations preserve
"law of conservation” 2. All objects must be cleared from the VM -
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 -
$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 -
$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 -
$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 -
$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 -
$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 -
$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 -
TxVM internals 31 1 VM parts 2 VM rules stacks
tx log runlimit code empty stacks tx is finalized runlimit not exceeded no failures -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
New output contract Locks the value and creates an output.
get_value [put_value [txid <pubkey> get_sig checksig verify] put_contract] output C3 -
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 -
New output contract Locks the value and creates an output.
$15 txvm stack get_value [ ]output C3 C2 tx log Input $5 Input $10 -
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 -
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 -
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 -
• 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