Project 2 Part 2 is due tomorrow (Thursday, 5 March).
Submission is by email, send a PDF with your answers to questions 5-9.
Keep thinking about ideas for your project. The first deliverable for the project will be a preliminary proposal due on March 19.
Enjoy your Spring Break!
Transaction outputs in bitcoin are protected by locking scripts, and must be unlocked by unlocking scripts. The scripts are written in a simple (compared to, say, the Java Virtual Machine language, but quite complex and poorly specified for what one might expect would be needed for bitcoin transactions) stack-based language. A transaction output is not unlocked unless an unlocking script is provided such that the result of executing the unlocking script, followed by executing the locking script, is a stack with value True on top (and no invalid transaction results during the execution).
Some script instructions:
||-||1||Pushes a 1 (True) on the stack|
||a||a a||Duplicates the top element of the stack|
||a b||(a+b)||Pushes the sum of the top two elements.|
||a b||0 or 1||Pushes 1 if the top two elements are exactly equal, otherwise 0.|
||a||-||If a is not True (1), terminates as Invalid.|
||-||-||Terminates as Invalid.|
||a b||-||If a and b are not equal, terminates as Invalid.|
||a||H(a)||Pushes bitcoin address, RIPEMD(SHA256(a)).|
Some more complex instructions:
OP_ENDIF - If the top of the stack is 1, executes [statements]. Otherwise does nothing.
OP_CHECKSIG - Pops two items from the stack, publickey and sig.
Verifies the entire transaction (known from node state, not the stack)
using the publickey and sig. If the signature is valid, push 1;
OP_1 OP_DUP OP_ADD OP_DUP OP_SUB OP_VERIFY
The most common locking script (send to public address):
OP_DATA20 (bitcoin address)
What must be on the stack for the locking script to succeed (end with 1 on top of stack)?
What must be on the stack for the locking script above ("Pay-to-Script-Hash") to succeed?
According to Most Popular Transaction
(analysis of all transactions in first 290,000 blocks), the ninth most popular script is:
What must be on the stack for the
OP_RETURN OP_DATA_40 locking script to succeed (end with
1 on top of stack)? (Trick question: what happens to the coin
protected by this locking script?)
Is the bitcoin scripting language Turing-complete?
If you are not clear on what Turing-complete means, see Dori-Mic and the Universal Machine!
Type: Script is the virtual machine the executes scripts (note that it has two Stacks)
Bitcoin Core Code
Some interesting things you can do with bitcoin scripts:
Contracts (see also Nick Szabo's Formalizing and Securing Relationships on Public Networks
Secure Multiparty Computations (to implement lotteries)
OP_RETURN/pasted script execution bug doesn't even make this list of The 9 Biggest Screwups in Bitcoin History.