Blockchain for Dummies Documentation
Total Page:16
File Type:pdf, Size:1020Kb
Blockchain for Dummies Documentation Nguyen Tran Ho Thanh Son Jul 03, 2018 Contents 1 Contents 3 1.1 Blockchain and Bitcoin.........................................3 1.1.1 What is a blockchain?......................................3 1.1.2 What is the difference between Bitcoin and Blockchain?...................3 1.1.3 What is Bitcoin?........................................3 1.1.4 How Bitcoin works?......................................4 1.1.4.1 Transactions......................................4 1.1.4.2 Independent Verification of Transactions.......................5 1.1.4.3 Aggregation of Verified Transactions.........................5 1.1.4.4 Constructing a Block Header.............................6 1.1.4.5 Mining of a Block...................................7 1.1.4.6 Finding the Puzzle- Why is it hard?..........................7 1.1.4.7 Difficulty Representation...............................7 1.1.4.8 Successfully Mining the Block............................8 1.1.4.9 Independent Confirmation of Each Block.......................8 1.1.4.10 Assembling and Selecting Chains of Blocks.....................8 1.1.4.11 Miners Reward....................................9 1.1.4.12 Several Branches...................................9 1.1.4.13 What if Someone tries to Hack the System?..................... 11 1.1.5 Bitcoin’s network in one infographic.............................. 13 1.2 Frequently Asked Questions....................................... 14 1.2.1 Questions............................................ 14 1.2.1.1 Who is in control of Bitcoin?............................. 14 1.2.1.2 How does one acquire bitcoins?............................ 14 1.2.1.3 What does “synchronizing” mean and why does it take so long?........... 15 1.2.1.4 What is a consensus algorithm and why is it useful in blockchain?......... 15 1.2.1.5 What is the difference between a public and private/consortium blockchains?.... 15 1.2.1.6 If the Bitcoin’s database is on my computer, can I add 1000 of BTC in my wallet?. 16 1.2.1.7 Why do I have to wait for confirmation?....................... 16 1.2.1.8 How much will the transaction fee be?........................ 16 1.2.1.9 What if I receive a bitcoin when my computer is powered off?............ 17 1.2.1.10 How does mining help secure Bitcoin?........................ 17 1.2.1.11 What do I need to start mining?............................ 17 1.2.1.12 Hasn’t Bitcoin been hacked in the past?........................ 17 1.3 Glossary................................................. 18 i ii Blockchain for Dummies Documentation The goal of this documentation is to introduce you to blockchain technology. The content of the document is copied and collected on internet. It’s just for study purpose. Contents 1 Blockchain for Dummies Documentation 2 Contents CHAPTER 1 Contents 1.1 Blockchain and Bitcoin 1.1.1 What is a blockchain? A Blockchain is a kind of database: while a normal database is located on a server, a blockchain is distributed among the software users. For example, the Facebook’s database is located on a protected server and no one can access the information. The Bitcoin’s blockchain instead is located on servers and computers (called nodes) of all the Bitcoin users. All the transactions that occur between ewallets are stored on the bitcoin’s blockchain. All the servers and the com- puters that are using bitcoin have the same copy of the blockchain stored on their hard disk. There are many kinds of blockchain with different features, like Ethereum, Hyperledger, Ripple. Some of them are more suitable to handle currency, others are used to transfer the ownership of assets (eg supply chain). You don’t need to download all the blockchain to your computer in order to use Bitcoin (or any other blockchain technology) as the current size of Bitcoin’s blockchain is over 160 GB and it can easily drain the resources of your computer. To avoid this issue there are different types of e-wallets (we will talk about them later). Source: http://www.ledgerprojects.com/blockchain-for-dummies/ 1.1.2 What is the difference between Bitcoin and Blockchain? Blockchain is the technology behind Bitcoin: Bitcoin cannot exist without a blockchain. It is like Internet and Facebook: Facebook cannot exist without Internet. Source: http://www.ledgerprojects.com/blockchain-for-dummies/ 1.1.3 What is Bitcoin? Simply put, bitcoin is a digital currency. No bills to print or coins to mint. It’s decentralized – there’s no government, institution (like a bank) or other authority that controls it. Owners are anonymous; instead of using names, tax IDs, or 3 Blockchain for Dummies Documentation social security numbers, bitcoin connects buyers and sellers through encryption keys. And it isn’t issued from the top down like traditional currency; rather, bitcoin is “mined” by powerful computers connected to the internet. Source: https://www.cnet.com/how-to/what-is-bitcoin/ 1.1.4 How Bitcoin works? 1.1.4.1 Transactions Let’s try to understand how blockchain works with a simple transaction over a Blockchain network. Suppose James wants to send 5 BTC to his friend Kevin. Now, this transaction is broadcasted in the form of a digital message. The digital message has a unique signature. Just like your signature provides the proof of ownership of the document, similarly, digital signature provides the proof that the transaction is genuine. Now this generated transaction is broadcasted to the network where it propagates peer to peer. Suppose the above transaction is first received by node A in the network. 4 Chapter 1. Contents Blockchain for Dummies Documentation 1.1.4.2 Independent Verification of Transactions Before sending transactions to its neighbors, each bitcoin node that gets the transaction will initially verify the trans- action. This guarantees only valid transactions are propagated across the system while invalid transactions are disposed of at the first node which receives them. Every node confirms each transaction against a long agenda of criteria. 1.1.4.3 Aggregation of Verified Transactions Independent aggregation of those transactions into new blocks by mining nodes combined with exhibited calculation through a proof-of-work algorithm. 1.1. Blockchain and Bitcoin 5 Blockchain for Dummies Documentation • By autonomously confirming every transaction as it is received and before propagating it, each node fabricates a pool of valid (however unconfirmed) transactions known as the transaction pool, memory pool or mempool • Transaction reaches Mining nodes it collects, validates, and relays new transactions just like other nodes • Unlike other nodes, miner node will then aggregate these transactions into a candidate block Let’s understand this better with an example. Let’s say Andy is a miner. (A mining node maintains a local copy of the blockchain, the list of all blocks created since the beginning of the bitcoin system in 2009) Now, after collecting all the transactions in a block, Andy needs to construct the block header. Now this step is important to understand how blockchain works 1.1.4.4 Constructing a Block Header To construct the block header, the mining node needs to fill in six fields, as listed in the table: Size Field Description 4 bytes Version To construct the block header, the mining node needs to fill in six fields, as listed 32 bytes Previous Block A reference to the hash of the previous (parent) block in the chain Hash 32 bytes Merkle Root A hash of the root of the Merkle tree of this block’s transactions 4 bytes Timestamp The approximate creation time of this block (seconds from Unix Epoch) 4 bytes Difficulty Target The proof-of-work algorithm difficulty target for this block 4 bytes Nonce A counter used for the proof-of-work algorithm 6 Chapter 1. Contents Blockchain for Dummies Documentation Once Andy’s node has all the fields filled in the block header, Andy started Mining the block. 1.1.4.5 Mining of a Block • With all the other fields filled, the block header is now complete and the process of mining can begin • The goal is now to find a value for the nonce that results in a block header hash that is less than the difficulty target • The mining node will need to test billions or trillions of nonce values before a nonce is found that satisfies the requirement Now that a candidate block has been constructed by Andy’s node, it is time for Andy’s hardware mining rig to “mine” the block, to find a solution to the proof-of-work algorithm that makes the block valid. Proof of work is a piece of data which is difficult(costly, time-consuming) to produce but easy for others to verify and which satisfies certain requirements. 1.1.4.6 Finding the Puzzle- Why is it hard? • The SHA-256 is a one-way function(hash) hence, brute force is the only way to a particular output value • On an average, it takes many random guesses to find a solution and thus the challenge is tough • It takes around 10 minutes on an average for someone to find the special key to the solution To keep the coin distribution predictable, puzzles becoming increasingly difficult to solve when more people work on them. Now, to validate the block according to the proof-of-work algorithm, Andy’s mining node has to reach the difficulty target. Let’s see how the difficulty is represented. 1.1.4.7 Difficulty Representation • The block contains the difficulty target, in a notation called “difficulty bits” or just “bits“ • Let’s say a block has 0x1903a30c as the difficulty bits. This notation expresses the difficulty target as a coeffi- cient/exponent format, with the first two hexadecimal digits for the exponent and the next six hex digits as the coefficient 1.1. Blockchain and Bitcoin 7 Blockchain for Dummies Documentation The formula to calculate the difficulty target from this representation is: So, such is the difficulty coefficient that Andy’s mining node has worked really hard to reach the difficulty target.