SlideShare a Scribd company logo
1 of 29
Class 15:
Scripting
Transactions
Cryptocurrency Cabal
cs4501 Fall 2015
David Evans and Samee Zahur
University of Virginia
Plan for Today
Scripting Transactions
Review/PS2
1
Reminders
Extra office hours (see notes)
Midterm Wednesday (in class)
Problem Set 3
2
https://github.com/bitcoin/bitcoin/blob/v0.1.5/script.cpp#L41
3
https://github.com/bitcoin/bitcoin/blob/v0.1.5/script.cpp#L58
4https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp
5https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp
Interpreting Script
6
https://github.com/bitcoin/bitcoin/blob/41e6e4caba9899ce7c165b0784461c55c867ee24/src/script/interpreter.cpp#L524
7
https://github.com/bitcoin/bitcoin/blob/41e6e4caba9899ce7c165b0784461c55c867ee24/src/script/interpreter.cpp#L524
Version 0.1
Project idea: look at how bitcoin
core code has evolved over time
Latest
8
9
Vout: ([]btcjson.Vout) (len=2 cap=4) {
(btcjson.Vout) {
Value: (float64) 229,
N: (uint32) 0,
ScriptPubKey: (btcjson.ScriptPubKeyResult) {
Asm: (string) (len=85) "OP_DUP OP_HASH160
d6980467719f0e93e9742b6389e09117b6b630a3 OP_EQUALVERIFY OP_CHECKSIG",
Hex: (string) (len=50) "76a914d6980467719f0e93e9742b6389e09117b6b630a388ac",
ReqSigs: (int32) 1,
Type: (string) (len=10) "pubkeyhash",
Addresses: ([]string) (len=1 cap=4) {
(string) (len=34) "PsVSrUSQf72X6GWFQXJPxR7WSAPVRb1gWx"
}
}
},
10
OP_DUP
OP_HASH160
d6980467719f0e93e9742b6389e09117b6b630a3
OP_EQUALVERIFY
OP_CHECKSIG
OP_DUP [x] Duplicates the top stack item
OP_HASH160 [x] Replaces top of stack with RIPEMD160(SHA256([top]))
OP_EQUALVERIFY [x1] [x2] If top two items are equal, outputs True;
otherwise, marks transaction as Invalid.
OP_CHECKSIG [pubkey] [sig] Checks that E_pubkey(sig)([entire transaction])
LockingScript
11
12
OP_DUP
OP_HASH160
d6980467719f0e93e9742b6389e09117b6b630a3
OP_EQUALVERIFY
OP_CHECKSIG
LockingScriptUnlockingScript
Unlocking Script
13
Unlocking Script
14
<signature>
<pub key>
โ€œPay-to-Script-Hashโ€
15
OP_HASH160
[20-byte hash]
OP_EQUAL
LockingScript
Unlocking/Locking (pre-2010)
16
OP_DUP
OP_HASH160
<bitcoin address (hash of public key)>
OP_EQUALVERIFY
OP_CHECKSIG
LockingScript
<signature>
<public key>
UnlockingScript
OP_RETURN
17
Original meaning: terminate script execution, leaving stack unchanged.
https://github.com/bitcoin/bitcoin/blob/v0.1.5/script.cpp#L170
Steal any output!
18
OP_DUP
OP_HASH160
<bitcoin address (hash of public key)>
OP_EQUALVERIFY
OP_CHECKSIG
LockingScriptUnlockingScript
Steal any output!
19
OP_DUP
OP_HASH160
<bitcoin address (hash of public key)>
OP_EQUALVERIFY
OP_CHECKSIG
LockingScriptUnlockingScript
This is the by far biggest bug in bitcoin (discovered so far!).
OP_RETURN (fixed July 2010)
20
https://github.com/btcsuite/btcd/blob/c153596542b3d87dd774c29aa5be5117ac01a234/txscript/opcode.go#L1239
https://github.com/bitcoin/bitcoin/blob/41e6e4caba9899ce7c165b0784461c55c867ee24/src/script/interpreter.cpp#L397
Actual Scripts in Bitcoin
21
22
(first 290,000 blocks, through 2014-03-11)
23
OP_RETURN
OP_DATA_40
More Powerful Scripts
24
OP_CHECKMULTISIG [x] [sig]k [pub key]k
valid := 0
for each signature [1, k]:
if checksig(sigk, pubk): valid += 1
if valid >= x: 1
else: 0
Has this Changed?
25
26
https://github.com/SabaEskandarian/CryptocurrencyProject
Saba
Eskandarianโ€™s
project last
semester
27
Charge
Wednesday: Midterm
Upcoming office hours:
Today: 5-6:30 (Ori, Rice 442)
Tomorrow: 2-3:30pm (Dave, Rice 507)
Tomorrow: 3:30-4:30pm (Samee, Rice 442)
28

More Related Content

Similar to Scripting Transactions

How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
Javier Lafora Rey
ย 
Staring into the eBPF Abyss
Staring into the eBPF AbyssStaring into the eBPF Abyss
Staring into the eBPF Abyss
Sasha Goldshtein
ย 

Similar to Scripting Transactions (20)

Script
ScriptScript
Script
ย 
utf.pdf
utf.pdfutf.pdf
utf.pdf
ย 
Git'in in 15
Git'in in 15Git'in in 15
Git'in in 15
ย 
Systems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting StartedSystems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting Started
ย 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)
ย 
Fun with Github webhooks: verifying Signed-off-by
Fun with Github webhooks: verifying Signed-off-byFun with Github webhooks: verifying Signed-off-by
Fun with Github webhooks: verifying Signed-off-by
ย 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
ย 
3DC Intro to Git Workshop
3DC Intro to Git Workshop3DC Intro to Git Workshop
3DC Intro to Git Workshop
ย 
Bitcoin protocol for developerBitcoin Protocol for Developers
Bitcoin protocol for developerBitcoin Protocol for DevelopersBitcoin protocol for developerBitcoin Protocol for Developers
Bitcoin protocol for developerBitcoin Protocol for Developers
ย 
Staring into the eBPF Abyss
Staring into the eBPF AbyssStaring into the eBPF Abyss
Staring into the eBPF Abyss
ย 
Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profit
ย 
Andrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profitAndrea Righi - Spying on the Linux kernel for fun and profit
Andrea Righi - Spying on the Linux kernel for fun and profit
ย 
Pseudo-versions, moving to Go1.13 and later versions
Pseudo-versions, moving to Go1.13 and later versionsPseudo-versions, moving to Go1.13 and later versions
Pseudo-versions, moving to Go1.13 and later versions
ย 
No more dead kittens - Clean Code
No more dead kittens - Clean CodeNo more dead kittens - Clean Code
No more dead kittens - Clean Code
ย 
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
ย 
How to make the calculator
How to make the calculatorHow to make the calculator
How to make the calculator
ย 
Migrating from Subversion to Git and GitHub
Migrating from Subversion to Git and GitHubMigrating from Subversion to Git and GitHub
Migrating from Subversion to Git and GitHub
ย 
Automated Dependency Updates with Renovate
Automated Dependency Updates with RenovateAutomated Dependency Updates with Renovate
Automated Dependency Updates with Renovate
ย 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
ย 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
ย 

More from David Evans

More from David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
ย 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
ย 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
ย 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
ย 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
ย 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
ย 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
ย 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
ย 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
ย 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
ย 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
ย 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
ย 
Silk Road
Silk RoadSilk Road
Silk Road
ย 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
ย 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
ย 
Alternate Cryptocurrencies
Alternate CryptocurrenciesAlternate Cryptocurrencies
Alternate Cryptocurrencies
ย 
Selfish Mining
Selfish MiningSelfish Mining
Selfish Mining
ย 
Quiz 2: Bitcoin Protocol, Mining, Supsersizing
Quiz 2: Bitcoin Protocol, Mining, SupsersizingQuiz 2: Bitcoin Protocol, Mining, Supsersizing
Quiz 2: Bitcoin Protocol, Mining, Supsersizing
ย 
Mostly About Superfish
Mostly About SuperfishMostly About Superfish
Mostly About Superfish
ย 
Mining Pools and Profits
Mining Pools and ProfitsMining Pools and Profits
Mining Pools and Profits
ย 

Recently uploaded

VIP Model Call Girls Shivane ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Shivane ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Shivane ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Shivane ( Pune ) Call ON 8005736733 Starting From 5K to ...
SUHANI PANDEY
ย 
VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...
SUHANI PANDEY
ย 
VIP Model Call Girls Alandi ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Alandi ( Pune ) Call ON 8005736733 Starting From 5K to 2...VIP Model Call Girls Alandi ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Alandi ( Pune ) Call ON 8005736733 Starting From 5K to 2...
SUHANI PANDEY
ย 
VIP Call Girls Vapi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Vapi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Vapi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Vapi 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
ย 
All Types๐Ÿ‘ฉOf Sex Call Girls In Mohali 9053900678 Romance Service Mohali Call ...
All Types๐Ÿ‘ฉOf Sex Call Girls In Mohali 9053900678 Romance Service Mohali Call ...All Types๐Ÿ‘ฉOf Sex Call Girls In Mohali 9053900678 Romance Service Mohali Call ...
All Types๐Ÿ‘ฉOf Sex Call Girls In Mohali 9053900678 Romance Service Mohali Call ...
Chandigarh Call girls 9053900678 Call girls in Chandigarh
ย 
VIP Model Call Girls Wadgaon Sheri ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Wadgaon Sheri ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Wadgaon Sheri ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Wadgaon Sheri ( Pune ) Call ON 8005736733 Starting From ...
SUHANI PANDEY
ย 
The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1
davew9
ย 
Call Girls In Tilak Nagar๊งโค ๐Ÿ” 9953056974๐Ÿ”โค๊ง‚ Escort ServiCe
Call Girls In  Tilak Nagar๊งโค ๐Ÿ” 9953056974๐Ÿ”โค๊ง‚ Escort ServiCeCall Girls In  Tilak Nagar๊งโค ๐Ÿ” 9953056974๐Ÿ”โค๊ง‚ Escort ServiCe
Call Girls In Tilak Nagar๊งโค ๐Ÿ” 9953056974๐Ÿ”โค๊ง‚ Escort ServiCe
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 

Recently uploaded (20)

ฮฆฮ‘ฮ“ฮ—ฮคฮŸ ฮคฮ•ฮ›ฮ•ฮ™ฮŸ ฮžฮžฮžฮžฮžฮžฮž ฮžฮžฮžฮžฮžฮž ฮžฮžฮžฮž ฮžฮžฮžฮž ฮž
ฮฆฮ‘ฮ“ฮ—ฮคฮŸ ฮคฮ•ฮ›ฮ•ฮ™ฮŸ ฮžฮžฮžฮžฮžฮžฮž ฮžฮžฮžฮžฮžฮž ฮžฮžฮžฮž ฮžฮžฮžฮž ฮžฮฆฮ‘ฮ“ฮ—ฮคฮŸ ฮคฮ•ฮ›ฮ•ฮ™ฮŸ ฮžฮžฮžฮžฮžฮžฮž ฮžฮžฮžฮžฮžฮž ฮžฮžฮžฮž ฮžฮžฮžฮž ฮž
ฮฆฮ‘ฮ“ฮ—ฮคฮŸ ฮคฮ•ฮ›ฮ•ฮ™ฮŸ ฮžฮžฮžฮžฮžฮžฮž ฮžฮžฮžฮžฮžฮž ฮžฮžฮžฮž ฮžฮžฮžฮž ฮž
ย 
Top Rated Pune Call Girls Yashwant Nagar โŸŸ 6297143586 โŸŸ Call Me For Genuine ...
Top Rated  Pune Call Girls Yashwant Nagar โŸŸ 6297143586 โŸŸ Call Me For Genuine ...Top Rated  Pune Call Girls Yashwant Nagar โŸŸ 6297143586 โŸŸ Call Me For Genuine ...
Top Rated Pune Call Girls Yashwant Nagar โŸŸ 6297143586 โŸŸ Call Me For Genuine ...
ย 
VIP Model Call Girls Shivane ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Shivane ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Shivane ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Shivane ( Pune ) Call ON 8005736733 Starting From 5K to ...
ย 
5th Annual International OMGD Grand Chapitre: A Spanish Wine Journey
5th Annual International OMGD Grand Chapitre: A Spanish Wine Journey5th Annual International OMGD Grand Chapitre: A Spanish Wine Journey
5th Annual International OMGD Grand Chapitre: A Spanish Wine Journey
ย 
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
ย 
(ISHITA) Call Girls Service Navi Mumbai Call Now 8250077686 Navi Mumbai Escor...
(ISHITA) Call Girls Service Navi Mumbai Call Now 8250077686 Navi Mumbai Escor...(ISHITA) Call Girls Service Navi Mumbai Call Now 8250077686 Navi Mumbai Escor...
(ISHITA) Call Girls Service Navi Mumbai Call Now 8250077686 Navi Mumbai Escor...
ย 
VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...
ย 
VIP Model Call Girls Alandi ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Alandi ( Pune ) Call ON 8005736733 Starting From 5K to 2...VIP Model Call Girls Alandi ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Alandi ( Pune ) Call ON 8005736733 Starting From 5K to 2...
ย 
Russian Call Girls in Nagpur Devyani Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Devyani Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Devyani Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Devyani Call 7001035870 Meet With Nagpur Escorts
ย 
VIP Call Girls Vapi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Vapi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Vapi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Vapi 7001035870 Whatsapp Number, 24/07 Booking
ย 
Top Rated Pune Call Girls JM road โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls JM road โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls JM road โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls JM road โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Ser...
ย 
All Types๐Ÿ‘ฉOf Sex Call Girls In Mohali 9053900678 Romance Service Mohali Call ...
All Types๐Ÿ‘ฉOf Sex Call Girls In Mohali 9053900678 Romance Service Mohali Call ...All Types๐Ÿ‘ฉOf Sex Call Girls In Mohali 9053900678 Romance Service Mohali Call ...
All Types๐Ÿ‘ฉOf Sex Call Girls In Mohali 9053900678 Romance Service Mohali Call ...
ย 
The Most Attractive Pune Call Girls Tingre Nagar 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Tingre Nagar 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Tingre Nagar 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Tingre Nagar 8250192130 Will You Miss Thi...
ย 
Food & Nutrition Strategy Baseline (FNS.pdf)
Food & Nutrition Strategy Baseline (FNS.pdf)Food & Nutrition Strategy Baseline (FNS.pdf)
Food & Nutrition Strategy Baseline (FNS.pdf)
ย 
Low Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur Escorts
Low Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur EscortsLow Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur Escorts
Low Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur Escorts
ย 
VIP Model Call Girls Wadgaon Sheri ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Wadgaon Sheri ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Wadgaon Sheri ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Wadgaon Sheri ( Pune ) Call ON 8005736733 Starting From ...
ย 
Week 5 Dessert Accompaniments (Cookery 9)
Week 5 Dessert Accompaniments (Cookery 9)Week 5 Dessert Accompaniments (Cookery 9)
Week 5 Dessert Accompaniments (Cookery 9)
ย 
Book Paid Chakan Call Girls Pune 8250192130Low Budget Full Independent High P...
Book Paid Chakan Call Girls Pune 8250192130Low Budget Full Independent High P...Book Paid Chakan Call Girls Pune 8250192130Low Budget Full Independent High P...
Book Paid Chakan Call Girls Pune 8250192130Low Budget Full Independent High P...
ย 
The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1
ย 
Call Girls In Tilak Nagar๊งโค ๐Ÿ” 9953056974๐Ÿ”โค๊ง‚ Escort ServiCe
Call Girls In  Tilak Nagar๊งโค ๐Ÿ” 9953056974๐Ÿ”โค๊ง‚ Escort ServiCeCall Girls In  Tilak Nagar๊งโค ๐Ÿ” 9953056974๐Ÿ”โค๊ง‚ Escort ServiCe
Call Girls In Tilak Nagar๊งโค ๐Ÿ” 9953056974๐Ÿ”โค๊ง‚ Escort ServiCe
ย 

Scripting Transactions