Bitcoin & Blockchain Overview
Published:
What is blockchain?
What is a block?
- Persistent, immutable and append-only data structure
- Block used as currency tracks
- User transactions
- Timestamp
- Reference
- A block (besides the genesis block) is tied to it’s previous block in a cryptographic way
- Each block contains
- Header
- One or more user’s transactions ![Simplified Bitcoin Blockchain]
3 Building block of blockchain
1. Decentralized Network
- P2P Architecture
- Nodes can join and leave freely
- Information are sent between nodes to maintain the ledger
2. Distributed Consensus
- Used to add block to the blockchain
- Diferent type of consensus protocol (E.g. PoW, PoS, PoET)
3. Cryptographic
- Hash Function
- DIgital signature
Consensus protocol
:abcd: Consensus Protocol Components
- Message Passing Rule
- How component broadcast and relay messages
- E.g. Fully connected network
- Processing Rule
- How a component changes its internal state in response of received message
- Goal -> All component agree on the same subject
:loudspeaker: Type of Conensus Protocols
Proof of Work (PoW)
- Used in Bitcoin
- A node’s proof of it’s computation effort by solving a cryptographic puzzle
- A node with a higher computation power usually yields a higher probability of solving the puzzle
Proof of Stake (PoS)
- Maintain a set of validators
- Validators participate by depositing an amount of currency
- Bigger stake holder have a higher chance of winning
- E.g. Chain-based Pos, BFT-style PoS
Proof of Elapsed Time (PoET)
- Validator is selected by random
- Each validator is trusted and verified by all others
- Validator is verified by hardware
Cryptographic Hash Function
- Used in process of creating digital signature (Authenticity, Integrity)
- Used to create cryptographic puzzles in PoW (Consensus)
- Create a address for users
- A mathematic transformation that convert message -> Digest
- The output is fixed length but the input can be a variable length
- Requirement, for $H(X) = Y$
- Computationally Efficient to find $Y$ for a given $X$ and $H$ function
- Collision Resistant - Hard to find $X_1$ and $X_2$ such that $H(X_1) = H(X_2) = Y$
- Same input always yields same result
- Computationally hard to find $X$ for a given $Y$
Digital Signature
Bitcoin
Nakamoto Consensus Protocol (Bitcoin)
- Finality - For every block added to the blockchain, the drop of probability asymptotically decreases to zero
- Agreement - Block is either accepted or drop off by all honest nodes.
- Validity - If all nodes received the same valid block, this block should be accepted into the blockchain
- Hash-chain integrity - The hash value of the of block $B\prime$ with block number $t+1$ has the hash value $pf$ previous block $B$ with block number $t$
:100: Validation of a block
- Validation of all the transaction in the block
- Verification of the hash value
:cop: Four rules for a single node
- Message passing rule Generated or received block should be
broadcast to peers in a timely manner
- Validation rule Blocks and transaction need to be validated before being broadcast to peers or append to blockchain
- Longest-chain rule Longest chain is always the desired chain
- Proof of Work (PoW) Generating block include
inserting a nonce
into the header. The higher the PoW difficulty, the more hashing operation needed.PoW difficulty is automatically adjusted
so that the average block generation interval of the network remains a constant value
:currency_exchange: How does Bitcoin actually work?
Digital signatures
- Hash function: SHA-256
- Signature Algorithm: Elliptic Curve Digital Signature Algorithm (ECDSA)
- Used to sign transations
Transaction records
- Transactions consist of one or more inputs and two outputs(Out and change)
- Out -> To the payee
- Change -> Back to the payer
Transaction records and Merkle Tree
- A single block store multiple transaction in a form of Merkle Tree
- Each node is a hash of it’s children
- The root hash node ensure node of the transaction on the leaf node could be modify
Proof of Work
- Find $X$ in $H(X) < Y$ with brute force for $H$ is SHA-256
- $Y$ is a string with a pre-determined number of leading zero bits
- To keep the block generate at a constant speed(every 10 minutes), the proof-of-work difficulty is adjusted based on the average speed of block.
- The increase in number of leading zeros in $Y$ will increase by the diffificulty exponentially.
Example of proof-of-work
- PoW require nodes to solve for a hash with brute force
- Hash for block #775,771 is 00000000000000000003aa2696b1b7248db53a5a7f72d1fd98916c761e954354
- The noice was 2,881,347,934
- The block reward for that successful hash was 6.25 BTC and 0.1360 BTC in fees
Transaction block chain
Lifecycle of a Bitcoin Transaction
Bob send 3 bitcoin to Alice
Bob->Network: How many bitcoin do I have?
Note right of Network: Verify Bob's previous transactions
Network->Bob: You have 5 bitcoin
Note left of Bob: Set Alice as payee
Note left of Bob: Set 3 bitcoin output amount
Note left of Bob: Set 2 bitcoin change amount
Note left of Bob: Sign with Bob's private key
Bob->Network: Send transaction
Note right of Network: Check transaction with Bob's pubkey
Note right of Network: Attached transaction to block
Note right of Network: Miner found nonce
Note right of Network: Verify nonce
Note right of Network: Block added to block chain
Alice->Network: Transaction from Bob?
Network->Alice: Exist
Question
- In the last page of the slides, it stated that digital coins have a unique ID. Do Bitcoin have a unique ID?
- In Bitcoin, when finding $X$, does nonce always start with zero and work it’s way up?
- When validatating transaction in a block, are we checking the transactions with the sender’s public key?
- How does the network check the previous transactions of Bob?
- The bitcoin paper only mention how to store the header but not the transaction of a block. Full node and lite node
References
- https://www.ledger.com/academy/blockchain/what-is-proof-of-work
- https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm
Next week
- Unspend transaction output
- Read the two papers sent by prof