Bitcoin Mechanics_ part 2
Bitcoin Mechanics_ part 2
Mechanics of Bitcoin
Recap: Bitcoin consensus
Bitcoin consensus gives us:
● Append-only ledger
● Decentralized consensus
● Miners to validate transactions
Bitcoin transactions
An account-based ledger (not Bitcoin)
time
might need to
Create 25 coins and credit to AliceASSERTED BY MINERS scan backwards
until genesis!
Transfer 17 coins from Alice to BobSIGNED(Alice)
Transfer 8 coins from Bob to CarolSIGNED(Bob)
Transfer 5 coins from Carol to AliceSIGNED(Carol)
is this valid?
Transfer 15 coins from Alice to DavidSIGNED(Alice)
4 Inputs: 2[1]
is this valid?
Outputs: 6.0→David, 2.0→Alice
SIGNED(Alice)
2 Inputs: 1[1]
Outputs: 6.0→Carol, 2.0→Bob
SIGNED(Carol)
...
3 Inputs: 1[0], 2[1]
Outputs: 19.0→Bob
SIGNED(Bob)
2 Inputs: 1[1]
Outputs: 6.0→Carol, 2.0→Bob
SIGNED(Carol)
...
3 Inputs: 2[0], 2[1]
two signatures!
Outputs: 8.0→David
SIGNED(Carol), SIGNED(Bob)
Bitcoin scripts
Output “addresses” are really scripts
OP_DUP
OP_HASH160
69e02e18...
OP_EQUALVERIFY OP_CHECKSIG
Input “addresses” are also scripts
scriptSig
30440220...
0467d2c9...
OP_DUP
scriptPubKey
OP_HASH160
69e02e18...
OP_EQUALVERIFY OP_CHECKSIG
TO VERIFY: Concatenated script must execute completely with no errors
Bitcoin scripting language (“Script”)
Design goals
● Built for Bitcoin (inspired by Forth)
● Simple, compact I am not impressed
● Support for cryptography
● Stack-based
● Limits on time/memory
● No looping
image via Jessie St. Amand
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
“Smart contracts”
Lecture 3.4:
Bitcoin blocks
Bitcoin blocks
H( ) H( )
}
The real deal: coinbase transaction
"in":[
{
Null hash pointer
"prev_out":{
redeeming "hash":"000000.....0000000",
nothing
"n":4294967295
}, First ever coinbase parameter:
arbitrary
"coinbase":"..." “The Times 03/Jan/2009 Chancellor
}, block reward
on brink of second bailout for banks”
"out":[
transaction fees
{
"value":"25.03371419",
"scriptPubKey":"OPDUP OPHASH160 ... ”
}
See for yourself!
7
getaddr() getaddr()
1, 7 getaddr()
8
3
6
2
4
Transaction propagation (flooding)
Already
5 heard that!
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) script matches a whitelist
○ Avoid unusual scripts
● Haven’t seen before Sanity checks only...
○ Avoid infinite loops Some nodes may ignore them!
A→C 5
1 A→C A→B
A→C
A→C 7
A→C A→B
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 our 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
20 GB
Tracking the UTXO set
● Unspent Transaction Output
○ Everything else can be stored on disk
● Currently ~12 M UTXOs
○ Out of 44 M transactions
● Can easily fit into RAM
Thin/SPV clients (not fully-validating)
Idea: don’t store everything
● Store block headers only
● Request transactions as needed
○ To verify incoming payment
● Trust fully-validating 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 23
24 That’s
Block
24 crazy talk!!
I found a nifty 3
6 24 new block! Block
Block 23
24
Block 23 2
Block 23
24
24
4
Block 23
24 PROBLEM: Old nodes will never 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
Currently seem very unlikely to happen