Robin Pan (@_Robin_Pan) profile picture

smart contract dev | prev @Furucombo & @deflast_finance

Joined December 2017
High quality, just like the app! Thanks @river0x @pauliepunt
3
2
26
1,018
【A Comprehensive Introduction to BTCFi Dark Horse —— RGB++】 It seems there is less introduction or discussion on RGB++ in the Western community. However, it might be one of the biggest narratives in this cycle. So, I decided to write one for this dark horse. I believe many people who follow this sector have heard of RGB++. Whether through breaking news, discovering it from CKB prices, or seeing the research report released by @MessariCrypto at the end of June, you might have come across some new terms that sound impressive but are still confusing. I am also in the same boat. So, I hope to write an introductory guide, summarizing my understanding and deconstructing this protocol from the perspective of a newcomer. I will try to focus only on the key points and necessary introductions, avoiding too much information that might hinder understanding. If you are interested in details, you can find answers in the documentation or light paper. Some references will be attached at the end of the article. @NervosNetwork is a renowned project from the previous round. I've been following them since their testnet phase. Unfortunately, in the last round, resources and attention were on the EVM and Solana ecosystems, which limited CKB's awareness. However, the team didn't give up and continued to improve the infrastructure and development tools over the past few years. They finally encountered the BTCFi explosion this round. Leveraging its unique UTXO extension architecture, Nervos Network co-founder @crypcipher proposed the RGB++ protocol ——— a BTCFi programmable and performance extension protocol without the need for cross-chain bridges. First, you need a basic understanding of CKB. The term CKB can refer to the chain (Common Knowledge Base) or the native token of this chain (CKByte). When referring to the token, CKB can be used as gas to pay miners and to calculate the space occupied on the chain. 1 CKB represents the ability to occupy one Byte. Here we can introduce the CKB chain, which, like Bitcoin, uses a UTXO structure, but each UTXO is extended into a model called Cell. Each Cell consists of four parts: Capacity, Data, LockScript, TypeScript - Capacity: Defines the total Bytes that this Cell can occupy on the chain, and also represents how much CKB is needed to carry this Cell (retrievable when the Cell is destroyed) - Data: Stores arbitrary data, which can be code, text, images, videos, or any other form - LockScript: Controls how this Cell can be unlocked. Since it is not hardcoded in the chain itself, it is highly flexible. You can specify it arbitrarily when creating the Cell. It can use common elliptic curve signature algorithms(ECDSA) or implement other algorithms yourself, even using simple arithmetic operations where anyone who knows the answer can unlock it (not recommended). This is very crucial, as it is chain-level cryptographic abstraction (or account abstraction), enabling it to simulate the encryption and decryption algorithms of any other chain. Wallets from those chains can operate directly on CKB seamlessly. This is also the main reason why other UTXO chains cannot easily mimic or copy the RGB++ concept. - TypeScript: Similar to LockScript but usually used for business logic. The only difference (temporarily not understanding it doesn't affect the later sections) is that LockScript only verifies inputs, while TypeScript verifies both inputs and outputs. Continuing with the main topic RGB++ can be summarized in one sentence: "Each RGB++ transaction sends a transaction on both Bitcoin and CKB, providing Bitcoin-level security for RGB++ assets through single-use sealing, isomorphic binding, and client-side validation techniques, while offering programmability and performance scalability without requiring cross-chain." I'll deliberately omit some details here to make the overall protocol easier to understand for everyone. For those interested in the details, you can read the Light Paper: talk.nervos.org/t/rgb-protoc… Single-Use Sealing: "Hash all actions related to this RGB++ transaction and write it on the specified UTXO transaction." This means writing a hash on Bitcoin's OP_RETURN. The UTXO itself is protected by the Bitcoin network, which has characteristics of being immutable and single-use. By linking the RGB++ transaction with the UTXO in this way, it provides state-lock protection for the RGB++ transaction. Hashing all actions is called "Commitment." Isomorphic Binding: "Execute all actions related to this RGB++ transaction and record them on a CKB Cell. The owner of this Cell is the UTXO specified by the single-use sealing. Such Cells are like shadows of the UTXO, also known as Shadow Cells." Apart from changes in UTXO occurring on Bitcoin, the rest of the RGB++ transaction will be executed and verified on the CKB chain, and the result will be recorded on a new Cell. This Cell can only be unlocked on the CKB chain with proof of spending the UTXO on Bitcoin. At this point, you might wonder how it's possible to make a Cell unlockable only by a specified UTXO. This is actually due to the chain-native cryptographic abstraction "LockScript" I mentioned earlier that CKB reserved during its design. For these RGB++ transaction-related Cells, instead of setting them to be unlocked using elliptic curve signature algorithms, a special unlock script developed for RGB++, the "RGB++ lock," is used. This script requires the on-chain BTC Tx that spent this UTXO as a parameter and must meet specific rules to unlock the Cell. Details can be found in the contract specification document: github.com/ckb-cell/RGBPlusP… In this way, RGB++ transactions achieve: 1. Security guaranteed by the Bitcoin network (LockScript unlocks the Cell only after specified UTXO is spent on Bitcoin) 2. Programmability extended by the CKB network (TypeScript supports arbitrary contract logic) Transaction Folding: "To further utilize the programmability and faster, cheaper transaction experience of L2 (i.e., CKB), RGB++ assets can leap to L2. After performing a series of operations on L2, the results are leaped back and bound to L1 (Bitcoin), requiring only one RGB++ transaction at the beginning and end, with numerous intermediate transactions on L2 being effectively folded." Due to the isomorphic binding mechanism in RGB++, cross-chain asset transfers don't require a bridge. The team has given this process a vivid name: "Leap." Transaction folding can actually be divided into three parts: 1. L1 → L2 Leap 2. L2 Txs 3. L2 → L1 Leap Transaction folding refers to the combination of these three steps, but it's actually legitimate to execute each step independently. You can do only 1+3 (similar to the original RGB++ transaction), only 2+3 (convert L2 assets to RGB++ assets), or only 1+2 (leap RGB++ assets to L2, perform some operations, and then stay on L2). This may seem complicated, but it's actually not. We know that each RGB++ transaction typically includes one transaction on L1 and one on L2: [the L1 transaction carrying the commitment] and [the L2 transaction creating the Shadow Cell to carry the actions]. The first step of folding is to change the Shadow Cell, originally controlled by UTXO, to be controlled by the user-specified L2 wallet (only changing the LockScript). This can be understood as separating the RGB++ assets from the RGB++ protocol onto this Cell (the conversion process actually requires waiting for the confirmation of six Bitcoin blocks, which is omitted here). Since this Cell is no longer controlled by UTXO, it can be used freely on L2, which is the second step of folding. At this point, since the asset has been separated from the RGB++ protocol, any action or modification on L2 is not considered a complete RGB++ transaction. It must go through the third step of folding to re-bind with UTXO to be re-recognized as an RGB++ asset. Speaking of re-binding, it's actually about changing the owner of [the final state of the separated Cell] from your wallet to a specific UTXO, i.e., changing its LockScript back to using RGB++ lock and the specified UTXO. As mentioned earlier, the conversion process of the first step of folding requires six block confirmations to prevent the potential malicious attack risk if the Bitcoin transaction gets reverted. Therefore, RGB++ lock is actually converted into a lock called BTC_Time_Lock, which only converts to your L2 wallet lock after confirming the Bitcoin transaction has over six block confirmations. For details, refer to: talk.nervos.org/t/rgb-1/7798 ** The RGB++ protocol is not the same as the RGB protocol, but a revised version. Here, to focus on introducing RGB++, the parts related to RGB have been deliberately omitted. Interested reader can read the Light Paper. Some questions you might have when first studying RGB++: Q1: It seems that RGB++ involves making transactions on two parallel chains and referencing each other, but without enforced custody or locking. What happens if I only initiate a transaction on one side and ignore the other? A: It will most likely burn the asset. Firstly, you can only initiate a transaction unilaterally on Bitcoin because UTXO control always belongs to you, regardless of RGB++. But if you spend this UTXO unilaterally without writing a new "Commitment" (hash of all actions) in the transaction, although you can take the proof of UTXO expenditure to CKB, the RGB++_lock cannot confirm that the actions you are about to take on CKB match the commitment on Bitcoin, as it cannot find the commitment. Therefore, it will not unlock the Shadow Cell. Since the UTXO, the owner of this Shadow Cell, has already been spent, it means no one can ever unlock it again, effectively burning it. And as mentioned above, the Shadow Cell owner on CKB is the UTXO, not your wallet, so you cannot initiate unilateral RGB++ transactions on CKB. Q2: I heard that accelerating the Bitcoin transaction in RGB++ might burn the asset. Why? A: The most likely reason is that the Bitcoin TxID has changed, but the on-chain commitment content has not been updated accordingly. One thing you need to know is that UTXO is actually identified by TxID + Index. Suppose the TxID before acceleration is TxID_A, and after acceleration, it changes to TxID_B, but the commitment still specifies the UTXO in TxID_A as the owner of the Shadow Cell. After acceleration, the Shadow Cell is created according to the commitment, but since it cannot find TxID_A, this Shadow Cell can never be unlocked. For details on the commitment content and RGB++ lock unlocking method, refer to: github.com/ckb-cell/RGBPlusP… Some terms you may encounter when starting to engage with the ecosystem: - Spore: Can be understood as an NFT carrier, each Spore stores an NFT. It can be destroyed to retrieve the CKB used to carry it if no longer needed. - Cluster: An NFT Collection. When creating a Spore, you can specify the Cluster it belongs to. - DOB (Digital Object): An NFT mechanism built on Spore, this type of NFT has DNA and customizable DNA decoding functions. DOB/0 is the first version of DOB, and DOB/1 is also in progress. - xUDT: A widely used fungible token protocol on CKB, similar to ERC20. More advanced: - code_hash: A hash used to identify which code to use. - hash_type: Defines which part the above code_hash is taken from, it can be from the TypeScript part or the Data part, with different functions. Using TypeScript means this is an upgradable script, while using Data means the code content cannot be modified. (Each code is also deployed on the chain as a Cell, called Code Cell, with the Data field of the Code Cell storing the executable code). - CKB address: Derived from LockScript + args, searching for an address equals searching for a specific LockScript + args. Special thanks to @chestersigned for helping with the review! Some ecosystem projects: @Nervapes: Currently my favorite RGB++ project. It has been working on CKB for many years, and now with RGB++, it brings a different play to NFTs. Nervape is not just an image but a ape that can traverse Bitcoin & CKB, equipping and unequipping gear on CKB and leaping back to Bitcoin with the entire avatar including gear (under development). @joy_protocol: The most widely used PassKey wallet on RGB++ & CKB. Clean and neat, very user-friendly. Besides wallet functionality, it also has a Marketplace. @HueHubOfficial: Marketplace and Launchpad for RGB++ on L1. @OmigaHQ: DEX on CKB. @UTXOSwap: RGB++ AMM DEX. @MarketDobby: RGB++ DOB Marketplace. @DIDbased: .bit domain name service on CKB. @dobhub: DOB Launchpad. @SilentBerryNFT : Web3 digital music distribution platform based on RGB++ protocol @imagiNation_mkt : Digital collectibles on CKB @Stablepp: Stablecoin on RGB++ @btckbseal: First RGB++ Token @WORLD3_AI: AI-powered Autonomous World @cellulalifegame: Fully on-chain AI game Some documents and learning resources: - Messari Report messari.io/report/understand… - RGB++ Light Paper talk.nervos.org/t/rgb-protoc… - RGB++ Security Analysis (Chinese) talk.nervos.org/t/rgb-1/7798 - RGB++ lock & BTC_Time_Lock github.com/ckb-cell/RGBPlusP… - CKB Development Open Course | Blockchain Community (Chinese course recording) learnblockchain.cn/course/53… youtu.be/pM--3N0gwJk?si=s-cZ… - RGB++ SDK (GitHub) github.com/ckb-cell/rgbpp-sd… - Spore Documentation docs.spore.pro #BTC #BTCFi #BiFi #CKB #RGB #RGBPP #CKBTC
【一文讀懂 BTCFi 黑馬 —— RGB++】 趁著市場回暖,來寫一篇這輪主要賽道之一 BTCFi 的黑馬,RGB++ 協議。 相信許多關注此賽道的人都聽過 RGB++ ,不論是在快訊中、從 CKB 價格發現,或從六月底 @MessariCrypto 釋出的研報中看到,然後查了一些介紹及文件,看到了幾個不明覺厲的新名詞,卻還是似懂非懂,我也是。所以希望寫一篇入門的介紹(懶人包),整理自己的理解,從剛接觸者的角度去解構這個協議,會盡量只做重點和必要的介紹,避免過多資訊影響理解,如果對細節有興趣可以再從文件或白皮書找答案,文末會附上一些參考。 @NervosNetwork 是上一輪的天王級項目,從測試網時期就在關注他們,可惜上一輪市場的資源和關注度都在 EVM 和 Solana 生態,讓 CKB 沒有太大發揮。 然而團隊沒有放棄,在過去幾年間持續完善基礎設施及開發工具,終於在這一輪遇上 BTCFi 的爆發,憑藉著其獨特的 UTXO 擴展架構,Nervos Network 聯創 @crypcipher 提出了 RGB++ 協議 ——— 一個無須跨鏈橋的 BTCFi 可編程和性能擴展協議。 首先需要先對 CKB 有基本的認識: CKB 這個詞可以指的是這條鏈(Common Knowledge Base),也可以是這條鏈的原生代幣(CKByte)。 當指的是幣時,CKB 可以用來當 gas 付給礦工,也可以用來計算鏈上的佔用空間,1 CKB 就代表能佔用一個 Byte。 這裡就能帶出 CKB 這條鏈,和 Bitcoin 同樣是 UTXO 架構,但其中的每個 UTXO 都被擴增成稱為 Cell 的模型,每個 Cell 由四個部分組成: Capacity(容量), Data(資料), LockScript(解鎖腳本), TypeScript(業務邏輯腳本) - Capacity(容量): 用來定義這個 Cell 總共能在鏈上佔用多少 Bytes,同時也代表需要花費多少 CKB 來乘載這個 Cell(消除這個 Cell 時能取回) - Data(資料): 存放任意資料,可以是代碼、文字、圖片、影片或其他任何形式 - LockScript(解鎖腳本): 控制此 Cell 如何能被解鎖,由於沒有在鏈本身寫死,因此極具靈活性。在創建 Cell 時可以任意指定,可以使用普遍的橢圓曲線簽章算法,也可以自己實作其他算法,甚至使用簡易的四則運算,知道答案者就能解鎖(不建議)。 這非常關鍵,是鏈級別的密碼抽象(或理解為帳戶抽象),使其能模擬其他任何鏈的加解密算法,用那些鏈的錢包就能無縫直接在 CKB 上操作。也是其他 UTXO 鏈無法輕易模仿/抄襲 RGB++ 概念的主因。 - TypeScript(業務邏輯腳本): 與 LockScript 大致相同,只是通常使用於業務邏輯。唯一差異(暫時不理解不影響後面篇章),在於 LockScript 只對 inputs 做驗證,而 TypeScript 會對 inputs 和 outputs 都做驗證。 接著切入主題 RGB++ 可以用一句話概括: 「每筆 RGB++ 交易都會在 Bitcoin 和 CKB 各發送一筆交易,透過一次性密封、同構綁定和客戶端驗證技術,為 RGB++ 資產提供了與 Bitcoin 同等的安全性,同時具有可編程性及性能擴展,無需跨鏈」 這邊會刻意刪掉一些細節,盡量用簡易好懂的敘述讓大家先對整體協議有基本的認識,想鑽研細節可以再自行閱讀 Light Paper: talk.nervos.org/t/rgb-protoc… 一次性密封: 「將與此 RGB++ 交易相關的所有動作取哈希後,寫在指定的 UTXO 交易上」 就是把一段哈希寫在 Bitcoin OP_RETURN 上。 UTXO 本身受到了 Bitcoin 網路的保護,有不可篡改且只能使用一次的特性,透過這個方式,將 RGB++ 交易與 UTXO 進行了連結,為 RGB++ 交易提供了狀態鎖定的保護。 所有動作取哈希這個動作稱為「承諾(Commitment)」。 同構綁定: 「將與此 RGB++ 交易相關的所有動作執行,並記錄到一個 CKB Cell 上,這個 Cell 的所有者為一次性密封指定的 UTXO。這類 Cell 如同 UTXO 的影子,也稱為 Shadow Cell」 除了 UTXO 的變動發生在 Bitcoin 上,RGB++ 交易的其餘部分都會在 CKB 鏈上被執行與驗證,並把結果記錄在一個新的 Cell 上,這個 Cell 只有在一次性密封的 UTXO 在 Bitcoin 上被花費後,才能拿著其被花費的證明到 CKB 鏈上解鎖這個 Cell。 看到這大家可能不免覺得神奇,如何達成讓 Cell 只被指定 UTXO 解鎖? 其實就是前面提到 CKB 在設計時就預留的,鏈原生的密碼抽象 LockScript(解鎖腳本)。在這些 RGB++ 交易相關的 Cell 上,不是設定以橢圓曲線算法解鎖,而是專為 RGB++ 開發的解鎖腳本「RGB++ lock」—— 必須拿花費此 UTXO 的已上鏈 BTC Tx 當參數,並且符合特定規則,才能解鎖。細節可以參考合約規範文檔: github.com/ckb-cell/RGBPlusP… 如此一來,就讓 RGB++ 交易達成了: 1. 安全性由 Bitcoin 網路保證(LockScript 指定 UTXO 花費後解鎖) 2. 可編程性由 CKB 網路擴展(TypeScript 支持任意合約邏輯) 交易折疊: 「為了進一步利用 L2(也就是 CKB )的可編程能力和更快更便宜的交易體驗,可以將 RGB++ 資產跳到 L2 ,在 L2 做完一系列操作後,再將結果跳回與 L1 (Bitcoin) 綁定,前後只需要各一筆 RGB++ 交易,中間在 L2 的無數交易相當於被折疊起來」 RGB++ 中由於同構綁定機制,資產跨鏈不需要用橋,團隊為其取了個生動的詞「跳(Leap)」。 實際上交易折疊可分為三個部分: 1. L1 → L2 Leap 2. L2 Txs 3. L2 → L1 Leap 交易折疊是三步合在一起的稱呼,但其實三步個別獨立執行也是合法的,可以只做 1+3 (類似原本的 RGB++ 交易),只做 2+3 (將 L2 資產轉為 RGB++ 資產),或只做 1+2(將 RGB++ 資產跳到 L2 執行一些操作後停留在 L2)。 這邊看似複雜,其實不然。 我們知道每筆 RGB++ 交易通常都包含 L1 和 L2 各一筆交易,[乘載承諾的 L1 交易] 和 [創建 Shadow Cell 乘載動作的 L2 交易]。 折疊的第一步是將原本由 UTXO 控制的 Shadow Cell 改成以用戶指定的 L2 錢包控制(只改變 LockScript),可以理解為將 RGB++ 資產從 RGB++ 協議分離出來到這個 Cell 上(其實轉換過程中需要等待六個 Bitcoin 區塊的確認,這邊先省略)。 而這個 Cell 由於不再受 UTXO 控制,可以在 L2 上盡情使用,也就是折疊的第二步。 此時,由於這個資產已從 RGB++ 協議分離出來,他在 L2 上的任何動作和改動,都不算是完整的 RGB++ 交易,必須通過折疊的第三步與 UTXO 重新結合,才能重新認定為 RGB++ 資產。 說到結合,其實就是將 [分離 Cell 的最終狀態] 的擁有者從你的錢包轉換成為某個 UTXO,也就是將它的 LockScript 改回使用 RGB++ lock 及指定的 UTXO。 前面說到折疊第一步的轉換過程需要六個區塊確認,是為了防止 Bitcoin 交易如果被 revert 而可能產生的惡意攻擊風險,因此其實是會將 RGB++ lock 轉換成一個稱為 BTC_Time_Lock 的鎖,當它確認這筆 Bitcoin 交易超過六個區塊確認後,才會再轉換成你在 L2 的錢包鎖。 細節可參考: talk.nervos.org/t/rgb-1/7798 ** RGB++ 協議並不等於 RGB 協議,而是他的改良版,這邊為了將重點聚焦在 RGB++ 的介紹而刻意省略與 RGB 相關的部分,感興趣的夥伴可以閱讀 Light Paper 或這篇推文:teapaw.org/jason_chen998/status/1… 一些剛接觸時可能會有的疑問: Q1: RGB++ 好像是在兩條平行鏈上各發一筆交易再相互參照來達成,但沒有強制託管和鎖倉,如果我不管另一邊,只在單邊發起交易會如何? A: 大概率燒掉。 首先,只有 Bitcoin 上能單邊發起交易,因為不論有沒有 RGB++, UTXO 的控制權一直屬於你。但當你單方面花掉這個 UTXO 而沒有在這筆交易中寫上新的「承諾 Commitment」(所有動作哈希),雖然能拿著 UTXO 的花費證明到 CKB 上,但 RGB++_lock 無法確認你在 CKB 上即將要做的動作與 Bitcoin 上的承諾匹配,因為找不到承諾,所以不讓這個 Shadow Cell 解鎖。而這個 Shadow Cell 的擁有者 UTXO 已經被花費掉了,代表永遠沒人能再解鎖他,因此形同燒掉。 如上所說,CKB 上的 Shadow Cell 擁有者是 UTXO 而不是你的錢包,因此無法在 CKB 上發起單邊 RGB++ 交易。 Q2: 聽說把 RGB++ 中 Bitcoin 的交易加速,可能會讓資產燒掉,為什麼? A: 最大的可能是 Bitcoin TxID 被改變了,但上鏈的 Commitment 內容沒有跟著修改。 這裡要知道的是 UTXO 其實就是用 TxID + Index 來辨認的。 假設加速前是 TxID_A,加速後變為 TxID_B,但 Commitment 的內容仍然是指定 TxID_A 中的 UTXO 當 Shadow Cell 的擁有者,加速後依照 Commitment 將 Shadow Cell 創建出來,但由於找不到 TxID_A ,所以這個 Shadow Cell 之後也就永遠無法被解鎖。 Commitment 內容及 RGB++ lock 解鎖方式細節可參考:github.com/ckb-cell/RGBPlusP… 一些開始接觸生態會遇到的名詞: - Spore: 可理解為一個 NFT 載體,每個 Spore 上存一個 NFT。不想要時可以銷毀並取回用來乘載的 CKB - Cluster: 一個 NFT Collection ,和 Spore 有從屬關係,Spore 創建時能指定隸屬的 Cluster - DOB (Digital Object): 建立在 Spore 上的一種 NFT 機制,這種 NFT 具有 DNA 及可客製化的 DNA 解碼函式。DOB/0 為 DOB 的第一個版本, DOB/1 也在推進中 - xUDT: CKB 上廣泛使用的同質化代幣協議,可理解為 ERC20 進階一點: - code_hash: 一段 hash 用來分辨要使用哪份 code - hash_type: 定義上述的 code_hash 是從哪部分取的 hash ,可以是 TypeScript 部分或是 Data 部分,有不同的功用。用 TypeScript 取的話代表這是一份可升級腳本,用 Data 取的話代表 Code 的內容不能有任何修改。(每份 code 也是當一個 Cell 部署在鏈上,稱為 Code Cell ,Code Cell 的 Data 欄位就是存放 Code 的執行碼) - CKB 地址就是從 LockScript + args 得來的,查找地址等於查找特定 LockScript + args 特別感謝 @chestersigned 幫忙 review! 一些文件及學習管道: - Messari 研報(英文) messari.io/report/understand… - RGB++ Light Paper(中文) talk.nervos.org/t/rgb-protoc… - RGB++ 安全性分析(中文) talk.nervos.org/t/rgb-1/7798 - RGB++ lock & BTC_Time_Lock(中文) github.com/ckb-cell/RGBPlusP… - CKB 開發公開課 | 登鏈社區(中文課程錄影) learnblockchain.cn/course/53… youtu.be/pM--3N0gwJk?si=s-cZ… - RGB++ SDK(GitHub) github.com/ckb-cell/rgbpp-sd… - Spore 文件(英文) docs.spore.pro/ 一些生態項目: @Nervapes : 我個人目前最愛的 RGB++ 項目,已在 CKB 耕耘多年,這次藉著 RGB++ 讓 NFT 有了不一樣的玩法,神經猿不只是一張圖,而是能穿梭於 Bitcoin & CKB 的猴子,在 CKB 上穿脫各種裝備,再把本體包含身上的裝備跳回 Bitcoin(開發中) @joy_protocol : RGB++ & CKB 上最廣泛使用的 PassKey 錢包,乾淨整潔,非常好用。除了錢包功能,也有開發 Marketplace @HueHubOfficial : RGB++ 在 L1 的 Marketplace 和 Launchpad @OmigaHQ : CKB 上的 DEX @UTXOSwap : RGB++ AMM DEX @MarketDobby : RGB++ DOB Marketplace @DIDbased : CKB 上的 .bit 域名服務 @dobhub : DOB Launchpad 如果有遺漏的再請大家幫忙補充了 #BTC #BTCFi #BiFi #CKB #RGB #RGBPP
4
17
2
55
4,140
【一文讀懂 BTCFi 黑馬 —— RGB++】 趁著市場回暖,來寫一篇這輪主要賽道之一 BTCFi 的黑馬,RGB++ 協議。 相信許多關注此賽道的人都聽過 RGB++ ,不論是在快訊中、從 CKB 價格發現,或從六月底 @MessariCrypto 釋出的研報中看到,然後查了一些介紹及文件,看到了幾個不明覺厲的新名詞,卻還是似懂非懂,我也是。所以希望寫一篇入門的介紹(懶人包),整理自己的理解,從剛接觸者的角度去解構這個協議,會盡量只做重點和必要的介紹,避免過多資訊影響理解,如果對細節有興趣可以再從文件或白皮書找答案,文末會附上一些參考。 @NervosNetwork 是上一輪的天王級項目,從測試網時期就在關注他們,可惜上一輪市場的資源和關注度都在 EVM 和 Solana 生態,讓 CKB 沒有太大發揮。 然而團隊沒有放棄,在過去幾年間持續完善基礎設施及開發工具,終於在這一輪遇上 BTCFi 的爆發,憑藉著其獨特的 UTXO 擴展架構,Nervos Network 聯創 @crypcipher 提出了 RGB++ 協議 ——— 一個無須跨鏈橋的 BTCFi 可編程和性能擴展協議。 首先需要先對 CKB 有基本的認識: CKB 這個詞可以指的是這條鏈(Common Knowledge Base),也可以是這條鏈的原生代幣(CKByte)。 當指的是幣時,CKB 可以用來當 gas 付給礦工,也可以用來計算鏈上的佔用空間,1 CKB 就代表能佔用一個 Byte。 這裡就能帶出 CKB 這條鏈,和 Bitcoin 同樣是 UTXO 架構,但其中的每個 UTXO 都被擴增成稱為 Cell 的模型,每個 Cell 由四個部分組成: Capacity(容量), Data(資料), LockScript(解鎖腳本), TypeScript(業務邏輯腳本) - Capacity(容量): 用來定義這個 Cell 總共能在鏈上佔用多少 Bytes,同時也代表需要花費多少 CKB 來乘載這個 Cell(消除這個 Cell 時能取回) - Data(資料): 存放任意資料,可以是代碼、文字、圖片、影片或其他任何形式 - LockScript(解鎖腳本): 控制此 Cell 如何能被解鎖,由於沒有在鏈本身寫死,因此極具靈活性。在創建 Cell 時可以任意指定,可以使用普遍的橢圓曲線簽章算法,也可以自己實作其他算法,甚至使用簡易的四則運算,知道答案者就能解鎖(不建議)。 這非常關鍵,是鏈級別的密碼抽象(或理解為帳戶抽象),使其能模擬其他任何鏈的加解密算法,用那些鏈的錢包就能無縫直接在 CKB 上操作。也是其他 UTXO 鏈無法輕易模仿/抄襲 RGB++ 概念的主因。 - TypeScript(業務邏輯腳本): 與 LockScript 大致相同,只是通常使用於業務邏輯。唯一差異(暫時不理解不影響後面篇章),在於 LockScript 只對 inputs 做驗證,而 TypeScript 會對 inputs 和 outputs 都做驗證。 接著切入主題 RGB++ 可以用一句話概括: 「每筆 RGB++ 交易都會在 Bitcoin 和 CKB 各發送一筆交易,透過一次性密封、同構綁定和客戶端驗證技術,為 RGB++ 資產提供了與 Bitcoin 同等的安全性,同時具有可編程性及性能擴展,無需跨鏈」 這邊會刻意刪掉一些細節,盡量用簡易好懂的敘述讓大家先對整體協議有基本的認識,想鑽研細節可以再自行閱讀 Light Paper: talk.nervos.org/t/rgb-protoc… 一次性密封: 「將與此 RGB++ 交易相關的所有動作取哈希後,寫在指定的 UTXO 交易上」 就是把一段哈希寫在 Bitcoin OP_RETURN 上。 UTXO 本身受到了 Bitcoin 網路的保護,有不可篡改且只能使用一次的特性,透過這個方式,將 RGB++ 交易與 UTXO 進行了連結,為 RGB++ 交易提供了狀態鎖定的保護。 所有動作取哈希這個動作稱為「承諾(Commitment)」。 同構綁定: 「將與此 RGB++ 交易相關的所有動作執行,並記錄到一個 CKB Cell 上,這個 Cell 的所有者為一次性密封指定的 UTXO。這類 Cell 如同 UTXO 的影子,也稱為 Shadow Cell」 除了 UTXO 的變動發生在 Bitcoin 上,RGB++ 交易的其餘部分都會在 CKB 鏈上被執行與驗證,並把結果記錄在一個新的 Cell 上,這個 Cell 只有在一次性密封的 UTXO 在 Bitcoin 上被花費後,才能拿著其被花費的證明到 CKB 鏈上解鎖這個 Cell。 看到這大家可能不免覺得神奇,如何達成讓 Cell 只被指定 UTXO 解鎖? 其實就是前面提到 CKB 在設計時就預留的,鏈原生的密碼抽象 LockScript(解鎖腳本)。在這些 RGB++ 交易相關的 Cell 上,不是設定以橢圓曲線算法解鎖,而是專為 RGB++ 開發的解鎖腳本「RGB++ lock」—— 必須拿花費此 UTXO 的已上鏈 BTC Tx 當參數,並且符合特定規則,才能解鎖。細節可以參考合約規範文檔: github.com/ckb-cell/RGBPlusP… 如此一來,就讓 RGB++ 交易達成了: 1. 安全性由 Bitcoin 網路保證(LockScript 指定 UTXO 花費後解鎖) 2. 可編程性由 CKB 網路擴展(TypeScript 支持任意合約邏輯) 交易折疊: 「為了進一步利用 L2(也就是 CKB )的可編程能力和更快更便宜的交易體驗,可以將 RGB++ 資產跳到 L2 ,在 L2 做完一系列操作後,再將結果跳回與 L1 (Bitcoin) 綁定,前後只需要各一筆 RGB++ 交易,中間在 L2 的無數交易相當於被折疊起來」 RGB++ 中由於同構綁定機制,資產跨鏈不需要用橋,團隊為其取了個生動的詞「跳(Leap)」。 實際上交易折疊可分為三個部分: 1. L1 → L2 Leap 2. L2 Txs 3. L2 → L1 Leap 交易折疊是三步合在一起的稱呼,但其實三步個別獨立執行也是合法的,可以只做 1+3 (類似原本的 RGB++ 交易),只做 2+3 (將 L2 資產轉為 RGB++ 資產),或只做 1+2(將 RGB++ 資產跳到 L2 執行一些操作後停留在 L2)。 這邊看似複雜,其實不然。 我們知道每筆 RGB++ 交易通常都包含 L1 和 L2 各一筆交易,[乘載承諾的 L1 交易] 和 [創建 Shadow Cell 乘載動作的 L2 交易]。 折疊的第一步是將原本由 UTXO 控制的 Shadow Cell 改成以用戶指定的 L2 錢包控制(只改變 LockScript),可以理解為將 RGB++ 資產從 RGB++ 協議分離出來到這個 Cell 上(其實轉換過程中需要等待六個 Bitcoin 區塊的確認,這邊先省略)。 而這個 Cell 由於不再受 UTXO 控制,可以在 L2 上盡情使用,也就是折疊的第二步。 此時,由於這個資產已從 RGB++ 協議分離出來,他在 L2 上的任何動作和改動,都不算是完整的 RGB++ 交易,必須通過折疊的第三步與 UTXO 重新結合,才能重新認定為 RGB++ 資產。 說到結合,其實就是將 [分離 Cell 的最終狀態] 的擁有者從你的錢包轉換成為某個 UTXO,也就是將它的 LockScript 改回使用 RGB++ lock 及指定的 UTXO。 前面說到折疊第一步的轉換過程需要六個區塊確認,是為了防止 Bitcoin 交易如果被 revert 而可能產生的惡意攻擊風險,因此其實是會將 RGB++ lock 轉換成一個稱為 BTC_Time_Lock 的鎖,當它確認這筆 Bitcoin 交易超過六個區塊確認後,才會再轉換成你在 L2 的錢包鎖。 細節可參考: talk.nervos.org/t/rgb-1/7798 ** RGB++ 協議並不等於 RGB 協議,而是他的改良版,這邊為了將重點聚焦在 RGB++ 的介紹而刻意省略與 RGB 相關的部分,感興趣的夥伴可以閱讀 Light Paper 或這篇推文:teapaw.org/jason_chen998/status/1… 一些剛接觸時可能會有的疑問: Q1: RGB++ 好像是在兩條平行鏈上各發一筆交易再相互參照來達成,但沒有強制託管和鎖倉,如果我不管另一邊,只在單邊發起交易會如何? A: 大概率燒掉。 首先,只有 Bitcoin 上能單邊發起交易,因為不論有沒有 RGB++, UTXO 的控制權一直屬於你。但當你單方面花掉這個 UTXO 而沒有在這筆交易中寫上新的「承諾 Commitment」(所有動作哈希),雖然能拿著 UTXO 的花費證明到 CKB 上,但 RGB++_lock 無法確認你在 CKB 上即將要做的動作與 Bitcoin 上的承諾匹配,因為找不到承諾,所以不讓這個 Shadow Cell 解鎖。而這個 Shadow Cell 的擁有者 UTXO 已經被花費掉了,代表永遠沒人能再解鎖他,因此形同燒掉。 如上所說,CKB 上的 Shadow Cell 擁有者是 UTXO 而不是你的錢包,因此無法在 CKB 上發起單邊 RGB++ 交易。 Q2: 聽說把 RGB++ 中 Bitcoin 的交易加速,可能會讓資產燒掉,為什麼? A: 最大的可能是 Bitcoin TxID 被改變了,但上鏈的 Commitment 內容沒有跟著修改。 這裡要知道的是 UTXO 其實就是用 TxID + Index 來辨認的。 假設加速前是 TxID_A,加速後變為 TxID_B,但 Commitment 的內容仍然是指定 TxID_A 中的 UTXO 當 Shadow Cell 的擁有者,加速後依照 Commitment 將 Shadow Cell 創建出來,但由於找不到 TxID_A ,所以這個 Shadow Cell 之後也就永遠無法被解鎖。 Commitment 內容及 RGB++ lock 解鎖方式細節可參考:github.com/ckb-cell/RGBPlusP… 一些開始接觸生態會遇到的名詞: - Spore: 可理解為一個 NFT 載體,每個 Spore 上存一個 NFT。不想要時可以銷毀並取回用來乘載的 CKB - Cluster: 一個 NFT Collection ,和 Spore 有從屬關係,Spore 創建時能指定隸屬的 Cluster - DOB (Digital Object): 建立在 Spore 上的一種 NFT 機制,這種 NFT 具有 DNA 及可客製化的 DNA 解碼函式。DOB/0 為 DOB 的第一個版本, DOB/1 也在推進中 - xUDT: CKB 上廣泛使用的同質化代幣協議,可理解為 ERC20 進階一點: - code_hash: 一段 hash 用來分辨要使用哪份 code - hash_type: 定義上述的 code_hash 是從哪部分取的 hash ,可以是 TypeScript 部分或是 Data 部分,有不同的功用。用 TypeScript 取的話代表這是一份可升級腳本,用 Data 取的話代表 Code 的內容不能有任何修改。(每份 code 也是當一個 Cell 部署在鏈上,稱為 Code Cell ,Code Cell 的 Data 欄位就是存放 Code 的執行碼) - CKB 地址就是從 LockScript + args 得來的,查找地址等於查找特定 LockScript + args 特別感謝 @chestersigned 幫忙 review! 一些文件及學習管道: - Messari 研報(英文) messari.io/report/understand… - RGB++ Light Paper(中文) talk.nervos.org/t/rgb-protoc… - RGB++ 安全性分析(中文) talk.nervos.org/t/rgb-1/7798 - RGB++ lock & BTC_Time_Lock(中文) github.com/ckb-cell/RGBPlusP… - CKB 開發公開課 | 登鏈社區(中文課程錄影) learnblockchain.cn/course/53… youtu.be/pM--3N0gwJk?si=s-cZ… - RGB++ SDK(GitHub) github.com/ckb-cell/rgbpp-sd… - Spore 文件(英文) docs.spore.pro/ 一些生態項目: @Nervapes : 我個人目前最愛的 RGB++ 項目,已在 CKB 耕耘多年,這次藉著 RGB++ 讓 NFT 有了不一樣的玩法,神經猿不只是一張圖,而是能穿梭於 Bitcoin & CKB 的猴子,在 CKB 上穿脫各種裝備,再把本體包含身上的裝備跳回 Bitcoin(開發中) @joy_protocol : RGB++ & CKB 上最廣泛使用的 PassKey 錢包,乾淨整潔,非常好用。除了錢包功能,也有開發 Marketplace @HueHubOfficial : RGB++ 在 L1 的 Marketplace 和 Launchpad @OmigaHQ : CKB 上的 DEX @UTXOSwap : RGB++ AMM DEX @MarketDobby : RGB++ DOB Marketplace @DIDbased : CKB 上的 .bit 域名服務 @dobhub : DOB Launchpad 如果有遺漏的再請大家幫忙補充了 #BTC #BTCFi #BiFi #CKB #RGB #RGBPP
深度解析RGB → RGB++ → RGB++Layer之间的演进到底发生了什么?RGB++协议近日完成了RGB++ Layer升级,可以将无桥跨链和智能合约扩展到BCH、BSV、Dogecoin这些所有UTXO链,并支持Runes、BRC20等其他Layer 1资产协议,RGB++ Layer的首个DEX UTXOSwap也同步上线主网,根据计划后续生态还会继续推出单独的浏览器、IBO等平台,再来聊聊RGB++以及这轮牛市的大黑马CKB吧,探讨RGB++与RGB之间的关系,以及为什么要将RGB++升级为RGB++ Layer。 首先要了解RGB和RGB++的区别,RGB的创始人是美国国家科学院博士@dr_orlovsky,也是非营利比特币发展组织LNP/BP 协会的技术委员会老大,而RGB++的创始人是CKB的联合创始人@crypcipher。 RGB的定义是为比特币和闪电网络提供一套可扩展的智能合约系统,通过UTXO结合客户端验证的方式完成链下扩容,这也意味着所有数据都保存在比特币交易之外。其核心思想是仅在必要的时候调用比特币区块链,所有Token的转移有效验证全部从共识层移出到链下,并只由这条交易相关的收款方客户端进行验证,所以客户端验证与我们所熟悉的一条交易要全网广播不同,而是通过只让和特定交易有关系的部分节点参与到工作中,从而完成该交易的有效性验证,这在一定程度上也加强了RGB协议的隐私性。 作为链下的客户端验证与链上比特币网络本身之处在于将原生的UTXO魔改创造出了“一次性密封条”概念用于智能合约的状态转换。根据比特币的规则每个UTXO只能被花费一次,所以可以巧妙的将它的特性利用作为一个密封条,在创建UTXO时相当于密封条上锁,在花费它的时候则密封条打开,RGB则利用UTXO为任何拥有智能合约的一方提供了验证其唯一性的能力,尽管将数据存在链下但通过UTXO绑定在链上,换句话说RGB利用比特币原生脚本作为其所有权和访问权的安全性来源,其实读到这里会感觉与Ordinals协议很类似,都是在已经改无可改的比特币网络上去利用现有的东西物尽其用挖掘出更多意想不到功能的“奇技淫巧”过程。 所以RGB本身只是一种用于扩展比特币的客户端验证技术,不是一个网络也不是一条区块链,严格意义上RGB并不能称之为BTC Layer2,但通过RGB可以赋予比特币一部分以太坊等智能合约所实现的能力,包括发Token、NFT、Defi甚至游戏等。 但尽管如此这一轮比特币生态爆火的ARC20、BRC20等资产发行协议都没有用RGB的链下客户端验证架构,主要在于其链下的业务逻辑很复杂工程量庞大,以及用户体验也难以理解,因为上文中说到的绑定UTXO,即两个用户使用RGB协议转让资产的时候不是提供自己的比特币地址,而是自己比特币的UTXO,每一个人给我的每一次转账都需要新创建一个UTXO,以及之前提到的点对点客户端验证过程中的隐私优势在有的场景也变成了劣势,当某个场景存在超过2个以上角色或者需要第三方参与时,只有交易双方可见数据的限制就会导致需要再做大量额外的工作去实现对应的业务逻辑,反而降低了可组合性和扩展性。 RGB++则是一条真正的“链”,其思想依然沿用RGB的将链上和链下分别创造一个交易并进行绑定的思想,不同之处在于既然客户端验证的目的本质上是为了将更多比特币网络无法存储的数据和无法实现的智能合约移到链下,并创建对应的交易与链上进行绑定,那为什么不直接用一个现成的图灵完备的UTXO链来“打包”替代掉客户端验证在做的事情,去和比特币这样一个图灵不完备的UTXO链相结合绑定呢?与其他EVM系BTC Layer2不同,因为都使用UTXO模型所以可以使得这两条链的UXTO进行一一绑定,我们将这个链称之为比特币的影子链,这样每移动一个比特币UTXO,影子链的UTXO也同步进行移动,从而通过这样的方式实现比特币链的图灵完备性,RGB++也称其为同构绑定。 而CKB作为一条图灵完备的UTXO链自然也就成为比特币的影子链,所有RGB++的交易都会同时在比特币和CKB上同步出现一笔交易,CKB取代了客户端验证的流程,用户只需要检查CKB上的相关交易就可以验证这笔RGB++的状态计算是否正确,从而极大的简化了客户端验证的工作。资产所有权依然由比特币主链的UTXO持有,CKB影子链则存储资产状态、智能合约等信息,所以也依然继续沿用比特币的安全性。并且因为CKB本身也是一条公链,无需像RGB客户端验证那样用户每次转账都需要提供新的UTXO地址,而是可以直接提供自己独立的钱包地址,也提高了用户体验。 而这一次RGB++ Layer的升级则是将比特币与CKB之间的关系扩展到所有UTXO链,即之前是CKB使用RGB++协议作为比特币的影子链,而现在RGB++协议单独抽象独立出来作为一层,可以与所有UTXO链相结合,打造成一个通用的、可跨链互操作的UTXO中间层,不再只是将CKB作为RGB++的索引器,可以将任意图灵完备的UTXO链作为其索引器,此外BTC、CKB、BSV、BCH等任何UTXO链的资产都可以进入RGB++生态,将各类铭文、符文等资产都可以变为RGB++ Layer上的资产。以及这里有个误区,即不只是比特币及其生态才会使用UTXO模型,如以太坊的执行层模块化Layer2 Fuel也是使用的UTXO,老牌Layer1公链Cardano也是UTXO,这些都可以进入RGB++生态。 因为传统的跨链桥是在主链上锁定或销毁掉资产并在子链上铸造出来对应数量的“假币”,然后在不跨回主链之前所有的资产交互全部都在子链完成,与主链无关,而RGB++使用UTXO同构绑定的特点则是两条链的交互完全1:1进行,不存在“跨链”的说法,你在Layer2上的操作本来就会直接影响到Layer1,所以且基于UTXO模型可以通过RGB++ Layer作为一个“无桥”的跨链桥,从而打通所有UTXO链的互操作性和资产流动性,资产内容丰富起来、流动性聚集后,将贫瘠的土壤变肥沃后,也就为后续更多比特币Defi玩法创建了前提条件。 所以这次RGB++ Layer的升级的主要目的也是为了促进实现Bitcoin Finance (BTCFi) 的发展,目前主要的用例包括UTXOSwap和IBO平台,UTXOSwap会作为RGB++ Layer的核心枢纽用来聚合各种UTXO链的资产流动性,得益于UTXO的特性,其实现链下撮合链上验证的过程,从而可以在撮合阶段接入AMM之外的流动性提供者,未撮合的交易也无需支付Gas费,并且可以选择任意Token作为Gas支付。IBO平台则是由RGB++的第一个资产Seal的社区开发运营,也属于比特币生态的第一个IBO工具,针对整个RGB++的Launchpad。 除了将存量的UTXO链进入RGB++外,一键发链平台UTXO Stack(其创始人同样也是RGB++创始人)可以发布UTXO架构的BTC Layer2并原生集成RGB++协议能力,从而创造增量UTXO链进入RGB++,UTXO Stack也获得了OKX、ABCDE、SNZ等投资。 所以RGB++ Layer2目前在资产和公链层面都具备了导入存量、创建增量的能力,其带来的BTCFi应用场景值得关注。
5
32
4
67
11,259
16/ A community built Dune dashboard shows that there are already ~283k SOL in their treasury and is increasing over 10k SOL a day on average in the past week. dune.xyz/yehjames/STEPN
1
9
Replying to @okx
Great Meetup!!