For the complete documentation index, see llms.txt. This page is also available as Markdown.

Mining

Mining, Proof of Work and Difficulty Adjustment


“Proof of Work is the soul of Bitcoin: it turns energy into security.” — Cypherpunk principle


1. Introduction

The mining is the mechanism that secures the Bitcoin network by enabling:

  • Issuance of new bitcoins

  • Protection against attacks

  • Temporal ordering of transactions

  • Probabilistic consensus

  • Cumulative immutability

  • Defense against tampering

The tool that makes this possible is Proof of Work (PoW).

This chapter explains:

  • How PoW works

  • Why it makes the network secure

  • The critical role of difficulty adjustment

  • Economic incentives of miners

  • Mathematical security models

  • Potential attacks (and why they are impractical)


2. What is mining in Bitcoin?

Mining is the process by which specialized nodes:

  1. group valid transactions,

  2. compete to find a valid hash for the header,

  3. propagate the winning block to the network,

  4. receive reward (subsidy + fees).


2.1. Formal definition of PoW

A miner must find:

H(header)<TargetH(\text{header}) < \text{Target}

where:

  • H=SHA256(SHA256(x))H = SHA256(SHA256(x))

  • Target is a number that defines the difficulty

  • the probability of success is inversely proportional to the hashrate global


3. Structure of the header used in PoW

The 80-byte header is the only data subjected to PoW:

Field
Bytes
Purpose

version

4

Consensus rules

prev_block_hash

32

Chaining

merkle_root

32

Transactions

timestamp

4

Timestamp

bits

4

Target compression

nonce

4

Value that is incremented


4. The “nonce” and the search space

The miner tests billions of nonces per second.

The nonce is 32 bits → 4 billion possible values. But if it is exhausted, the miner modifies:

  • extraNonce (in coinbase)

  • merkle_root

  • timestamp

which creates a practically infinite space for PoW.


5. Difficulty: heart of economic security

Bitcoin adjusts the difficulty every 2016 blocks (~2 weeks) to maintain an average interval of:

10 minutos por bloque10 \text{ minutos por bloque}

If blocks are mined faster:

  • hashrate ↑

  • difficulty ↑

If they are mined slower:

  • hashrate ↓

  • difficulty ↓


5.1. Difficulty adjustment formula

The new difficulty is calculated as:

Dnew=Dold⋅trealtesperadoD_{new} = D_{old} \cdot \frac{t_{real}}{t_{esperado}}

where:

  • tesperado=2016⋅600=1,209,600st_{esperado} = 2016 \cdot 600 = 1,209,600 s (2 weeks)

  • trealt_{real} = actual time it took for the last 2016 blocks

Limits:

  • maximum adjustment ±4×

  • prevents exaggerated manipulation


6. The target: numerical threshold

Difficulty is an abstract value. The target is the concrete number the hash must be less than.

Target=2224−1Dificultad\text{Target} = \frac{2^{224} - 1}{Dificultad}

Simplified example:

HASH (in hex): 0000000af3c1... TARGET: 0000000fffff...

Since HASH < TARGET → valid block


7. Pseudocode example of PoW

8. Why is PoW secure?

Because it physically costs energy to generate hashes, while verifying them is trivial:

Costo de minar≫Costo de verificarCosto \ de \ minar \gg Costo \ de \ verificar

Costs for the attacker:

  • specialized hardware (ASICs)

  • electricity

  • infrastructure

  • lost economic opportunity

  • financial risk

  • social coordination

Costs for the verifier:

  • a single hash per node

  • less than 1 ms per block

8.1. Accumulated security

PoW creates a “cryptographic wall”:

Seguridad de la cadena∝PoW acumuladoSeguridad \ de \ la \ cadena \propto PoW \ acumulado

No matter how many nodes exist: security comes from the total work buried under each block.

9. Economic incentives: game theory applied

We could define mining as a strategic interaction between economic agents.

9.1. Block reward

It is composed of:

Recompensa=Subsidio+FeesRecompensa = Subsidio + Fees

Subsidy:

50×2−n50 \times 2^{-n}

where n=nuˊmero de halvingsn = número \ de \ halvings.

9.2. Aligned incentives

  • Miners → maximize profits

  • Nodes → verify rules

  • Users → want security

  • Developers → improve efficiency

Incentives are set up to favor:

  • Honesty > Attack

9.3. Why attacking the network is irrational

To rewrite old blocks you must redo all the accumulated PoW competing against all honest miners at a cost higher than the benefit.

Even an attacker with 51%:

  • cannot steal funds

  • cannot modify rules

  • cannot create inflation

  • can only reverse their own payments

And at a ruinous cost.

10. Global hashrate: security metric

Hashrate global≈TH/sHashrate \ global \thickapprox TH/s

(terahashes/second)

The higher it is, the more expensive it is to attack the network.

10.1. Conceptual example

If the network has:

300EH/s300 EH/s

(300 quintillion hashes/s)

An actor would have to match that power just to compete.

11. Mining pools

Miners usually group into pools.

Reasons:

  • reduce variance

  • stable income

  • share work

The pool:

Miners → send shares → Pool aggregates PoW → Pool produces block → Distributes reward

11.1. Does this increase centralization risk?

Yes, but not as much as it seems:

  • changing pools is trivial

  • pools do not control private keys

  • they only coordinate work

  • if they abuse, miners migrate

12. Types of hardware in the history of mining

Era
Hardware
Efficiency
Duration

2009

CPU

Very low

Months

2010

GPU

50× CPU

~1 year

2012

FPGA

10× GPU

Short

2013-present

ASIC

1,000× GPU

Dominant

ASIC = Application-Specific Integrated Circuit

13. Mathematical models of block time

Mining follows a Poisson process.

Expected time per block:

E[T]=1λE[T]= \dfrac{1}{λ}

where:

λ=dificultadhashrateλ =\dfrac{dificultad}{hashrate}

Variability: some blocks take seconds, others hours. But the long-run mean converges to ~10 minutes.

14. Attacks on the PoW system

14.1. 51% attack

Allows:

  • reversing own payments

  • censoring transactions (temporarily)

Does not allow:

  • creating bitcoins

  • stealing funds

  • breaking signatures

  • changing consensus rules

14.2. Selfish mining

Theory: miner withholds blocks to gain advantage.

Reality:

  • requires threshold > 33%

  • not very profitable

  • easy to detect

  • partially solved with BIP32, P2P improvements and topologies

14.3. Timestamp attacks

Manipulate time to adjust difficulty. Mitigation:

  • strict limits

  • allowed window ± 2h

  • nodes reject impossible timestamps

15. Why PoW is superior to PoS (according to original design)

Cypherpunk / engineering perspective:

  • Based on physics, not on wealth

  • Objective cost of attack

  • History protected with irreversible work

  • Australian Fairness → everyone can compete

  • Proven dynamics since 2009 without failures

PoW is a mechanism neutral, resilient, verifiable and politically independent.

16. Chapter conclusion

Mining and Proof of Work are:

  • The physical security layer of Bitcoin

  • The source of its immutability

  • The engine of its issuance

  • The foundation of its consensus

  • The economic barrier against attackers

PoW turns electricity into digital security. Difficulty adjustment turns fluctuations into stability. Incentives turn competition into collective protection.

Mining is not “wasting energy”. It is spending energy to prevent fraud, a military function without violence.

Last updated

Was this helpful?