Mechanics S5
Mechanics S5
and Cryptocurrencies
Prof. Murtuza Jadliwala
[email protected]
.
2 Inputs: 1[1]
Outputs: 6.0→Carol, 2.0→Bob
SIGNED(Alice)
..
.
3 Inputs: 1[0], 2[1]
Outputs: 19.0→Bob
SIGNED(Bob)
.
2 Inputs: 1[1]
Outputs: 6.0→Carol, 2.0→Bob
SIGNED(Alice)
..
.
3 Inputs: 2[0], 2[1]
two signatures!
Outputs: 8.0→David
SIGNED(Carol), SIGNED(Bob)
Sum of all output values less than or equal to sum of all input values!
If sum of all output values less than sum of all input values, then difference
goes to miner as a transaction fee
Bitcoin scripts
Output “addresses” are really scripts
OP_DUP
OP_HASH160
69e02e18...
OP_EQUALVERIFY OP_CHECKSIG
Input “addresses” are also scripts
(from the redeeming transaction)
30440220...
scriptSig
0467d2c9...
OP_EQUALVERIFY Returns true if inputs are equal, false (marks transaction invalid)
otherwise
OP_CHECKSIG Checks that the input signature is valid using input public key for
the hash of the current transaction
OP_CHECKMULTISIG Checks that t signatures on the transaction are valid from t (out
of n) of the specified public keys
OP_CHECKMULTISIG
• Built-in support for joint signatures
• Specify n public keys
• Specify t
• Verification requires t signatures are valid
BUG ALERT: Extra data value
popped from the stack and
ignored
Bitcoin script execution example
✓
<pubKeyHash?>
<pubKey>
<pubKeyHash>
<pubKey>
<sig>
true
OP_RETURN
<arbitrary data>
Should senders specify scripts?
?
I’m ready to pay for my purchases! Big Box
<signature>
<signature>
<<pubkey> OP_CHECKSIG>
OP_HASH160
<pubkey>
<hash of redemption script>
OP_CHECKSIG
OP_EQUAL
To: Alice
From: Bob
“Smart contracts”
Bitcoin blocks
Bitcoin blocks
H( )
H( )
Hash tree (Merkle tree) of
transactions in each block H( ) H( )
H( ) H( )
3
6
2
4
Transaction propagation (flooding)
Already
heard that!
5
1
7
A→B
8
A→B A→B
A→B
New tx! 3
6 A→B A→B
A→B 2
A→B
A→B A→B
4
A→B
Should I relay a proposed transaction?
• Transaction valid with current block chain(default)
• Run script for each previous output being redeemed and
ensure that script returns true!
• Script matches a whitelist
• Avoid unusual scripts Sanity checks only...
• Haven’t seen before Well-behaving nodes implement them!
Some nodes may ignore them!
• Avoid infinite loops
• Doesn’t conflict with others I’ve relayed
• Avoid double-spends
Nodes may
New tx! differ on transaction pool
A→C
A→C 5
1 A→C A→B
A→C
A→C 7
A→B
A→C
8
A→B
A→B
3
6 A→B
A→B 2
A→B
4
A→B
Race conditions
Transactions or blocks may conflict
• Default behavior: accept what you hear first
• Network position matters
• Miners may implement other logic!
Stay tune for the lecture on mining!
Block propagation nearly identical
Relay a new block when you hear it if:
• Block meets the hash target
• Block has all valid transactions
• Run all scripts, even if you wouldn’t relay
• Block builds on current longest chain
• Avoid forks
Sanity check
Also may be ignored...
Source: Yonatan Sompolinsky and Aviv Zohar: “Accelerating Bitcoin’s Transaction Processing” 2014
How big is the network?
• Impossible to measure exactly
• Estimates-up to 1M IP addresses/month
• Only about 5-10k “full nodes”
• Permanently connected
• Fully-validate
• This number may be dropping!
Fully-validating nodes
• Permanently connected
• Store entire block chain
• Hear and forward every node/transaction
Storage costs (in 2014)
20 GB
Storage costs (in 2018)
160 GB
Source: blockchain.info
Tracking the UTXO set
• Unspent Transaction Output
• Should be stored in memory - everything else can be
stored on disk, why?
65 M
Source: blockchain.info
Tracking the UTXO set
• Currently ~65 M UTXOs
• Out of 300 M transactions
• Can require several Gigabytes to store – can it fit in the RAM of a standard
computer?
300 M
Source: blockchain.info
Thin/SPV clients (not fully-validating)
SPV – Simplified Payment Verification (e.g., Wallet nodes)
Compare to:
• VISA: 2,000-10,000 transactions/sec
• PayPal: 50-100 transaction/sec
Cryptographic limits in Bitcoin
• Only 1 signature algorithm (ECDSA/P256)
• Hard-coded hash functions
7
Block 23
24
That’s 8
crazy talk!! Block
That’s
Block 24
23
24 crazy talk!!
I found a nifty 3
6 24 new block! Block
Block 23
24
Block 23 2
Block 23
24
24
4 PROBLEM: Old nodes will never
Block 23
24
catch up
Soft forks
Observation: we can add new features which only limit
the set of valid transactions
<signature>
<<pubkey> OP_CHECKSIG>
OP_HASH160
<hash of redemption script>
OP_EQUAL
Old nodes will just approve the hash, not run the
embedded script
Soft fork possibilities
• New signature schemes
• Extra per-block metadata
• Shove in the coinbase parameter
• Commit to UTXO tree in each block
Hard forks
• New op codes
• Changes to size limits
• Changes to mining rate
• Many small bug fixes