關於跨鏈技術的分析和思考

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"當前的區塊鏈底層技術平臺百花齊放,不同的業務、不同的技術底層的區塊鏈之間缺乏統一的互聯互通的機制,這極大限制了區塊鏈技術和應用生態的健康發展。跨鏈的需求由此而來,本文通過分析幾種主流的跨鏈方案探討跨鏈技術的本質及相應的解決思路。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"一、跨鏈的類型","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"跨鏈交互根據所跨越的區塊鏈底層技術平臺的不同可以分爲同構鏈跨鏈和異構鏈跨鏈:同構鏈之間安全機制、共識算法、網絡拓撲、區塊生成驗證邏輯都一致,它們之間的跨鏈交互相對簡單。而異構鏈的跨鏈交互相對複雜,比如比特幣採用PoW算法而聯盟鏈Fabric採用傳統確定性共識算法,其區塊的組成形式和確定性保證機制均有很大不同,直接跨鏈交互機制不易設計。異構鏈之間的跨鏈交互一般需要第三方輔助服務輔助跨鏈交互。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"二、主流跨鏈機制概述","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"截至目前,主流的區塊鏈跨鏈技術方案按照其具體的實現方式主要分爲三大類,分別是公證人機制、側鏈/中繼和哈希鎖定:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1.公證人機制(Notary schemes): 公證人也稱見證人機制,公證人機制本質上是一種中介的方式。具體而言,假設區塊鏈A和B本身是不能直接進行互操作的,那麼他們可以引入一個共同信任的第三方作爲中介,由這個共同信任的中介進行跨鏈消息的驗證和轉發。公證人機制的優點在於能夠靈活地支持各種不同結構的區塊鏈(前提是公證人能夠訪問相關方的鏈上信息),缺點在於存在中心化風險。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2.哈希鎖定(Hash-locking): 哈希鎖定技術主要是支持跨鏈中的原子資產交換,最早起源自比特幣的閃電網絡。其典型實現是h哈希時間鎖定合約HTLC(Hashed TimeLock Contract)。哈希鎖定的原理是通過時間差和影藏哈希值來達到資產的原子交換。哈希鎖定只能做到交換而不能做到資產或者信息的轉移,因此其使用場景有限。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"3.側鏈/中繼鏈(Sidechains / Relays): 側鏈是指完全擁有某鏈的功能的另一條區塊鏈,側鏈可以讀取和驗證主鏈上的信息。主鏈不知道側鏈的存在,由側鏈主動感知主鏈信息並進行相應的動作。而中繼鏈則是側鏈和公證人機制的結合體,中繼鏈具有訪問需要和驗證進行互操作的鏈的關鍵信息並對兩條鏈的跨鏈消息進行轉移。從這個角度看中繼鏈也是一種去中心的公證人機制。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下面就這幾種跨鏈方式的典型實現方式進行詳細分析:","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":" 典型跨鏈機制實現分析","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.公證人機制","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b1/b194b75c70267c5deef521e6908a6b00.jpeg","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Alice 通過交易所錢包將自己的比特幣打入交易所地址;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Alice 在交易所上掛上賣單1個BTC賣出20ETH價格;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Bob需要將自己的ETH打入交易所的以太坊地址;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Bob通過交易所掛出購買比特幣的單子 20ETH買一個比特幣;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"交易所將Alice的賣單和Bob的賣單進行撮合;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"交易所將Alice在交易所存儲的1BTC 轉移給Bob的比特幣地址;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"交易所將Bob在交易所存儲的20ETH 轉移給Alice的以太坊地址;","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"至此完成了Alice和Bob的BTC和ETH的交換(案例中省去了交易所的服務費)。通過該例子可以看出交易所的方式目前僅能夠支持資產的交換,且資產交換的原子性、安全性完全由中心化的交易所保障存在較大的中心化風險。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/61/613c2ac459cd75d4c188ec5f794c0e68.jpeg","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除此之外還有一種著名的分佈式賬本技術Ripple,也是採用類似公證人的機制來解決全球金融機構之間的資產交換。Ripple的系統架構如上圖所示,Ripple系統中交易通過網絡中的驗證者進行交易的驗證,驗證者驗證的交易通過加密算法保護交易內容不能被驗證着窺探從而保證交易的隱私性。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"公證人機制的跨鏈技術實現簡單,且能夠比較靈活地支持不同類型的底層區塊鏈體系。公證人機制的主要問題在於公證人機制的安全性保障完全由公證人系統保障。參與跨鏈的相關方需要對中間人給予較大的信任。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.哈希鎖定","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"哈希時間鎖定(HTLC)最早出現在比特幣的閃電網絡,跨鏈資產交換支持一定數量的A鏈資產和一定數量的B鏈資產進行原子交換。哈希時間鎖定巧妙地採用了哈希鎖和時間鎖,迫使資產的接收方在deadline內確定收款併產生一種收款證明給打款人,否則資產會歸還給打款人。收款證明能夠被付款人用來獲取接收人區塊鏈上的等量價值的數量資產或觸發其他事件。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如下圖所示,我們用一個例子來闡述如何使用哈希時間鎖定進行跨鏈的原子資產交換,假設Alice和Bob有資產交換的需求,Alice想用1個BTC和Bob換20個ETH. 那麼首先需要在兩條鏈上設置哈希時間鎖定合約,然後執行如下步驟:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c0/c069d2ab396193c6a82038e20520d010.jpeg","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Alice 隨機構建一個字符串s,並計算出其哈希 h = hash(s) ;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Alice 將h發送給Bob的合約;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Alice鎖定自己的1個BTC資產,並設置一個較長的鎖定時間t1, 並設置了獲取該BTC的一個條件:誰能夠提供h的原始值s就可以得到該BTC;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Bob觀察到Alice 合約中鎖定了一個BTC, 然後Bob鎖定自己的20個ETH資產,並設置一個相對較短的鎖定時間 t2 , t2 < t1, Bob也設置了同樣獲取條件(誰提供h的原始值s就可以獲取20個ETH);","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Alice將自己最初生成的字符串s發送到Bob的合約裏取得了20個ETH;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Bob觀察到步驟5中Alice的s值,將其發送給Alice的合約成功獲取1個BTC; 至此Alice和Bob完成了資產的交換。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從上述的過程我們可以看出哈希時間鎖定合約有一些約束條件:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"進行跨鏈資產交換的雙方必須能夠解析雙方的合約內部數據,例如s,例如鎖定資產的證明等;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"哈希鎖定的超時時間設置時需要保證存在時間差,這樣在單方面作弊時另一方可以及時撤回自己的資產。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"哈希鎖定的思想運用在支付領域較多,例如閃電網絡、雷電網絡以及跨鏈資產轉移協議 Interledger 等。但是哈希鎖定目前看只適合偏資產或者關鍵數據的交換,甚至不支持轉移因此其試用場景受限。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"3.側鏈/中繼鏈","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":5},"content":[{"type":"text","text":"側鏈:側鏈是相對於主鏈而言的,最初的側鏈提出是針對比特幣做新特性的測試和研發。側鏈相對主鏈而言能夠驗證和解析主鏈中的區塊數據和賬本數據。側鏈實現的基礎技術是雙向錨定(Two-way Peg),通過雙向錨定技術可以將數字資產在主鏈上進行鎖定,同時將等價的資產在側鏈中釋放。相反當側鏈中相關資產進行鎖定時,主鏈上錨定的等價資產也可以被釋放。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"BTC-Relay是號稱的史上第一個側鏈,BTC-Relay是通過以太坊構建了一個比特幣的側面,運用以太坊的智能合約允許用戶驗證比特幣的交易。這裏我們仍然以Alice 1BTC和Bob的20ETH數字資產交換爲例闡述相應原理:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Bob將20ETH發送到BTCSwap的合約進行凍結;(該合約只要能夠確認BTC網絡上Bob接收到來自Alice 1BTC就自動將20ETH轉給Alice);","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Alice 確認Bob凍結信息後,將1 BTC轉給Bob比特幣賬戶;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"BTC Relayer將比特幣區塊頭推送到BTCSwap合約;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Alice 接下來就可以調用relay tx;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"BTCSwap合約結合tx和BTC鏈的區塊鏈進行SPV驗證,驗證通過則將20ETH轉給Alice以太坊地址。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/83/8328c63098cd2da7443458f80b0b466f.jpeg","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這種跨鏈的實現方式簡單,但是BTC Relay需要額外的信任和維護成本,且智能合約內部的數據存儲會有體積膨脹的問題。但是側鏈的機制相對哈希鎖定而言能夠提供更多的跨鏈交互場景,側鏈以及類SPV驗證的思想適合所有跨鏈的場景。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":5},"content":[{"type":"text","text":"中繼鏈:中繼鏈本質上算是公證人機制和側鏈機制的融合和擴展,目前社區內最活躍的兩個跨鏈項目 Cosmos 和 Polkadot 採用的都是基於中繼鏈的多鏈多層架構,其中Cosmos目前支持的是跨鏈資產交互而Polkadot則宣稱提供任意類型的跨鏈交互,具體實現還有待觀察。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/9d/9dd4a9fd7bd54f96867c87e9f7c2d86c.jpeg","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"爲了支持平行鏈之間的跨鏈互操作,Cosmos提出了一種跨鏈交互協議IBC(Inter-Blockchain Communication protocol), 並利用tendermint共識算法的即時確定性實現多個異構鏈之間的價值和數據傳輸。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"首先我們以Chain A到Chain B轉賬10 token爲例說明使用IBC的跨鏈交互:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"互相跟蹤,也就是說如果A要和B進行跨鏈交易,那麼A和B鏈需要分別運行相當於對方區塊鏈的輕節點服務,這樣互相可以實時接收到對方的區塊頭信息(方便後續執行類SPV驗證);","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"A鏈上初始化IBC協議,凍結相關資產10 token, 並生成相應的證明發送給B區塊鏈;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"B鏈接收到相應的IBC消息,通過A鏈的區塊頭信息確定A確實進行相應的資產凍結,然後B鏈會生成等價值10 token的資產。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以上是使用IBC協議的兩個平行鏈直接進行跨鏈的基本過程,如果區塊鏈很多,那麼這種方式的兩兩跨鏈複雜度會呈現組合級別增加。因此Cosmos網絡又引入了一種Hub的中繼鏈,所有的平行鏈都通過IBC連接到Hub,讓Hub輔助跨鏈交易的驗證和轉移,目前Cosmos實現了一個官方的Hub稱爲Cosmos Hub(如前圖所示)。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如下圖所示是Cosmos網絡的詳細架構圖Cosmos爲方便平行鏈開發提供了基本服務CosmosSDK包括:共識、網絡以及IBC協議等,這樣基於Cosmos SDK開發的子鏈之間都能夠方便地互相交互。此外對於非Cosmos SDK 開發的區塊鏈需要使用Peg Zone進行橋接,如圖中的Ethereum。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/36/364058b7984f3c108eaa50b8b37cafd1.jpeg","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"筆者認爲Cosmos爲跨鏈帶來的最大貢獻在於IBC協議的設計,IBC協議提供了一種通用的跨鏈協議標準。IBC的設計使得跨鏈交易可以在多個Hub之間進行安全路由和轉發,類似目前互聯網的TCP/IP 協議。但是遺憾的是目前的Cosmos設計也只能夠支持資產的跨鏈,而且由於不同區塊鏈的業務不同其共識速率的不一致也會影響跨鏈交易有效性的證明。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Polkadot:Polkadot也是一種集成平行鏈和中繼鏈的多層多鏈架構,Polkadot區塊鏈的整體架構圖如下圖所示,主要包含三種角色鏈和四種參與方:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/7f/7ff05f60703f5429be137c0274df1752.jpeg","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"三種鏈角色:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"中繼鏈(Relay chain): 中繼鏈位於Polkadot的體系的核心地位,主要是爲整個系統提供統一的共識和安全性保障;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"平行鏈(Parachain): 在Polkadot中平行鏈負責具體的業務場景,平行鏈自身不具備區塊的共識,它們將共識的職責渡讓給了中繼鏈,所有平行鏈共享來自中繼鏈的安全保障,中繼鏈是Polkadot組成的一部分;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"橋接鏈:橋接鏈指的是非Polkadot體系之外的區塊鏈,如Bitcoin, Ethereum, 這些區塊鏈有自身的共識算法,它們通過不同的Bridge與Polkadot連接在一起進行跨鏈交互。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"四種參與方:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"驗證者(Validator): 驗證者負責Polkadot的網絡出塊,會運行一箇中繼鏈的客戶端,在每一輪區塊產生中會對其提名的平行鏈出的塊進行覈驗。當平行鏈的跨都被他們的子驗證者集合確定好之後,驗證者們會將所有平行鏈區塊頭組裝到中繼鏈的區塊並進行共識。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"覈驗人(Collator): 幫助驗證者收集、驗證和提交備選平行鏈區塊,維護了一個平行鏈的全節點。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"釣魚人(Fisherman):釣魚人主要靠檢舉非法交易或者區塊以獲取收益;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"提名人(Nominator): 擁有stake的相關方,維護和負責驗證者的安全性。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Polkadot的特性包括兩個,一個是共享安全性,一個是不需信任的跨鏈交互。這裏的不需信任的跨鏈交互其實是和第一個特點共享安全性密切相關的,而且Polkadot的不需信任的跨鏈交互也主要是隻其內部的平行鏈之間。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在Polkadot中如果parachain A 需要發送一筆交易到parachain B的過程如下:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"A鏈將跨鏈交易放到自己的engress(每個平行鏈有一個消息輸出隊列engress 和一個消息輸入隊列ingress);","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"A鏈的Collator收集A鏈的普通交易以及跨鏈交易並提交給A鏈的驗證者集合;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"A鏈的驗證者集合驗證成功,將本次A鏈的區塊頭信息以及A鏈的engress內信息提交到中繼鏈上;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"中繼鏈運行共識算法進行區塊確認以及跨鏈交易路由,中繼鏈上的驗證者會將A鏈的相應交易從A鏈的engress queue中移動到B鏈的ingress queue中。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"B鏈執行區塊,將ingress queue中相應交易執行並修改自身賬本。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以上便是Polkadot跨鏈交易的主要步驟,由於所有平行鏈的共識同步發生(中繼鏈區塊示意圖如下),因此跨鏈交易不會有諸如雙花等安全性問題。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/01/01dc014a58e288f36cc18310ba1257f0.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Polkadot的平行鏈之間的跨鏈交換的安全性保障主要來自共享安全性這個特點,共享安全性使得跨鏈交易和普通交易同步發生也就不存在其他跨鏈場景中的雙花等跨鏈數據不一致問題。其次Polkadot中的引入的特殊狀態驗證方法方便中繼鏈進行跨鏈等消息的有效性驗證。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"值得一提的是Polkadot項目目前還處在項目初期,對於parachain的設計、Collator的協作以及Validator的共識、工作效率等都未完善。這種共享安全性的方式是否也限制了平行鏈自身的性能都還有待考證。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"  關於跨鏈技術的幾點思考:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"綜合以上的一些主流跨鏈場景和方案的分析,從跨鏈的概念以及需求上看跨鏈的本質其實就是如何將A鏈上的消息M安全可信地轉移到B鏈並在B鏈上產生預期效果。那麼一個成功的跨鏈交互到底需要解決哪些問題呢?筆者認爲主要有以下四個問題:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"消息M的真實性證明,也就是說M是否確實是存在A鏈上的,也確實是A鏈發給B鏈的;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"消息M的路由,如何讓跨鏈消息安全跨系統路由;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"消息M的有效性證明,這裏的有效性是指來自A鏈的消息M如何讓B鏈認可其抵達B鏈時狀態仍然有效,比如轉移的資產是否是凍結的,沒有雙花的,如果是狀態那麼是否在此期間未發生改變等;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"消息M的執行結果證明,這個是指A鏈需要確認跨鏈操作是否成功,以及成功操作的相應回執。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那麼針對這些關鍵本質問題,如何去處理呢?筆者設想未來的區塊鏈應該在底層平臺的設計之初就需要遵循統一的跨鏈協議標準,就像現在的操作系統對TCP/IP協議的支持一樣。需要進行通用跨鏈的區塊鏈至少要支持一下功能:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"提供跨鏈消息的輸入和輸出口徑,例如Cosmos和Polkadot的跨鏈隊列;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"提供跨鏈消息的真實性證明,區塊鏈需要提供類似SPV的證明手段;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"消息的有效路由需要構建跨鏈消息的統一格式,定義好消息的來源和去處以及消息內容,如Cosmos的IBC協議;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"消息的有效性證明,區塊鏈可能需要設計新的類似UTXO的可驗證存儲結構,方便做類SPV類驗證,否則目前的基於KV的數據存儲方式做有效性證明幾乎不可能;","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"跨鏈執行結果證明,和有效性證明類似,需要全新的數據結構和運行算法支持。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除此之外,跨鏈系統的設計還需要考慮系統穩定性、可擴展性以及易升級性、容錯等等,總而言之,真正的可信互聯網建設艱辛漫長,諸君共勉!","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"更多區塊鏈技術知識,添加小助手18458407117(vx),加入技術交流羣一起共話前沿~","attrs":{}}]}]}],"attrs":{}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章