Appendix C. Serialisation Codec (Element Encoding Method) ## C.1.1. Trivial Encoding 以下有四種簡單的編碼情況: ### (C.1) 空值 空值將會輸出空的序列 ### (C.2) octet-sequence 八位元序列輸入,不需要做任何轉換 (因為就是要轉換成八位元) ### (C.3) tuple 分別將 tuple 中的成員進行序列化後,將序列結果串在一起。 ### (C.4) 多參數 將輸入的多個參數以 tuple 形式進行序列化 ## C.1.2. Integer Encoding 將自然數轉換為固定長度的八位元組序列 (octet-sequence), 使用 little-endian 編碼方式進行。(little-endian 會將結果,由左邊開始放置) 以下為簡易的整數轉換 ($0 <= x < 2^{(8*l)}$) ![image](https://hackmd.io/_uploads/B1k97npz1x.png) ![image](https://hackmd.io/_uploads/r1RPR36zJl.png) 以下為通用版的整數轉換 (支持到 $\mathbb{N}_{2^{64}}$ => unsigned int64) 三個條件對應不同編碼計算: 1. $x = 0$ 2. $2^7 \le x < 2^{56}$ 3. $2^{56} \le x < 2^{64}$ ```python if x == 0: # 條件一 if 2**(7*l) <= x < 2**(7*(l+1)): # 條件二 else if x < 2**64: # 條件三 ``` > 於 3.4 Numbers 中的定義: $\mathbb{N} = \{ 0, 1, ... \}$ and $\mathbb{N}_n = \{ x | x \in \mathbb{N}, x < n \}$ > 因此 $\exists l \in \mathbb{N}_8$ 的範圍是 $\{0,1,2,3,4,5,6,7\}$ ![image](https://hackmd.io/_uploads/BJHLg6pf1x.png) > [name=Yccinamoroll3741]: 分段處理提升效率, 太小的數字不需要用到 2^64 這麼大 所以 integer encoding 是 256 進位, 但是需要用到的 byte 數量會動態調整(dynamic array) > [name=Eugene]: > 這個公式會依照數值的大小回傳不同長度的八位元組序列 ($l$ 會依照 $x$ 大小而改變) > [name=Eugene]: > Q: 為什麼輸出的 $\mathbb{Y}$ 長度會是 1~9? > A: ==因為第一個位置都是用來作為識別使用, 可以辨識出該輸入 $x$ 的數值範圍與長度== > [name=Eugene]: 以 APPENDIX C. Block Serialization 的定義上,會定義 $l$ 的大小,例如 C.22 案例, $l$ 會影響輸出序列的大小。(實際也可以透過 x 來反推最佳的 $l$ 大小) ## Eq. 303 $\updownarrow$ 符號代表長度與內容: ![image](https://hackmd.io/_uploads/BJCroFsfyl.png) ## Eq. 305 Bit sequence Encoding: 簡單把 bit 轉成 8 位元組 ## Eq. 306 Dictionary Encoding: "key:value" pair 的長度 + key : value ## Eq. 307 Set Encoding: 同 Sequence Encoding 但因為 Set 本身沒有排序,所以要依照小到大排序 ## Eq. 308 Block Encoding: C.2 Block Serialization 區塊的序列化是將 header 以及 extrinsic data 依照順序以 tuple 的形式放入進行序列化, 可以參考 equations 4.2, 4.3 以及 5.1 (關於 header 以及 extrinsic data 的定義) > - equation 4.2 > $$ > \mathbf{B} \equiv (\mathbf{H}, \mathbf{E}) > $$ > - equation 4.3 > $$ > \mathbf{E} \equiv (\mathbf{E}_T,\mathbf{E}_D,\mathbf{E}_P,\mathbf{E}_A,\mathbf{E}_G) > $$ > > - equation 5.1 > $$ > \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) > $$ ### C.13 以 tuple 的方式將 header 以及所有的 extrinsic data 放入進行序列化 $$ \varepsilon(\mathbf{B}) = \varepsilon ( \mathbf{H},\ \varepsilon_T(\mathbf{E}_T),\ \varepsilon_P(\mathbf{E}_P),\ \varepsilon_G(\mathbf{E}_G),\ \varepsilon_A(\mathbf{E}_A),\ \varepsilon_D(\mathbf{E}_D)) $$ ### C.14 $\mathbf{E}_T$ (tickets) tickets 用來決定哪個驗證者負責產生區塊 tickets 資料大小是可變動的,因此透過 $\updownarrow$ 的序列化方式進行。(序列化其長度與內容) $$ \varepsilon_{T}(\mathbf{E}_T) = \varepsilon(\updownarrow \mathbf{E}_T) $$ > 深入閱讀:6.7 The Extrinsic and Tickets. 有關於 $\mathbf{E}_T$ 的介紹, 前往 [Extrinsic 筆記](https://hackmd.io/hk0xabpQRrCb5OnM6upU7w?view) ### C.15 $\mathbf{E}_P$ (preimages) - $p$: preimage, Preimage lookups 是區塊鏈中提供靜態數據查詢的一種機制 - 可以在區塊鏈中儲存靜態數據,透過任意的 key/value pairs 進行儲存。(提供給 Refine 階段快速查詢數據使用) - 使用 hash 作為索引,查詢到原始數據 - 資料來源是 extrinsic data - $s$: service of identifier (用來作為索引) - 需要排序(參考 3.7.1 sequence 有介紹排序規則) ![image](https://hackmd.io/_uploads/HJSJlVRMJl.png) > 深入閱讀 9. Service Account 以及 9.2 Preimage Lookups ### C.16 $\mathbf{E}_G$ (reports) ![image](https://hackmd.io/_uploads/HkNl2nnz1l.png) ==TODO: 11.4 Work Report Guarantees. 有關於 $\mathbf{E}_G$ 的介紹, 尚未閱讀== ### C.17 $\mathbf{E}_A$ (The Assurances Extrinsic) ![image](https://hackmd.io/_uploads/rkRNg5TzJl.png) ==TODO: 11.2 Package Availability Assurances. 有關於 $\mathbf{E}_A$ 的介紹, 尚未閱讀== ### C.18 $\mathbf{E}_D$ (The disputes extrinsic) ![image](https://hackmd.io/_uploads/S1k7bq6M1e.png) > 深入閱讀:10.2 Extrinsic. 有關於 $\mathbf{E}_D$ 的介紹, 前往 [Extrinsic 筆記](https://hackmd.io/hk0xabpQRrCb5OnM6upU7w?view) ### C.19 $\mathcal{E}(\mathbf{H})$ = 連結以下兩個序列化結果 - $\mathbf{H}_s$ : a block seal - $\mathbf{H}_U$ : 定義於 C.20 ![image](https://hackmd.io/_uploads/rJVDGqTGyg.png) ==Seal (seal signature) 是以什麼格式記錄? sealing keys?== ### C.20 $\mathcal{E}_U(\mathbf{H})$ 會使用於 C.19 - $\mathbf{H}_p$ : parent hash - $\mathbf{H}_r$ : prior state root - $\mathbf{H}_x$ : extrinsic hash - $\mathbf{H}_t$ : a time slot index - $\mathbf{H}_e$ : the epoch - $\mathbf{H}_w$ : winning tickets - $\mathbf{H}_o$ : offenders markders - $\mathbf{H}_i$ : a Bandersnatch block author index - $\mathbf{H}_v$ : the entropy-rielding VRF signatrue - $\text{¿}$ : 定義於 APPENDIC C.8, 用來判斷輸入是否為空值,會有不同的輸出。 ![image](https://hackmd.io/_uploads/rkvhLcpzyg.png) - $\mathcal{E}_2$:定義於 APPENDIC C.5, 用來對於整數型態的編碼, 此處限制了 $l = 2$ 的狀況進行整數編碼。 ![image](https://hackmd.io/_uploads/r1lnfDcpfJl.png) ![image](https://hackmd.io/_uploads/Byx2Sc6f1e.png) ### C.21 - $\mathbb{X}$ : The set of refinement contexts ![image](https://hackmd.io/_uploads/ryq3w5Tfkl.png) > ==TODO: 11. REPORTING AND ASSURANCE, 11.1.2 Refinement Context . 有關於 $\mathbb{X}$ 的介紹, 尚未閱讀== ### C.22 - $\mathbb{S}$ : The set of availability specifications ![image](https://hackmd.io/_uploads/BJDtO96fkx.png) ==TODO: 11. REPORTING AND ASSURANCE, 11.1.3 Availability . 有關於 $\mathbb{S}$ 的介紹, 尚未閱讀== ### C.23 - $\mathbb{L}$ : The set of work results ![image](https://hackmd.io/_uploads/Bkgb4F9aMJg.png) ==TODO: 11. REPORTING AND ASSURANCE, 11.1.4 Work Result . 有關於 $\mathbb{L}$ 的介紹, 尚未閱讀== ### C.24 - $\mathbb{W}$ : The set of work-reports ![image](https://hackmd.io/_uploads/B18YF56fJe.png) ==TODO: 11. REPORTING AND ASSURANCE, 11.1.1 Work Report . 有關於 $\mathbb{W}$ 的介紹, 尚未閱讀== ### C.25 - $\mathbb{P}$ : The set of work-packages. See equation 14.2 ![image](https://hackmd.io/_uploads/BJrZqcTzkx.png) ==TODO: 14.3. Packages and Items 有關於 $\mathbb{P}$ 的介紹, 尚未閱讀== ### C.26 $\mathbb{I}$ : The set of work items. See equation 14.3 ![image](https://hackmd.io/_uploads/B1HkscTMke.png) ==TODO: 14.3. Packages and Items 有關於 $\mathbb{I}$ 的介紹, 尚未閱讀== ### C.27 $\mathbb{C}$ : The set of seal-key tickets. See equation 6.6. *Not used as the set of complex numbers.* ![image](https://hackmd.io/_uploads/rkSsjcpMJl.png) > 6.2. Safrole Basic State 有關於 $\mathbb{C}$ 的介紹, 前往 [6.2 Safrole Basic State 筆記](https://hackmd.io/ek3wRMPERIudG41mFuirfA#6-2-Safrole-Basic-StateSafrole-%E5%9F%BA%E6%9C%AC%E7%8B%80%E6%85%8B) ### C.28 $O$ 會使用於 C.23 - $\mathbb{J}$ : The set of work execution erros - $\mathbb{Y}$ : The set of octet strings/"blobs". Subscript denotes length. See section 3.7 ![image](https://hackmd.io/_uploads/ryDF2qaMkx.png) ### C.29 $\mathcal{E}_I$ 會使用於 C.26 ![image](https://hackmd.io/_uploads/BJHahopG1e.png)