B++ Logo

Proof-of-Work Mechanism

Bitcoin uses a proof-of-work consensus mechanism where miners compete to solve a cryptographic puzzle. This process secures the network and validates transactions.

How It Works

  1. Block Construction: Miners collect transactions from the mempool and create a candidate block
  2. Nonce Search: Miners repeatedly hash the block header with different nonce values
  3. Difficulty Target: The hash must be below a certain target (set by network difficulty)
  4. Success: When a miner finds a valid hash, they broadcast the block to the network
  5. Reward: The miner receives the block reward (currently 3.125 BTC) plus transaction fees

Mining Difficulty

  • Adjustment: Every 2016 blocks (~2 weeks), the difficulty adjusts based on network hash rate
  • Target: Maintains ~10 minute average block time
  • Current Network Hash Rate: ~700 EH/s (exahashes per second)
  • See Also: Difficulty Adjustment for detailed explanation

Technical Details

Block Headers

Nonce Space

  • Range: 0 to 4,294,967,295 (2^32 - 1)
  • Exhaustion: If all nonces fail, miners change the coinbase transaction or timestamp
  • Search Space: Effectively unlimited through coinbase modifications

Target Difficulty

  • Network-Wide: All miners compete against the same target
  • Dynamic: Adjusts every 2016 blocks based on actual vs. target block time
  • Purpose: Maintains consistent block production rate

Hash Function: SHA256D

Bitcoin uses a double SHA-256 hash function:

hash = SHA256(SHA256(block_header))

This means:

  1. First SHA-256 hash of the block header
  2. Second SHA-256 hash of the first hash result
  3. Result must be below the network difficulty target

SHA256D Implementation


Mining Process Flow

1. Collect Transactions
   ↓
2. Build Block Header
   ↓
3. Hash Block Header
   ↓
4. Check if Hash < Target
   ├─ Yes → Broadcast Block → Receive Reward
   └─ No → Increment Nonce → Repeat from Step 3

Educational Value

What You'll Learn

  1. Block Construction: How Bitcoin blocks are built
  2. Mining Algorithms: SHA256D hash function
  3. Network Protocol: RPC communication with Bitcoin node
  4. Difficulty Adjustment: How network difficulty works
  5. Economic Incentives: Why mining is competitive

Technical Concepts

  • Block Headers: 80-byte block metadata
  • Coinbase Transactions: Special reward transactions
  • Merkle Trees: Transaction organization
  • Nonce Space: 4.3 billion possible values
  • Difficulty Target: Network-wide mining target