William Liu

Bitcoin Basics


##Table of Contents

##Summary

Bitcoin is an online peer-to-peer currency. Alice wants to give another person, Bob, an infocoin. Let’s walkthrough how we could implement this/what the Bitcoin Protocol is.

##Iteration 1

Alice uses a string of bits as a primitive form of money. She writes “I, Alice, am giving Bob one infocoin”. She then signs with a private cryptographic key and announces this to the world.

##Iteration 2

Sign with a serial number to fix duplication. Alice writes “I, Alice, am giving Bob an infocoin with serial number 1111123”

##Iteration 3

Eliminate the bank, make everyone the bank. Everyone keeps a block chain that is a public ledger of transactions.

##Iteration 4

This last iteration is closer to what Bitcoin is. It’s made up of:

  1. proof-of-work is a hard computational puzzle that artifically makes it computationally costly for network users to validate transactions
  2. users mine (get rewards) users for trying to help validate transactions

This makes it so that a cheater would need enormous computational resources to cheat (thus impractical). We no longer rely on the number of people on the network, but focuses on the total computational power they bring.

Users need to solve the proof-of-work puzzle or else the network won’t accept it as a valid transaction.

####Proof of Work

Bitcoin uses a SHA-256 hash function. An example proof-of-work may be adding say a nonce (e.g. 0) to the end of the actual text (e.g. “hello world”):

h("hello world0") = fjdskal43242jkfdldajkll34jlksfdl

We would keep incrementing the nonce (e.g. 1, 2, 3) until we find a result that has say 4 starting zeroes

h("hello world4323") = 0000fjlaj24jlkdssfajl4j3jllfj

The actual Bitcoin network is a little more sophisticated and can adjust how difficult the target (e.g. the number of zeroes needed) is so that it averages about 10 minutes to validate. We can also require multiple puzzles to be solved.

####Mining

The validation process is called mining. For every block of transactions validated, the user gets a bitcoin reward. A 10^-8 bitcoin is the minimial unit of Bitcoin and is called a satoshi. As another reward besides mining, there can also be a minimal transaction fee that goes to the people helping validate.

####Order

We want an order to see which transactions have occurred first. Without an order, we won’t know who owns what infocoins. New blocks always include a pointer to the last block validated in the chain (in addition to the list of transactions in the block).

Sometimes there’s a fork in the block chain, which means two miners validated and broadcasted to the entire network at the same time. To resolve this, new miners are assigned the longest fork. A valid fork needs at least 5 blocks following.

####Issues

Alice can still double spend by paying herself and Charlie in an inprobable scenario; say Charlie accepts the infocoin (which happens after the transaction has been confirmed 6 times in the longest chain), and somehow Alice has so much computing power to overpower the network so that her fork is the longest. Again this is unlikely, but possible.

##Bitcoin

To use bitcoin, you install a wallet program (e.g. Multbit). This shows you how many bitcoins you have. If you’re a merchant that allows people to pay using Bitcoin, you tell your wallet program to generate a Bitcoin address; this creates a public/private key pair where the public key is a result of hashing your public key. E.g. Address: 17jfdkaljklfdasjlfsajl

  1. You send your Bitcoin address to the person who wants to buy from you.
  2. The person who wants to pay you generates a transaction
    • This includes an identifier for the transaction
    • Version number of Bitcoin
    • Number of inputs and outputs
    • Any lock_time (when can the transaction be finalized); usually 0 (i.e. immediately)
    • Input of the transaction (e.g. signature of person sending the money, corresponding public key)
    • Note: there is nothing explicitly specifying how many bitcoins should be spent in this transaction (like trying to buy bread with 20 dollars and can’t break that down)
    • Output of the transaction (i.e. how many bitcoins are we spending?)

Instead of creating a serial number from a central area, users self-generate a transaction id by hashing the transaction.

####Bitcoin Exchange

A Bitcoin exchange is like a bank where you deposit money and can buy or sell bitcoins when it reaches a certain amount.