# 驗證

### 驗證（Verification）是區塊鏈節點檢查交易和區塊是否符合規則的過程。這就像銀行櫃檯人員核對你的身份和帳戶餘額——只不過在區塊鏈上，每個節點都是櫃檯，每筆交易都要經過所有人的檢查。

***

## 為什麼需要驗證？

區塊鏈沒有中央權威，所以每個節點都要自己驗證：

* **不能相信別人說的**：礦工可能作弊，節點可能被駭
* **Trust, but verify**：自己跑一遍規則才安心
* **去中心化的代價**：每個節點都做重複的工作

{% hint style="info" %}
**「Don't trust, verify」**

這是比特幣社群的名言。意思是不要相信任何人告訴你的，自己運行節點來驗證一切。
{% endhint %}

***

## 驗證什麼？

### 交易驗證

| 檢查項目  | 說明          |
| ----- | ----------- |
| 數位簽名  | 確認是帳戶持有人發起的 |
| 餘額足夠  | 確認有錢可以轉     |
| 格式正確  | 交易資料符合規範    |
| 無雙重支付 | 同一筆錢沒有花兩次   |

### 區塊驗證

| 檢查項目  | 說明          |
| ----- | ----------- |
| 工作量證明 | 哈希值符合難度要求   |
| 前區塊連結 | 正確指向前一個區塊   |
| 時間戳   | 時間合理、沒有來自未來 |
| 區塊大小  | 沒有超過上限      |
| 交易有效  | 區塊內所有交易都合法  |
| 獎勵正確  | 礦工沒有多拿區塊獎勵  |

***

## 驗證的過程

```
收到新區塊
    ↓
檢查區塊頭（PoW、時間戳、連結）
    ↓
逐筆驗證區塊內交易
    ↓
全部通過？
   ↓ 是              ↓ 否
接受區塊           拒絕區塊
寫入本地鏈       丟棄、標記節點
```

{% hint style="warning" %}
**驗證失敗的後果**

如果一個節點持續發送無效區塊或交易，其他節點可能會把它加入黑名單，不再接收它的訊息。
{% endhint %}

***

## 驗證 vs 確認

這兩個詞常被混淆：

| 概念     | 說明            |
| ------ | ------------- |
| **驗證** | 檢查交易/區塊是否合法   |
| **確認** | 交易被打包進區塊後的區塊數 |

一筆交易可能「驗證通過」但還沒「被確認」（還在交易池等待打包）。

***

## 不同節點的驗證能力

| 節點類型   | 驗證能力         |
| ------ | ------------ |
| 全節點    | 完整驗證所有規則     |
| 輕節點    | 只驗證區塊頭，信任全節點 |
| SPV 錢包 | 最低程度驗證，依賴他人  |

{% hint style="success" %}
**運行全節點的意義**

運行全節點意味著你不需要信任任何第三方。你自己驗證每一筆交易、每一個區塊，確保沒有人能欺騙你。
{% endhint %}

***

## 驗證與共識的關係

驗證是共識的基礎：

1. 節點收到新區塊
2. 驗證區塊是否合法
3. 合法才接受，加入本地區塊鏈
4. 廣播給其他節點

如果大多數節點都接受同一條鏈，就形成了**共識**。

***

## 延伸閱讀

* [打包](/qu-kuai-lian-ru-he-da-cheng-gong-shi/wa/da-bao.md) — 產生待驗證區塊的過程
* [廣播](/qu-kuai-lian-ru-he-da-cheng-gong-shi/wa/bo.md) — 區塊如何傳遞給其他節點
* [全節點](/gei-kai-fa-zhe-de-zhi-nan/node/quan.md) — 完整驗證的節點
* [輕節點](/gei-kai-fa-zhe-de-zhi-nan/node/liang.md) — 簡化驗證的節點
* [共識機制](/qu-kuai-lian-ru-he-da-cheng-gong-shi/consensus.md) — 驗證後如何達成一致

***

#### 參考資料

* [Bitcoin Protocol Rules](https://en.bitcoin.it/wiki/Protocol_rules)
* [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf)


---

# Agent Instructions: 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:

```
GET https://www.0x1.academy/qu-kuai-lian-ru-he-da-cheng-gong-shi/wa/undefined.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
