# V. The Header
一個區塊的 header 會由以下資訊組成
- [x] $\mathbf{H}_p$ : parent hash
- [x] $\mathbf{H}_r$ : prior state root
- [ ] $\mathbf{H}_x$ : extrinsic hash
- [x] $\mathbf{H}_t$ : a time slot index
- [x] $\mathbf{H}_e$ : the epoch
- [x] $\mathbf{H}_w$ : winning tickets
- [x] $\mathbf{H}_o$ : offenders markders
- [x] $\mathbf{H}_i$ : a Bandersnatch block author index
- [x] $\mathbf{H}_v$ : the entropy-rielding VRF signatrue
- [ ] $\mathbf{H}_s$ : a block seal
Header 可以分別使用 $\varepsilon$ (包含 seal) 以及 $\varepsilon_U$ (不包含 seal) 進行序列化 (octet sequence)
> $\varepsilon$: 八位元序列編碼方法
> [!Warning]
> 目前不了解什麼狀況 Seal 不會被加入 Header 的序列化中,需要閱讀更多資訊。
>
> Seal 是區塊的一部分, 通常包含對該區塊的資料進行加密簽名或是其他形式的驗證,否些情況下,這個 Seal 可能不會被包含在 Header 的序列化中。
透過以下的公式可以了解,Header 是由多種資訊進行序列化所組成。
$$
\mathbf{H} \equiv (\mathbf{H}_p, \mathbf{H}_r, \mathbf{H}_x, \mathbf{H}_t, \mathbf{H}_e, \mathbf{H}_w, \mathbf{H}_o, \mathbf{H}_i, \mathbf{H}_v, \mathbf{H}_s)
$$
> [!Note]
> **octet sequence (八位元序列)**
> 將資訊轉換為八位元的二進位,該序列將會作為 hash function 的輸入。
> `A` 的 ASCII 數值為 `65`
> `65` 的二進位數值為 `01000001`
---
### $\mathbf{H}_p$
區塊鏈是一系列的區塊,每個區塊都透過 parent's header (父區塊標頭) 的 hash 來參照到前一區塊,可以一直追溯到某一個區塊引用了 genesis header (創世標頭)
:older_man: :arrow_right: :man: :arrow_right: :baby:
除了 genesis header $\mathbf{H}_{0}$ 外,所有的 block headers $\mathbf{H}$ 都會與 parent header $\mathbf{H_p}$ 有關, 關係如下:
$$
\mathbf{H}_p \in \mathbb{H} \,,\quad \mathbf{H}_p \equiv \mathcal{H}(\mathcal{E}(P(\mathbf{H})))
$$
- $P(H)$: parent header
- $P$ 是一個可以透過 block header 取得 parent block header 的函數
- $\mathcal{E}(P(H))$:parent header 的序列化結果
- $\mathcal{E}$ 是一個序列化函數
- $\mathcal{H}(\mathcal{E}(P(H)))$:parent header 序列化後進行 hash,即為 $H_p$
- $\mathcal{H}$:The Blake 2b 256-bit hash function
- $\mathbb{H}$ 是一個 32-octet cryptographic 的集合
透過 $P$ 這個函數,我們也可以定義出一個祖先標頭集合 (the set of ancestor headers) $A$
$$
h \in \mathbf{A} \Leftrightarrow h = \mathbf{H} \vee (\exists i \in \mathbf{A} : h = P(i))
$$
> [!Note]
> 翻譯:
> 如果 $h$ (header) 是祖先的話
> 需要符合以下兩種情況的其中一種:
> - $h$ 是當前區塊的 header $\mathbf{H}$
> - $h$ 是某一個祖先區塊標頭 $i$ 的父區塊標頭 (所以還是祖先:older_man: :older_woman:)
我們 (JAM?) 只要求儲存 24 小時內的 ancestor headers
---
### $\mathbf{H}_r$
$\mathbf{H}_r$ 是一個 Merkle tree 的根節點 (root), 是父區塊的最終狀態 (parent block's posterior state)
> 每一個區塊的最終狀態,將會成為下一個區塊的初始狀態
$$
\mathbf{H}_r \in \mathbb{H} \,,\quad \mathbf{H}_r \equiv \mathcal{M}_\sigma(\sigma)
$$
- $\mathbb{H}$ 是一個 32-octet cryptographic 的集合
- $\mathcal{M}_{\sigma}$:state-Merklization function 可以轉換 state 變成固定長度的 hash (32-octet commitment)
> [name=Yccinamoroll3741] see Appendix. D
---
### $\mathbf{H}_x$
$\mathbf{H}_x$ 是將 extrinsic 資料序列化後,再進行 hash。
任意區塊 $\mathbf{B} = (\mathbf{H}, \mathbf{E})$
(任意區塊是由 header 與 extrinsic data 組成)
$$
\mathbf{H}_x \in \mathbb{H} \,,\quad \mathbf{H}_x \equiv \mathcal{H}(\mathcal{E}(\mathbf{E}))
$$

- $\mathcal{H}^\#$:對 block 中所有 extrinsic 組成的資料 a,建立一個 Merkle root hash。
- $\mathbb{H}$ 是一個 32-octet cryptographic 的集合
- $\mathcal{H}$:The Blake 2b 256-bit hash function
---
### $\mathbf{H}_t$
一個有效的區塊,需要符合以下條件:
- 當前區塊的 time slot index $\mathbf{H}_t$ 一定要大於 parent 的 time slot index $P(\mathbf{H})_t$ (:pencil::否則順序性就有問題了)
- time slot index $\mathbf{H}_t$ 的時間點必須在過去 (:pencil::不可以產生出一個未來區塊)
$$
\mathbf{H}_t \in \mathbb{N}_T \,,\quad
P(\mathbf{H})_t < \mathbf{H}_t\ \wedge\ \mathbf{H}_t\cdot\mathsf{P} \leq \mathcal{T}
$$
- $\mathbb{N}_T$: $\mathbb{N}_T \equiv \mathbb{N}_{2^{32}}$
- timeslot index 的範圍 $0 \leq x < 2^{32}$
- P = 6 seconds
- T : 當前的時間點
> $\mathbb{N}_T$, $\mathsf{P}$ 於 4.8. Epochs and Slots 有詳細說明
> $\mathcal{T}$ 於 4.4. Time 有詳細說明
### $\mathbf{H}_e$
#### Epoch Marker:
這個標記指定了與下一個「時期」(Epoch)相關的金鑰和熵(entropy)。這是為了防止票據比賽(ticket contest)沒有完全結束的情況,這種情況相當罕見。
如果票據比賽失敗,這個標記將幫助進行必要的處理。
$$
\mathbf{H}_e \in (\mathbb{H, [\mathbb{H}_\mathbf{B}]_\mathbf{V})}?
$$

- $\mathbb{H}$: The set of 32-octet cryptographic values. A subset of Y32. H without a subscript generally implies a hash
function result. See section 3.8. NOTE: Not used as quaternions.
- $\mathbb{H}_\mathbf{B}$: The set of Bandersnatch public keys. A subset of Y32. See section 3.8 and appendix G.
- $\mathbb{H}_\mathbf{E}$: The set of Ed25519 public keys. A subset of Y32. See section 3.8.2.
> [!Warning]
> 詳細資訊寫在第六章, 待補充。
### $\mathbf{H}_w$
#### Winning-Tickets Marker:
這個標記包含了下一個時期的 600 個時段封印票據(slot sealing tickets)。這些票據對區塊的選擇和驗證至關重要。
$$
\mathbf{H}_w \in [{\mathbb{C}} _{\mathsf{E}}]{?}
$$
> [!Warning]
> 詳細資訊寫在第六章, 待補充。
---
### $\mathbf{H}_o$
#### Offenders Marker:
Offenders Marker 包含了一個 Ed25519 密鑰的序列,表示那些最近有不當行為的驗證者。這些不當行為的驗證者將被列出,並可能會受到懲罰或其他處理。
> [!Warning]
> 詳細資訊寫在第六章, 待補充。
---
### $\mathbf{H}_i$

所有的區塊都可以透過一個 public key 來得知該區塊的作者是誰,但是這個 public key $\mathbf{H}_a$ 並不會直接的儲存於 block header, 而是透過一個 index $\mathbf{H}_i$ 來進行索引。
$$
\mathbf{H}_i \in \mathbb{N}_\mathsf{V} \,,\quad \mathbf{H}_a \equiv \kappa'[\mathbf{H}_i]
$$
- $\mathbf{H}_i$:a Bandersnatch block author index
- $\mathbb{N}_\mathsf{V}$:自然數集合
- $\mathbf{H}_a$:a Bandersnatch key of the block author
- $\kappa'$:驗證者 public key 集合
> [!Warning]
> Q: 需要閱讀更多資訊,$\kappa'$ 會被儲存在哪?
> A: Preimage?
> Q: posterior & prior Kappa difference?
> > [name=Yccinamoroll3741] by Eugene
---
### $\mathbf{H}_v$
VRF Output
---
### $\mathbf{H}_s$
A block seal
> [!Warning]
> 需要閱讀更多資訊,是否與 Polkadot 文件定義的相同?