bitcoin transaction scripting andy ofiesh senior software engineer armory technologies, inc. mit...
TRANSCRIPT
Bitcoin Transacti
on Scripting
Andy OfieshSenior Software EngineerArmory Technologies, Inc.
MIT Bitcoin Expo, May 3rd, 2014
© Armory Technologies, Inc. 2014
Who am I?
What have I done?
What am I doing?
© Armory Technologies, Inc. 2014
What is a Transaction?
• The Block chain has a list of Blocks
• A Block has a list Transactions (Tx)
• A Transaction has a list of Transaction Inputs (TxIn) and TransactionOutputs (TxOut)
• Each TxIn has a corresponding TxOut that it Spends. Some TxOuts are Unspent
© Armory Technologies, Inc. 2014
What is a Transaction Script?
• Transaction Scripts come in two parts.
• A TxOut Script gives the puzzle that must be solved in order to spend a TxOut.
• A TxIn Script (SigScript) gives the solution to a TxOut Script’s puzzle.
• The two parts of the transaction script are executed when you try to spend a TxOut. 1st execute your spending TxIn’s SigScript, then the spent TxOut’s Script. If there is no failure and the top of the stack is non-zero, then spending the TxOut is allowed.
© Armory Technologies, Inc. 2014
Transaction Scripting Language
• Bitcoin is not just a value transfer system. It is a programmable money system.
• Many types of contracts and escrow are possible.https://en.bitcoin.it/wiki/Contracts
• Stack-Based (Forth-like)
• Not Turing-Complete (No loops)
• Language reference:https://en.bitcoin.it/wiki/Script
© Armory Technologies, Inc. 2014
Standard Transaction Scripts
• There 4 different Standard Transaction Types
– Pay to Public Key (P2PK, generally used for mined Bitcoins)
– Pay to Public Key Hash (P2PKH)
– Multi-Signature M-of-N (MultiSig)
– Pay to Script Hash (P2SH)
© Armory Technologies, Inc. 2014
Non-Standard Transaction Scripts
• There are many valid scripts that are not standard.
• Most miners only mine standard scripts, but a few will mine non-standard scripts by request.
• Most Bitcoin nodes won’t even forward non-standard transactions to peers.
• Putting a non-standard transaction into a P2SH TxOut script makes the TxOut standard– Spending this TxOut is still non-standard, but that’s the
receiver’s problem
• Testnet considers all scripts standard.– Great for testing and bitcoin puzzles
© Armory Technologies, Inc. 2014
Tools
• Block Chain Info
• Bitcoin Armory Application
• Armory Python Scripting Tools– https://bitcoinarmory.com/developers/python-scripting/
• BitcoinD Command Line
• BitcoinJ– https://code.google.com/p/bitcoinj/
• Jeff Garzik’s – python-bitcoinlib– https://bitcointalk.org/index.php?topic=150436.0
© Armory Technologies, Inc. 2014
Pay to Public Key Hash Example
© Armory Technologies, Inc. 2014
TxOut Script - 76 a9 14 9fde...4abe 88 ac
TxIn Script - 49 3046...b101 41 04c8...eb79
OP_DUP OP_HASH160 Push 20 Public Key Hash OP_EQUALVERIFY OP_CHECKSIG
Push ~73 bytes – DER Encoded Signature Push 65 (or 33) bytes – Public Key
Signature Signature
Public Key
Signature
Public Key
Public Key
Signature
Public Key
Pub Key Hash
Signature
Public Key
Pub Key Hash
Pub Key Hash
Signature
Public Key
OP_TRUE
Multi Signature
© Armory Technologies, Inc. 2014
TxOut Script - 52 41 041...6c84 41 04db...8751 41 043b...d649 53 ae
TxIn Script - 00 48 3045...9c01 49 3046...e601
OP_2 Push 65 (or 33) bytes – Public Key (times 3) OP_3 OP_CHECKMULTISIG
Push ~73 bytes – DER Encoded Signature (times 2)
OP_FALSE
Signature
Signature
OP_TRUE
OP_FALSE
OP_FALSE
Signature
Signature
OP_FALSE
OP_2
Signature
Signature
OP_FALSE
OP_2
Pub Key Hash
Pub Key Hash
Pub Key Hash
OP_3
Signature
Signature
OP_FALSE
OP_2
Pub Key Hash
Pub Key Hash
Pub Key Hash
Pay to Script Hash Example
© Armory Technologies, Inc. 2014
TxOut Script - a9 14 1451...dbc0 87
OP_HASH160 Push 20 Public Key Hash OP_EQUAL
Signature
Serialized Script
Script Hash
TxIn Script - 48 3045...9c01 49 3046...e601 4c c9 5241...53ae
Push ~73 bytes – DER Encoded Signature (times 2) Push 201 bytes - Serialized Script
Signature
Signature
Signature
Serialized Script
Signature
Signature
OP_TRUE
Serialized Script
Signature
Signature
Script Hash
Serialized Script
Signature
Signature
Script Hash
MIT Expo Bitcoin Puzzles by Armory
• 1 Bitcoin Treasure Hunt – Get Handout– https://blockchain.info/tx/6804a732fe2ca7a653b2a30580d2f035750114e02d5e1841512274b1eb45008a
• Total of 1 Bitcoin can be collected by solving all of these on Testnet:
– http://blockexplorer.com/testnet/tx/4ad79d6373431defd0de6459368f7e295d674aa316293fc4a0b249567fb0f889
– http://blockexplorer.com/testnet/tx/c5c6b5582ff9d572296e7af3d6821f103f88386ee9f77ffae78c2db45816b80e
– http://blockexplorer.com/testnet/tx/fb6839158e862a660d7d37cc1437805bbd4ad81d00fae28b9f58c72393c8a166
– http://blockexplorer.com/testnet/tx/e83e207c0400df52785c2999785b25ea65f5e6ca5643caa6347f62d715b85777
– http://blockexplorer.com/testnet/tx/2d931ffc545e9e42612d38cd6a8aa013256c9dedad3bc069336f9f6347abbd80
• For helpful links and other resources visit:https://bitcoinarmory.com/developers/mit-expo/
• For questions and to submit Testnet solutions send email to [email protected]© Armory Technologies, Inc. 2014