Lecture 4: Blockchains

80 bytes block consists of 32 bytes previous block hash, 32 bytes transactions Merkle tree hash, timestamp, bits, nonce, etc. Each block is <= 1MB to minimize the propagation times. Therefore, large transactions require more service fee to compensate miners to include the transaction in the block.

Miner’s transaction checks
  1. ScriptSig (from spending transaction) || ScriptPubKey (from funding transaction) executes and this should produce non-empty stack. Empty stack or zero is false.
  2. Transaction inputs are in the UTXO set.
  3. Sum of all outputs <= Sum of all inputs

As of Oct 2016, 43M UTXO, 475K unique addresses, and 15.9M BTC in circulation.

Transaction signature is over the whole transaction (except the signature itself) => miners cannot modify any portion of the transaction. P2PKH (Pay to public key hash) does not reveal the public key (but only its hash), this provides added security in terms of someone brute-forcing the public key. The signature scheme ECDSA does not have strong unforgeability which means that miner can change ECDSA pair (r, s) to (r, s’). This changes the transaction hash. Therefore, transaction hashes cannot be relied upon. Not knowing this fact lead to Mt. Gox collapse.  Segregated Witness, eventually, fixed this by moving signatures out of the transaction hash.

There are two types of transactions

  1. Pay to Public Key hash (P2PKH)
  2. Pay to script hash (P2SH)
    Funding transaction scriptPk: HASH160 H()  EQUAL  # Only hash of the script is exposed at the funding time
    Spending transaction scriptSig: <sig1> <sig2> ….<sigN> <redeemScript>
    Miner verifies that

    1. ScriptSig | ScriptPk -> true => script is correct
    2. ScriptSig -> true => script is satisfied
      This is different from what miner does for P2SH

Another example of P2SH is multi-sig: m out of n signatures required.
Redeem script: <2> <pk1> <pk2> <pk3> <3> CHECKMULTISIG
Bitcoin implement is buggy so it eats the first element of the ScriptSig, therefore, add a dummy first element <0>
ScriptSig: <0> <sig1> <sig3> <redeemScript>
Applications of multi-sig =>

  1. Co-signatory – 2 out of 2 signatures required
  2. Escrow – buyer will fund a 2-out-3 signatures transaction which two of the buyer, seller, and judge’s signatures.
  3. Micropayments – which accumulate and send together to save on the transaction fee.

Bitcoin Address

Base 58 – a-z, A-Z, 0-9 excluding {0,o, i, l} => 34 char addresses

Addresses for P2PKH starts with 1.
Addresses for P2SH starts with 3.