> For the complete documentation index, see [llms.txt](https://www.notbank.com/learn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.notbank.com/learn/academy/en/bitcoin/security.md).

# Security

***

> “Bitcoin is a security castle built with layers of economic incentives.”\
> — *Attributed to Dan Held*

***

## 1. Introduction

Bitcoin is the most secure computer system on the planet in terms of resistance to digital, economic, and political attacks.\
It achieves its security through:

* **Strong cryptography**
* **Proof of Work**,
* **Resilient P2P topology**
* **Consensus rules**
* **Economic incentives**
* **Non-cooperative game theory**
* **Physical costs of attack**

This chapter analyzes:

* Theoretical and real attack vectors
* Defense via PoW and nodes
* Limits of security
* Economic and social attacks
* Consensus dynamics
* Mathematics of probabilistic security
* Adversary scenarios

***

## 2. Bitcoin security model

Bitcoin follows a security model **probabilistic**, not deterministic.\
It does not guarantee absolute certainty, but rather **increasing certainty over time**.

### 2.1. Probabilistic security of consensus

The probability that an attacker reorganizes (z) blocks decreases exponentially:

<p align="center"><span class="math">P(z) = \sum_{k=0}^{\infty} \frac{\lambda^k e^{-\lambda}}{k!} \left( \frac{q}{p} \right)^k</span></p>

where:

* $$q$$ = attacker's hashrate
* $$p$$ = honest hashrate
* $$\lambda = z \cdot \frac{q}{p}$$

For $$q < 0.5$$, the probability becomes negligible after 6 confirmations.

***

### 2.2. Multilayer security

Bitcoin has **5 layers of security**:

1. **Cryptographic** → signatures, hashes
2. **Economic** → incentives, rewards
3. **Energy** → PoW
4. **P2P Network** → antiseptic topology
5. **Social / consensus** → independent nodes

***

## 3. Classic attacks on the blockchain

### 3.1. 51% attack

Attacker obtains >50% of the hashrate.

Can:

* reorganize N blocks
* reverse their own payments
* temporarily censor transactions

Cannot:

* forge bitcoins
* steal others' funds
* break ECDSA
* change rules

Estimated cost of the attack:

<p align="center"><span class="math">\text{Costo} \approx \text{Hashrate global} \times \text{Precio electricidad} \times \text{Tiempo}</span></p>

Conclusion: **economically suicidal**.

***

### 3.2. Double-spend attacks

Type A: **Race attack**\
Type B: **Finney attack**\
Type C: **Vector 76**\
Type D: **Deep reorg** (requires massive PoW)

Bitcoin mitigates through:

* successive confirmations
* accumulated PoW
* honest nodes
* fast propagation

***

### 3.3. Eclipse attacks (node isolation)

Goal: isolate a node and control all the information it receives.

Mitigation:

* redundant connections
* geographic diversity
* random addressing
* anti-Sybil rules
* P2P protocol improvements (BIP155)

***

### 3.4. Censorship attacks

Miners may attempt to exclude transactions:

But:

* pools are replaceable
* individual miners switch pools
* market competition
* economic incentives (fees)
* node relay

Outcome: large-scale censorship → impractical.

***

## 4. Economic attacks

### 4.1. Selfish mining (Eyal & Sirer, 2013)

Theory: a miner hides blocks to amplify their reward.

Requires >33% of the hashrate to be profitable.

Mitigated by:

* faster block propagation
* natural penalty
* improved network topology
* against honest strategies

***

### 4.2. Spying / pool-hopping

Miners jump between pools based on reward probability.

Effect: reduces efficiency of poorly designed pools.\
The global system is not affected.

***

### 4.3. State-level economic attack

A State could attempt to:

* subsidize electricity
* buy massive hardware
* censor blocks internationally

Problems:

* astronomical cost
* specialized hardware hard to manufacture
* detectable attacks
* difficult political coordination
* nodes can reject invalid blocks

***

## 5. Network and P2P layer attacks

### 5.1. Sybil attacks

Create thousands of fake nodes to influence the network.

Mitigations:

* PoW limits useful identities
* random topology
* full nodes verify everything
* no voting → multiple identities do not grant power

***

### 5.2. DDoS attacks

Attempt to saturate nodes:

* rate limiting
* automatic disconnection
* protected mempool
* dynamic TTL

Bitcoin Core incorporates defenses by design.

***

## 6. Cryptographic attacks

### 6.1. Breaking SHA-256

Currently: **impractical**.

Even with quantum computing:

* Grover reduces the complexity of $$2^{256}$$ to $$2^{128}$$
* still impossible to break in reasonable times

***

### 6.2. Breaking ECDSA

Theoretical quantum threat (Shor's algorithm).

Natural mitigation:

* public keys not revealed until spent
* possible future transition to post-quantum signatures
* soft-fork for new schemes

Bitcoin is prepared to upgrade if necessary.

***

## 7. Consensus security

Bitcoin is not democratic.\
Rules are not voted on.\
Nodes **verify** immutable rules.

### 7.1. Who decides the rules?

1. **Users run full nodes**
2. Nodes accept or reject blocks
3. Miners *cannot* impose invalid rules
4. Developers do not control nodes
5. Exchanges also do not control rules

It is a system of **emergent consensus**, not imposed.

***

### 7.2. Hard forks vs soft forks

* **Soft fork** → restrictive, compatible changes
* **Hard fork** → changes rules, creates new chain

Bitcoin favors soft forks (BIP9, BIP8, Speedy Trial).

***

## 8. Game theory applied

Bitcoin implements a game of incentives:

| Player         | Goal             | Strategy                  |
| -------------- | ---------------- | ------------------------- |
| Miners         | Maximize revenue | Mine honestly             |
| Nodes          | Security         | Reject invalid blocks     |
| Users          | Ownership        | Choose honest nodes       |
| Pool operators | Fees             | Coordinate work           |
| Attackers      | Profit           | Attack → prohibitive cost |

Nash equilibrium:

> Mining honestly is the dominant strategy.

***

## 9. Mathematical models of security

### 9.1. Probability of deep reorg

<p align="center"><span class="math">P = \left( \frac{q}{p} \right)^z</span></p>

If $$q = 0.1$$ and $$z = 6$$:

<p align="center"><span class="math">P = (0.1)^6 = 10^{-6}</span></p>

***

### 9.2. Energy cost of the attack

<p align="center"><span class="math">Costo = H_{red} \cdot E \cdot t</span></p>

Where:

* $$H\_{red}$$  hashrate
* $$E$$  cost per hash
* $$t$$  time

Cost far exceeds possible benefits.

***

## 10. Social and political attacks

The most dangerous:

* anti-Bitcoin propaganda
* regulatory pressure
* attempts at prohibition
* intimidation of miners
* blocking exchanges

But Bitcoin resists:

* private nodes → impossible to shut down
* mobile miners → global relocation
* liquidity outside exchanges
* extreme decentralization

***

## 11. Emergent security of the ecosystem

### 11.1. Full nodes

Nodes enforce:

* block size
* valid signatures
* correct scripts
* consensus rules
* accumulated PoW
* heaviest chain
* valid timestamps

Miners **do not command**; nodes verify.

***

### 11.2. Mempool: defense against invalid transactions

The mempool discards:

* double spends
* transactions without fees
* out-of-range transactions
* malformed data

***

## 12. Chapter conclusion

Bitcoin's security is the combination of:

* unbreakable cryptography,
* alliances of economic incentives,
* physical costs of attack,
* distributed consensus,
* independent verifying nodes,
* adversarial game theory,
* emergent immutability.

Bitcoin is not secure by “luck”:\
it is secure because **it designs incentives so that attacking is more expensive than defending**.

***

> Bitcoin's security is not based on trusting anyone.\
> It is based on that, even if someone wanted to attack, **they could not afford it**.

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.notbank.com/learn/academy/en/bitcoin/security.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
