banner
CKB 中文

CKB 中文

CKB 是理想的比特币 Layer 2

Implementation of CKB Stablecoin Payment

1. Overview#

CKB stablecoin payment is a decentralized stablecoin payment solution based on the CKB network, allowing users to generate and manage the USD-pegged stablecoin RUSD through a joint network of CKB and Bitcoin, utilizing Layer 2 expansions such as RGB++ and Fiber Network, achieving fast, low-cost, and secure cross-chain stablecoin payments.

2. Introduction to Core Components#

2.1 CKB (Common Knowledge Base)#

Image1

2.1.1 What is CKB#

CKB is the Layer 1 blockchain of the Nervos Network, whose main functions can be summarized as Consensus & Execution and Data Availability, enhancing scalability through payment channels and RGB++ built on top of it.

It is based on the PoW consensus mechanism, similar to BTC, and uses an upgraded BTC algorithm NC-MAX, which improves network efficiency and responsiveness by accelerating transaction confirmation times and reducing orphan block rates. Unlike BTC's fixed interval of one block every 10 minutes, CKB dynamically adjusts block intervals based on network activity (approximately every four hours), optimizing performance.

CKB employs the Eaglesong hash function, a hash function specifically customized for the Nervos Network, serving as an alternative to SHA-256, providing the same level of security.

CKB uses the Cell model as the core of its data structure, which is an improved version of BTC's UTXO accounting model:

  • Through a dual-script system, it allows for more flexible data storage and verification, supporting asset issuance and smart contract execution.

  • It provides data storage and state management functions, ensuring the long-term availability of all on-chain assets and data.

2.1.2 Cell Model#

Cell Model and Its Features:

  • The Cell model is similar to BTC's UTXO model but achieves on-chain data storage and verification of smart contract scripts through the introduction of dual scripts.
  • Store any type of data or asset: In BTC's UTXO model, each transaction output can only contain simple amount information and ownership; whereas each Cell in CKB can store smart contract code and trigger these scripts to execute in transactions through external calls, meaning each Cell can independently execute the smart contract logic associated with it, having programmability.
  • Separation of state and computation: Since Cells store the code and state of smart contracts, complex computational tasks can be executed independently by each Cell on Layer 2 or off-chain, with the execution results synchronized back to Layer 1 through transactions, ensuring network security and data consistency.
  • Parallel execution and transaction bundling: Through the Cell model, smart contracts in different Cells can achieve parallel execution, while the transaction results of different Cells can be bundled and updated on-chain, making this method more efficient and reducing transaction costs.
    Image2

How the Cell Model Works:

  • Cells consist of inputs and outputs: Similar to BTC's UTXO model, Cells execute transactions and state updates through inputs and outputs. Each Cell can be spent as an input in a transaction, generating new outputs and creating new Cells.
  • Elements of a Cell: Each Cell contains Capacity, Updated Data, Lock Script, and Type Script.
  • Capacity: Capacity records the size of the storage space of the Cell and represents the storage value of CKB tokens. Users creating Cells need to allocate a certain amount of Capacity based on the data volume to ensure effective utilization of on-chain storage space.
  • Data: This is one of the core features of the Cell model, allowing the storage of any information from simple numbers to complex smart contract states, enabling the storage of diverse data on the blockchain.
  • Dual-script system: The Lock Script is used for authentication, similar to BTC's signature mechanism, preventing unauthorized users from accessing or modifying data in the Cell. Users must provide the correct signature or multi-signature to unlock and use the Cell; the Type Script defines the data validation logic of the Cell, setting rules for how the Cell can be used or changed in future transactions, determining the legality of transactions or states through smart contract execution or rule validation.
  • Live Cell & Dead Cell: A Live Cell refers to a Cell that has not yet been spent and can still be used as input for the next transaction or state update; once a Cell is spent, it becomes a Dead Cell and can no longer be used, but its historical record remains on-chain to ensure traceability.
  • State leasing mechanism: Users need to pay CKB tokens to lease storage space on the chain, ensuring long-term data storage while preventing state bloat.

Image3

2.1.3 Programmability & CKB-VM#

The Cell model is the foundation of CKB's programmability: It supports storing the state and execution scripts of smart contracts in each Cell, tightly integrating contract execution and asset management.

Through the Turing-complete RISC-V virtual machine (CKB-VM), developers can execute custom smart contracts on-chain. The flexibility of the RISC-V instruction set gives developers more freedom to write contracts, enabling CKB to support complex contract logic.

CKB-VM supports multiple languages: Including popular languages such as C and Rust. This broad compatibility distinguishes CKB-VM from other blockchain virtual machines that are typically limited to specific languages, opening it up to a wider developer community. The CKB network also supports SDKs for mainstream languages like JavaScript, Rust, Go, and Java, making it easier for developers to use familiar tools for development.

Compatibility and scalability: The design of CKB-VM ensures compatibility with BTC's UTXO model and other blockchains while supporting highly scalable smart contracts and complex applications.

2.1.4 PoW Consensus Mechanism#

CKB adopts a PoW consensus mechanism similar to BTC, ensuring the security and decentralization of the network. Like BTC, miners compete to compute hash values to package blocks, ensuring the immutability and censorship resistance of the network.

NC-MAX Algorithm: Compared to BTC, CKB introduces the improved NC-MAX algorithm. This improvement allows for higher throughput and optimizes block packaging efficiency, reducing orphan block rates and enhancing transaction confirmation speeds, making it suitable for large-scale application scenarios such as asset storage and payment settlement.

Eaglesong Hash Function: The custom design of the Eaglesong hash function provides performance and security advantages for the Nervos CKB network through ASIC neutrality, efficiency, security, and network fairness, ensuring decentralization while enhancing mining efficiency and network scalability.

2.1.5 Multi-layer Security Architecture#

CKB employs a multi-layer security architecture: Layer 1 focuses on the final settlement of data and the secure storage of states, while Layer 2 is used to expand transaction processing capabilities.

The separated architecture ensures the security of the main chain (Layer 1): Reducing the load during transaction processing and improving the overall stability of the network.

2.1.6 Connection and Orthodoxy with BTC#

Cross-chain interoperability of the UTXO model:

  • The Cell model of CKB is an extension of the BTC UTXO model. BTC users can map their assets to the CKB network, leveraging the flexibility of the CKB network for storage, smart contract operations, and decentralized finance (DeFi) applications.
  • Since Cells are structurally similar to BTC UTXOs and CKB can be compatible with BTC signature algorithms, users can manipulate CKB on-chain assets using BTC wallets, and the same applies to other UTXO public chains.

Orthodoxy: CKB maintains ideological consistency with BTC by adopting NC-Max (Nakamoto Consensus Max), which is an improved version of Nakamoto consensus, providing better security and performance.

Community Support: The Nervos community consists of numerous blockchain technology enthusiasts, developers, and miners, and has received support from parts of the BTC community. Its orthodoxy lies in inheriting BTC's decentralization philosophy while meeting broader needs through extended functionalities.

2.1.7 The Role of CKB in Stablecoin Payments#

Storage and management of stablecoin balances: The Cell model of CKB is the foundation for stablecoin storage, with users' stablecoin balances such as RUSD stored in Cells on-chain. Each Cell contains complete balance information, ensuring the security and traceability of assets.

Recording transaction states: CKB supports recording every state change of transactions on-chain, allowing all payment processes to be transparently recorded and tracked through the Cell model. This mechanism is crucial in stablecoin payments, ensuring the security and verifiability of transactions.

Execution of smart contracts: Complex operations such as conditional payments and locks during the stablecoin payment process can be implemented through smart contracts supported by CKB-VM.

2.2 RGB++#

2.2.1 What is RGB++#

RGB++ is a decentralized asset issuance and smart contract protocol suitable for the Bitcoin UTXO model and other UTXO public chains.

The RGB++ protocol inherits the idea of creating a transaction on-chain and off-chain and binding them from the RGB protocol. The difference is that RGB utilizes client-side validation to move more data and smart contracts that cannot be stored on the BTC network off-chain, creating corresponding transactions bound to the chain, while RGB++ moves this unstoreable data and unimplementable smart contracts to CKB, making CKB the smart contract settlement layer for BTC.

2.2.2 Basic Functions#

Through RGB++, CKB acts as a shadow chain for BTC: As a supplementary chain to BTC, it handles complex logic and smart contract operations that BTC natively cannot process.

Interacting with the BTC network

  • Transaction Occurrence: In the BTC network, users complete transactions through the conventional UTXO model, while the parts involving smart contract execution bind the contract state and data to CKB through RGB++.
  • Validation Logic: Transaction records conducted on the BTC network will synchronize with the contract states stored on CKB through RGB++, ensuring the legality of transactions through specific validation logic. Whenever a transaction occurs on the network, RGB++ triggers contract execution on CKB, checking whether the transaction meets predetermined rules, such as whether the balance is sufficient, whether the signature is valid, and whether the contract conditions are satisfied.

RGB++ uses a client-side validation model to ensure the privacy and integrity of off-chain data, submitting data to CKB for final settlement only after off-chain validation passes.

Asset issuance and management: RGB++ allows users to issue assets (such as stablecoins, tokens, etc.) through off-chain protocols and use CKB to manage the lifecycle of these assets (including not only asset issuance and circulation but also more complex operations such as time locks and conditional payments).

RGB++ combines the high security of BTC with the programmability of CKB.

2.2.3 Isomorphic Binding#

Image4

Cross-chain synchronization of assets & states: Isomorphic binding refers to maintaining synchronization of assets and states between BTC and CKB (or other UTXO public chains, such as Cardano) through a binding mechanism. Whenever an asset transaction occurs on the BTC chain, RGB++ maps the corresponding contract state or asset change on CKB.

Extended UTXO: In isomorphic binding, each UTXO on the BTC chain will have a corresponding Cell (UTXO container) on CKB, recording the corresponding asset state and smart contract conditions.

Asset Binding: When a user holds a certain RGB++ asset on the BTC chain, the corresponding Cell on CKB will store the relevant asset state, ensuring consistency of asset information between the two chains through isomorphic binding.

Transaction Synchronization: When RGB++ token transactions occur, the isomorphic binding mechanism generates a Commitment on the BTC network, consuming the corresponding Cell on the CKB chain, while new Cells are generated to allocate assets.

Advantages of Isomorphic Binding - Empowering BTCFi

  • Smart contract support: BTC cannot natively support Turing-complete smart contracts, but through isomorphic binding, CKB can serve as the execution layer for smart contracts, managing complex transaction conditions for BTC assets, such as time locks and conditional payments.
  • Flexibility in asset management: Isomorphic binding allows for managing assets circulating in the BTC network on CKB, enabling users to execute complex financial operations through CKB's flexible programming capabilities without changing the underlying protocol of BTC.

2.2.4 Leap#

RGB++ Layer upgrade proposal: Expanding the binding relationship between CKB and BTC to all UTXO chains, achieving cross-chain asset transfer through "re-binding."

Bridge-less cross-chain between BTC and other UTXO chains: Its core purpose is to allow RGB++ assets on the BTC chain to seamlessly transfer to other UTXO chains by switching the UTXO that binds the assets, supporting asset management and transfer across multiple blockchains.

Bridge-less technology: Leap achieves cross-chain asset transfer through isomorphic binding technology and switching UTXOs across different chains without relying on traditional Lock-Mint cross-chain bridges.

Operational Process: For example, a user can control RGB++ assets originally on the BTC chain through the Cardano chain and perform asset splitting and transfer on the Cardano chain.

  • Publish Commitment: First, the user needs to publish a Commitment on the BTC chain, declaring the intention to unbind the assets bound to the BTC UTXO.
  • Cardano Chain Binding: Next, publish a new Commitment on the Cardano chain, binding the RGB++ asset to Cardano's eUTXO.
  • Modify Lock Script: Then, modify the lock script of the RGB++ asset on the CKB chain, switching the unlocking conditions from BTC UTXO to Cardano's eUTXO. This step allows asset holders to control assets originally on the BTC chain through the Cardano chain.

The Role of CKB in Leap:

  • CKB acts as an indexer and data availability (DA) layer. All RGB++ asset data is still stored on the CKB chain, with CKB serving as a third-party witness to handle Leap requests and ensure the security of cross-chain assets.
  • CKB provides security and credibility: Compared to the multi-signature or MPC (multi-party computation) mechanisms commonly seen in traditional cross-chain bridges, CKB's security and decentralization attributes are more reliable.

2.2.5 The Role of RGB++ in Stablecoin Payments#

Issuance and circulation of stablecoins: Stablecoins are issued on the BTC chain through RGB++, leveraging CKB for smart management of assets.

Cross-chain asset management: The combination of RGB++ Layer and CKB ensures seamless operation of stablecoin payments across different UTXO chains.

Smart contract support: Provides complex payment conditions, time locks, and other functions for stablecoin payments, enhancing the flexibility and security of payments.

Bridge Role: The RGB++ Layer acts as a bridge between BTC (and other UTXO chains) and CKB, extending BTC's programmability and asset management capabilities, making BTC's stablecoin payment functions more diverse and flexible.

2.3 Fiber Network#

2.3.1 Introduction to Fiber Network#

Fiber Network is a Layer 2 extension solution on CKB similar to the BTC Lightning Network: It is specifically designed to enhance CKB's off-chain payment capabilities, allowing users to make fast and low-cost payments off-chain. It achieves off-chain transactions through payment channels, reducing the pressure on the main chain and increasing transaction speed.

Characteristics of off-chain payments: Fiber Network enables rapid transfers off-chain through payment channels, reducing reliance on the CKB main chain and increasing transaction throughput.

Current Status: As of September 2024, according to mempool data, over $300 million is currently allocated in the BTC Lightning Network, with approximately 12,000 nodes and nearly 50,000 payment channels established between them. The Fiber Network based on Nervos CKB has already launched its testnet.

2.3.2 Technical Highlights#

Off-chain payment channels (Fiber Channels): Fiber Network allows users to directly exchange assets off-chain by creating payment channels, submitting the final state to the CKB main chain for settlement only when the channel is closed.

On-chain contracts (HTLC):

  • Similar to the BTC Lightning Network, Fiber Network now also uses Hash Time-Locked Contracts (HTLC) to ensure the security of off-chain transactions; if an off-chain transaction is not confirmed within the agreed time, assets can be automatically returned through HTLC.
  • PTLC: Fiber Network improves upon HTLC to avoid using the same cryptographic value for the entire payment path, employing PTLC to prevent privacy leakage of transaction associations.

Multi-Hop Routing: Like the BTC Lightning Network, Fiber Network supports payment path jumps through multiple nodes, using the Dijkstra algorithm to search for payment paths, thereby reducing routing costs and increasing the success rate of multi-hop path payments.

Monitoring Service - Watchtower Service: Users can utilize 24/7 monitoring services to track the status of payment channels, preventing malicious nodes from attempting double spending or cheating (preventing transaction participants from submitting expired commits on-chain). This service can automatically track transactions and issue alerts.

2.3.3 Differences Between Fiber Network and BTC Lightning Network#

Multi-asset support:

  • BTC Lightning Network previously only supported off-chain payments in BTC, but now supports other assets through the Taproot Asset upgrade.
  • Fiber Network supports various assets, including CKB, BTC, RGB++ stablecoins, etc.

Transaction fees and speed:

  • BTC Lightning Network incurs higher BTC transaction fees when opening and closing channels due to operating on the BTC chain, especially when BTC transaction fees rise, significantly increasing the cost of channel operations.
  • Fiber Network, relying on CKB, has higher TPS and lower transaction fees, making the costs of opening and closing channels lower and providing a better user experience.

Cross-chain interoperability:

  • BTC Lightning Network is primarily used for payments within the BTC network and does not yet support cross-chain payments with other UTXO chains.
  • Fiber Network supports the circulation of various assets, including: native BTC assets (including inscriptions, runes, etc.), CKB, and RGB++ native assets (including RUSD, etc.).
  • Cross-chain asset off-chain payments: Leveraging RGB++ Layer, assets from all UTXO chains can enter the Lightning Network.
  • Fiber Network and BTC Lightning Network can interconnect: Achieving cross-chain payments (only Fiber Network can initiate, BTC Lightning Network can receive), allowing users to use CKB or RGB++ assets to purchase assets on the BTC Lightning Network while ensuring the atomicity of cross-chain transactions (avoiding situations where some assets succeed/fail in cross-chain transactions).

2.3.4 The Role of Fiber Network in Stablecoin Payments#

Fiber Network supports off-chain stablecoin transfers, ensuring the immediacy and low cost of payments.

Fiber Network enables users to conduct high-frequency trading off-chain by creating off-chain payment channels, reducing pressure on the main chain.

Fiber Network supports cross-chain atomic payments, allowing stablecoin payments to securely traverse multiple chains.

2.4 Stable++#

2.4.1 Introduction to Stable++#

Image5

Stable++ is a decentralized over-collateralized stablecoin protocol in the CKB ecosystem, allowing users to mint USD-pegged RUSD by collateralizing BTC or CKB.

RUSD is theoretically the first stablecoin issued directly on the Bitcoin network based on the RGB++ protocol, utilizing CKB's capabilities to provide a more localized and efficient solution.

Transaction Fees: Users are charged fees for minting RUSD by collateralizing BTC/CKB and for redeeming BTC/CKB by returning RUSD.

RUSD Staking: Users can earn governance tokens STB by staking borrowed RUSD.

Governance Token STB

  • Users can earn profits by participating in the liquidation of collateral through staking STB.
  • Users can participate in fee sharing by staking STB.

Cross-chain interoperability: RUSD can achieve transfers between UTXO chain accounts through RGB++'s isomorphic binding and Leap functionality.

Lower Minimum Collateralization Ratio (MCR): Thanks to efficient liquidation, the risk of potential losses faced by the protocol and stability providers is reduced, thereby lowering the demand for collateral value.

Decentralization: Stable++ is a fully decentralized, independently operating protocol that requires no control or permission from any entity, allowing users to interact with the system freely and securely.

2.4.2 Liquidation Mechanism - Dual Insurance#

Image6

Overview: The liquidation mechanism is a protective measure triggered when the value of collateral falls below a certain critical point (minimum collateralization ratio for borrowing RUSD), ensuring that the generated RUSD stablecoin is always sufficiently backed by collateral. The system will automatically liquidate users with insufficient collateral to maintain the overall stability of the system.

Stability Pool:

  • To address inefficiencies during widespread liquidations, Stable++ uses a stability pool to replace the auction method commonly used in most lending protocols for liquidation, eliminating the need to find liquidators in the market.
  • Automatic Liquidation: The stability pool requires LPs (users) to pre-deposit RUSD as reserves. When liquidation occurs, RUSD equivalent to the bad debt in the stability pool will be directly destroyed, while the collateral will be directly allocated to LPs.
  • By automatically liquidating through the stability pool, the ability to directly allocate over-collateralized assets replaces traditional auctions, improving the operational efficiency and stability of stablecoins during widespread liquidations.

Reallocation

  • Overview: When the stability pool does not have enough reserves to cover bad debt liquidation, the bad debt and collateral will be distributed among borrowers through a sufficiency allocation mechanism.
  • Debt Reallocation: When the liquidation pool cannot cover all bad debts, the remaining debt will be proportionally redistributed among all borrowers.
  • Collateral Distribution: While all borrowers collectively absorb the bad debt, they will also receive a proportional allocation of over-collateralized assets as a reward.
  • By having all borrowers collectively bear the bad debt, this mechanism ensures that there is no uncovered debt in the system, avoiding the accumulation of systemic risk.

2.4.3 The Role of Stable++ in Stablecoin Payments#

The Stable++ protocol generates the stablecoin RUSD, which serves as the primary stablecoin used in payments.

Stable++ improves the traditional over-collateralization method through its innovative liquidation mechanism, ensuring the stability of the RUSD price.

With the isomorphic binding and Leap capabilities of RGB++, RUSD becomes the first truly freely circulating stablecoin across any UTXO-supporting chain, further broadening the liquidity of stablecoins.

2.5 JoyID#

2.5.1 What is JoyID#

The JoyID Passkey wallet is a cryptocurrency wallet that combines Passkey key management.

In the Nervos ecosystem, JoyID is designed as a cross-chain, decentralized identity authentication and management tool, allowing users to securely store and use cryptocurrencies and other decentralized applications.

2.5.2 Main Features#

  • No passwords or mnemonic phrases required: Access the wallet through biometric recognition, enabling passwordless login.
  • Supports BTC and Fiber Network: Users can trade faster and more efficiently, helping to expand the application scenarios of CKB.
  • Multi-chain support: JoyID supports not only BTC and Nervos CKB but also ETH and a range of EVM chains.
  • Additional security through Passkey: Passkey generates the secp256k1 signatures required for blockchain transactions through secp256r1 signatures associated with hardware devices, as secp256r1 signatures are not exposed in transactions and are generated only through biometric information, adding extra security to the wallet.
  • Combination of security and usability
    • Security: Hardware wallet > Passkey wallet > Software non-custodial wallet > Custodial wallet
    • Usability: Passkey wallet > Custodial wallet > Software non-custodial wallet > Hardware wallet

2.5.3 The Role of JoyID in Stablecoin Payments#

JoyID serves as the user interface, allowing users to make stablecoin payments on the CKB network, managing their RUSD assets and payment channels.

With its excellent combination of capabilities (security, usability, multi-chain support), JoyID can further empower stablecoin payments and other transactions based on CKB.

  • Payment Initiation and Acceptance: Users can open payment channels through the JoyID wallet for stablecoin payments.
  • Stablecoin Issuance: RGB++ and Stable++ work together, with Stable++ generating RUSD through over-collateralization of BTC or CKB, then issuing it on-chain through RGB++.
  • Cross-chain Transactions and Circulation: RGB++ seamlessly connects the BTC chain (and other UTXO chains) with the CKB chain through isomorphic binding and Leap, allowing RUSD and other assets to operate cross-chain across multiple UTXO chains, expanding the asset circulation range and ensuring data synchronization.
  • Transaction Records and Settlement: The combination of Fiber Network and CKB supports rapid processing of off-chain payments, with CKB serving as the L1 chain to ensure the final settlement of transactions, safeguarding the security of all transaction states and assets.
  • Foundation for Complex Transactions: CKB's virtual machine and Cell model provide an execution environment for smart contracts, supporting complex payment conditions and custom contract logic while ensuring the decentralization of the Stable++ protocol.

References:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.