Blockchain - Chapter 2
Introduction to Blockchain – Chapter 2
Notes
1. Building Blocks of Blockchain
Structure of Blocks
Block Size: 4 bytes, defines the size of the block.
Block Header: 80 bytes, contains metadata for validation.
Transaction Counter: Variable size, counts total transactions in a block.
Transactions: Actual transaction data stored in the block.
Structure of Block Headers
Version: Defines validation rules.
Previous Block’s Header Hash: Ensures continuity by linking to the prior block.
Merkle Root Hash: A hash of all transactions in the block for integrity verification.
Timestamp: The time when the block was created.
Difficulty Target: Defines how hard it is to mine a block.
Nonce: A variable adjusted to find a valid hash.
Genesis Block
First block in Bitcoin’s blockchain, hardcoded in the software.
Block Height: The position of a block in the chain.
Coinbase Transaction: The first transaction in a block, generating new coins.
State Blocks and Orphan Blocks
Stale Blocks: Blocks that were solved but not added due to faster solutions elsewhere.
Orphan Blocks: Blocks initially accepted but later rejected when a longer chain appears.
Cryptographic Hashes
Properties: Fixed-length, one-way encryption, deterministic, highly sensitive to input
changes, and collision-resistant.
Common Algorithms: SHA-256 (Bitcoin), Keccak-256 (Ethereum).
Block Hashes: Each block has a unique hash ensuring integrity.
2. Transactions
Overview of Transactions
Each transaction has inputs (fund sources) and outputs (destination addresses).
Transactions are digitally signed for authenticity.
UTXO Model (Unspent Transaction Output)
Transactions reference previous unspent outputs.
Transaction Fee: Calculated as the difference between inputs and outputs.
Transaction Lifecycle
1. Broadcast: Sent to the network.
2. Unconfirmed (Mempool): Awaiting miner selection.
3. Miner Confirmation: A miner adds it to a block.
4. Network Confirmation: Other miners validate it.
Transaction Fees
Determined by transaction size and network congestion.
Higher fees result in faster confirmations.
Types of Transactions
1. P2PKH (Pay to Public Key Hash) – Most common transaction type.
2. P2SH (Pay to Script Hash) – Supports smart contracts and multi-signatures.
3. MultiSig Transactions – Require multiple signatures for authorization.
4. Pay to Pubkey – Now obsolete.
5. OP_RETURN – Allows storing small data on the blockchain.
3. Merkle Trees and Merkle Roots
Merkle Root: A single hash representing all transactions in a block.
Integrity Check: Helps nodes verify transactions without downloading the full blockchain.
Structure: A binary tree where pairs of transaction hashes are combined to form a parent
hash until a single Merkle Root is formed.
4. Coinbase Transactions
First transaction in a block, rewards miners with newly minted Bitcoin.
Reward consists of:
Block Reward (newly created coins).
Transaction Fees from included transactions.
Genesis Block contained a message: "The Times 03/Jan/2009 Chancellor on brink of
second bailout for banks."
5. Consensus Mechanisms
Ensures all network participants agree on the blockchain state.
Prevents fraud and double spending.
In Bitcoin, consensus is achieved through Proof of Work (PoW).
Miners compete to solve cryptographic puzzles to add new blocks.
Summary
Blocks contain transactions and metadata for security.
Transactions follow the UTXO model and require digital signatures.
Merkle Trees ensure transaction integrity.
Coinbase Transactions reward miners and introduce new coins.
Consensus Mechanisms keep the network secure and decentralized.