Introduction to bit coin

Post on 15-Jan-2015

252 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

RSVP for Data Science Classes at www.nycdatascience.com

Transcript

NYC Data Science Academy

Introduction to BitCoin

NYC Data Science Academy

P2P: Peer-to-Peer Network

A peer-to-peer (P2P) network is a type of

decentralized and distributed network

architecture in which individual nodes in the

network (called "peers") act as both suppliers

and consumers of resources, in contrast to the

centralized client–server model where client

nodes request access to resources provided by

central servers.

Peers are distributed in the whole Internet. It is

hard to control and monitor the network

activities. It is widely used in fields asking for

high privacy.

A P2P network

A network based on the client-server

model

NYC Data Science Academy

BitCoin

The fundamental paper by Satoshi Nakamot

Feature: Based on algorithm and public recognition, Decentralized

Scarcity, Mining, SHA256, Easy to exam, limit of speed

Comparing to Gold. Does bitcoin worth it?

Is BitCoin a Ponzi Scheme?

BitCoin and Anarchism

Problems: Copycats, Deflation, Anti-Conservation

How to maintain and manage the P2P network?

NYC Data Science Academy

Blueprint of Electronic Money

NYC Data Science Academy

Duplicated transactions

Solution: An authorized organization to record and exam transactions

A Mint is an organization that produce valid electronic money(avoid

duplicated transactions). Receiver of a transaction need to send electronic

money back to the mint for validation.

Pitfall: Relying too much on the central organization (Breakdown, Attacked,

Manipulated, Monitored or Spied)

NYC Data Science Academy

Basic Concepts: the system of Bitcoin

Block: account book

Transaction

Bitcoin

Item: record of transactions

Transactions are recorded by Items

A block consists of many items (and other data)

Many blocks form a chain

Iterate over the items in the block chain to check account balance and

transaction validity,

NYC Data Science Academy

Experiment: Check a block

http://blockexplorer.com/

Enter your block number to see the data

NYC Data Science Academy

What is inside a Block?

NYC Data Science Academy

Transaction

NYC Data Science Academy

Block

Bitcoin system only record blocks but not balance. Balance is calculated

from items (records of transactions) in blocks

Every block stores all the items from all over the world in ten minutes. And

there will be a new block every ten minutes. The speed is stable.

Number of items in a block is not stationary

Every node is producing block but the valid block is unique. We will talk

about it later.

An ideal block:Block IDItem 1,Item 2,...Item n

Previous Block ID,Next Block ID,Other Information

NYC Data Science Academy

Block Chain

Blocks are connected by doubly linked list according to their generation

order. This structure is convenient for iteration.

Every node is storing a block chain. Finally these chains are all the same,

as the only valid one in the system.

The 1st Block

Block IDPrev IDNext ID

The 2nd Block

Block IDPrev IDNext ID

The 3rd Block

Block IDPrev IDNext ID

NYC Data Science Academy

Bitcoin and block generation

How to create Bitcoin: generate blocks (Fierce competitions of the

generation, that is what we called 'Mining' .)

Rules: the first to the 210 thousand-th block worth 50 Bitcoins each, the

210 thousand-th to the 420 thousand-th block woth 25 Bitcoins, and so on.

Repeating this procedure, we will get in total 21Million Bitcoins.

Because the real-world is always expanding, Bitcoin is determined to meet

the problem of deflation.

Blocks will be generated cotinuously, because transactions will be charged

for the service.

NYC Data Science Academy

Security

Private key and Public key, digital signature

SHA256: http://en.wikipedia.org/wiki/SHA-2

NYC Data Science Academy

Security

Private key and Public key, digital signature

SHA256: http://en.wikipedia.org/wiki/SHA-2

NYC Data Science Academy

Security

Enough money for the transaction (Solved)

Authenticity of transaction

Repeat Transactions

NYC Data Science Academy

Authenticity of transaction: Digital Signature

NYC Data Science Academy

Calculate a hash number a, from all the data of block A.

Store a in the next block B.

Verify that if A is the previous block of B: Calculate a from A again, then

compare to the hash number x stored in B.

Generate b from B and store it in C. Then we repeat this process and will

get a block chain.

Duplicated Transactions: Timestamp

Block

Previous hash number x

Item Item Item Item

Block

Previous hash number x

Item Item Item Item

NYC Data Science Academy

Timestamp

Do not rely on the local time, only related to the order of blocks

If there's a center maintaining the chain of valid blocks, it would be easy to

check duplicated transactions.

How to achieve it in a decentralized network?

NYC Data Science Academy

Problems of P2P

Various network condition

Nodes are not running 24/7

No center for management

May exist evil nodes

NYC Data Science Academy

Bitcoin solution of P2P

Proof of Work

Controlling of block generation speed

Block broadcast and valid block chain

NYC Data Science Academy

Proof of Work

1. Calculate a hash number from the latest block

2. Keep receive items that are broadcasted but not inside any blocks. Check

them and delete invalid ones(not enough money).

3. Randomly choose a number, Nounce.

4. Group data in step 1~3 and use SHA256 to calculate a 256bit hash number

x.

5. Verify if there are enough leading 0s in x. If yes, then verify if this x meets

the difficulty. If yes, then this process is finished.

6. Else, repeat from step 2. If there's a new block from other nodes, we need

to restart the whole process.

NYC Data Science Academy

Difficulty of Proff-of-Work

https://en.bitcoin.it/wiki/Difficulty

NYC Data Science Academy

Difficulty

Controlling the speed of block generation. Updated every 2016 blocks (2

weeks) .

Difficulty = maximum_target / current_target

The target is a 256-bit number (extremely large) that all Bitcoin clients

share. The SHA-256 hash of a block's header must be lower than or equal to

the current target for the block to be accepted by the network. The lower the

target, the more difficult it is to generate a block.

Max target:

00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Current target (this is changing):

0000000000000000B3AA0000000000000000000000000000000000000000

0000

NYC Data Science Academy

Bits

Each block stores a packed representation (called "Bits") for its actual

hexadecimal target. The target can be derived from it via a predefined

formula. For example, if the packed target in the block is 0x1b0404cb, the

hexadecimal target is

0x0404cb * 2**(8*(0x1b - 3)) =

0x00000000000404CB00000000000000000000000000000000000000000

0000000

NYC Data Science Academy

Difficulty is a Global parameter

If there's the only valid block chain, every node will get the same difficulty.

Difficulty is controlling the speed of block generation

Difficulty is also useful when checking a block's validity.

NYC Data Science Academy

Meaning of Difficulty

Control the speed and avoid inflation. A rapid increase in computation

power is not affecting the generation speed.

Increase the cost of cheating.

The P2P netword need a lot of nodes to ensure the security (avoid

manipulation). Difficulty is what drives nodes running.

NYC Data Science Academy

Temporal Block

Content of the block:

1. x genereted from SHA256, as the block ID

2. All the collected valid items

3. Random Number n

4. The latest hash number from the global block chain

5. Other informations

Broadcast this block to the P2P network

What will other nodes do:

Duplication transactions and Validation

NYC Data Science Academy

Validation

Get items in the block

Check if there's duplicated items

Other validation steps

Link this block to the end of the locally stored 'Global Block Chain' . It is not

formally added to the global block chain yet.

NYC Data Science Academy

Braches

A node will receive many new blocks generated from a common global

chain.

For each block, generate braches locally.

Nodes are receiving blocks in different time points, and this leads to

different local braches.

When there comes a longer chain, a node will turn to the longer one and

discard the shorter one.

This algorithms will ensure the convergence to the longest chain.

NYC Data Science Academy

Example of Braches

The Green block is the 1st block of the world.

Black blocks represents the longest block

chain, and validated to be the global chain.

Grey blocks are blocks on local braches, and

discarded finally.

NYC Data Science Academy

Example of Braches

1. The form of two braches.

2. The right brach receive a new block and we discard the left one.

3. Again, different blocks linked to the end of global chain.

NYC Data Science Academy

Example of Braches

4. Firstly we receive two more blocks on the right brach

5. And another two blocks on the left brach, now these two

braches are still of the same length.

6. Receive another block and we finally discards the right

one.

NYC Data Science Academy

Example of Braches

7. The left brach receives another block.

8. Another one added to the left branch.

NYC Data Science Academy

Example of Braches

Finally, we have our longest block chain.

NYC Data Science Academy

Confirm the Transaction

To confirm a transaction, we need to add it to a newly generated block, and

after 5 more blocks, this transaction could be finally confirmed and the

transaction is successfully recorded.

After 6 blocks added to the global chain, it is nearly impossible to cheat or

attack the original chain. The cheater cannot find a cluster that

overwhelms all the other honest nodes and add 6 more fake blocks to the

global chain.

Once the transaction is confirmed, it is almost impossible to modify or

cancel.

NYC Data Science Academy

Summary of security of Bitcoin

All nodes in a P2P network monitor and save the global unique transaction

backup

Timestamp ensure the order of blocks is valid

SHA256 ensure the generation of a block is hard, but validation is easy.

Proof-of-Work ensure the majority (honest nodes) have the true transaction

record.

NYC Data Science Academy

Problems of Bitcoin system

Privacy

Transaction needs a lot of time to be confirmed

Deflation

Anti Conservation

Increasing amount of data

NYC Data Science Academy

Bitcoin in Action!

How to register?

How to mine?

How to trade Bitcoin?

How to pay with Bitcoin?

NYC Data Science Academy

The official website

https://bitcoin.org/en/

NYC Data Science Academy

What? There's official website?

https://bitcoin.org/en/about-us

NYC Data Science Academy

Bitcoin Wallet

MultiBit

NYC Data Science Academy

Need Screenshot from Mac or just demonstration in real time

Need Screenshot from Mac or just demonstration in real time

NYC Data Science Academy

Bitcoin Miner

GUIMiner

NYC Data Science Academy

Popular Mining Website

Deepbit

BTCGuild

BMP

NYC Data Science Academy

Need Screenshot from Mac or just demonstration in real time

Need Screenshot from Mac or just demonstration in real time

NYC Data Science Academy

Bitcoin exchange

Mt.Gox: It was the largest website, but closed in February 2014.

BTC-E: https://btc-e.com/

Bitstamp: https://www.bitstamp.net/

NYC Data Science Academy

Pay with Bitcoin

Bitcoin is told to be the best currency for illegal missions.

But publicly it is not very popular.

Donate bitcoin to personal projects is more popular. As in the popular game

2048.

NYC Data Science Academy

FAQ

FAQ

top related