What is RGB, and how do its smart contracts work?
RGB, which stands for "
Really Good for Bitcoin," is
a smart contract protocol that operates as a second-layer technology above Bitcoin (BTC) or as a third layer above the Lightning Network.
RGB boasts characteristics such as
greater scalability and confidentiality compared to Bitcoin. This means it can confirm transactions faster and does not disclose any information that would later become visible on a blockchain.
Indeed,
RGB is neither a blockchain nor a rollup; instead, it is a
Directed Acyclic Graph (DAG), sometimes colloquially referred to as a "
state machine."
The main goal of this DAG is
to offload a maximum amount of work and data from the Bitcoin blockchain. This is done for various reasons: to avoid overloading the Bitcoin network, to prevent the rapid increase in the size of its blockchain, to create a new environment conducive to the development of smart contracts, and to enhance transaction confidentiality.
Although
RGB does not require tokens to function, its smart contracts enable the creation of various assets and services, including fungible and non-fungible assets (NFTs), decentralized finance (DeFi),
Decentralized Autonomous Organizations (DAOs), decentralized identities, and much more.
Several second-layer solutions exist on Bitcoin today, but RGB has the potential to stand out from the rest:
-
Liquid (L-BTC) - a second-layer solution enabling the creation of various digital assets but is
more centralized than RGB.
-
Stacks (STX) - a separate blockchain, which is
also more centralized than RGB.
-
Taproot Assets protocol - that only allows asset creation by leveraging the Taproot update.
Client-side validation
Based on the ideas of Peter Todd, client-side validation is the concept that
transaction validation should be performed by the future owner of the assets and rights being exchanged.
Client-side validation implies that owners and smart contracts must have access to the "
stash." The "
stash" represents the history of proofs of past transactions and should be transferred to the new owner
to verify the validity of transactions.
As a result, smart contracts and transactions are validated
within the wallets themselves and
not on a network of nodes.
Wallets
create the new state and prepare data compression in a Merkle tree before anchoring the state in a Bitcoin transaction or a Lightning Network transaction; this is referred to as the "commitment."
The scalability of RGB is truly remarkable. In fact, it would be possible to gather
100,000 states from different protocols into a single commitment and thus accommodate
all the contracts of Ethereum (ETH) using
just a few on-chain commitments. Thanks to RGB, Bitcoin has the theoretical potential
to process millions of contracts per second, all while improving privacy.
As for the storage of stash, it is indeed possible to rely on a third party to keep our data for us. However, just as with a custodial wallet where one might say, "
not your keys, not your crypto", in this case, it's "
not your keys, not your stash".
Client-side validation differs from the consensus system of a blockchain because, as shown in the following illustration,
only Bob needs to verify the validity of his own properties. Unlike a blockchain where each transaction must be checked and validated by the entire network, which is more energy-intensive and slower.
The Life of a Smart Contract in RGB
Each transaction creates a new state. Thus, if Bob owns 10 RGBTC (the native BTC wrap on RGB), he will be considered the "state owner" of his 10 RGBTC states.
Now he can view the history of his tokens from their creation (the genesis) to ensure their authenticity, but no other information is disclosed to him. He cannot know how many RGBTC Alice and Jeanne held at the time of purchase or how much they bought from the previous person.
In a blockchain system, it is in everyone's interest to verify each transaction. If a fraudulent transaction is confirmed, it could impact the security of the entire network.
In a state machine, Bob only validates the transactions that interest him and does not need to know that Alice received USDT from Jeanne.
The Single Use Seals
Also based on the ideas of Peter Todd, "single-use seals" are used to link each new RGB state to a Bitcoin Unspent Transaction Output (UTXO).
These seals could be compared to the seals on a letter. The content of the letter represents the new state, and once the seal is closed, the content cannot be changed without breaking it.
If the seal is broken, it becomes unusable, and the transaction will no longer be valid.
These seals ensure that a transaction can only be spent once within the RGB system. Publishing them on the Bitcoin blockchain further strengthens this mechanism, benefiting from its protection against double spending.
While RGB could be linked to any information publishing system, it turns out that Bitcoin is the best tool for storing these transaction proofs.
The RGB Schema
The "Schema" is the set of rules governing a smart contract on RGB. Each developer can initialize a different schema, defining the characteristics they consider necessary for the proper functioning of the smart contract under construction.
The schema represents the entirety of the smart contract's rules which will be stored in the stash. If a token is issued in compliance with this schema, it will be recognized and accepted by compatible smart contracts. However, if it does not adhere to the schema's rules, it will not be processed.
This schema system allows for the improvement or modification of a smart contract's rules without having to change the code across the entire RGB network. The schema provides a structure and clear constraints to ensure compatibility and security of RGB assets.
From a technical perspective, the schema defines various aspects, including the types of data retained, the types of rights granted to participants, and how rights and properties can be transferred.
The schema is defined in the first state, meaning at the genesis of the smart contract. The individual who created the genesis will be called the "smart contract issuer" or the issuer of the smart contract.
Illustration of the Life of a Smart Contract on RGB
Thus, the life of a smart contract in RGB can be likened to the expansion of the universe. The genesis of the smart contract would correspond to the Big Bang, a crucial moment when all rules and laws are established in the schema.
Each point represents a celestial body, corresponding to the properties of the users. Each line represents the movements of celestial bodies, corresponding to properties that separate and converge. Just like the expanding universe, smart contracts are immutable, and their lives continue to expand endlessly.
AluVM:
AluVM is RGB's virtual machine, representing an essential advancement in optimally connecting RGB smart contracts to the Bitcoin network.
Developed in Rust, AluVM provides greater accessibility to developers, making it easier to create and manage smart contracts in the RGB ecosystem. This approach improves the efficiency of RGB's development.
Comparative Table of Different Virtual Machines
RGB-20: Fungible Assets
RGB-20 is the name of
the interface used as a foundation for creating smart contracts for fungible assets, such as governance tokens, cryptocurrencies comparable to currencies, stablecoins, and more.
For instance, RGBTC, the representation of BTC on RGB, is an RGB-20 token.
Please note that
a burn or mint mechanism can be added during the creation of a new token, and this mechanism must be included in the Schema.
RGB-21, Non-Fungible Assets
RGB-21 is the name of
the interface used as a foundation for creating smart contracts for non-fungible assets (NFTs). Leveraging the features of RGB,
RGB-21 offers an innovative and more efficient approach to storage, privacy, and monetization of content.
With RGB-21, there is no longer a need to rely on costly blockchain storage or use centralized data management solutions like Microsoft Azure, AWS, etc. Instead,
all data is stored by the owners themselves.
One of the key features of RGB-21 is its ability to allow creators
to sell access rights to the content one or multiple times while preserving ownership and control over it. This eliminates the need for expensive intermediaries, enables creators to maximize their profits, and allows anyone to purchase rights to a file.
RGB-22, Decentralized Digital Identities
RGB-22 is the name of
the interface used as a foundation for creating smart contracts for decentralized digital identities (
DID). The privacy features of RGB are well-suited for this use case.
This interface was conceived even before the network was finalized, becoming a clear objective for the developers.
RGB-22 could enhance the security of our personal data.
Decentralized digital identities are valuable as
they help address the issues related to the centralization of personal data on the Internet.
Currently, platforms
collect, use, and sell our data to create detailed user profiles, enabling them to target advertisements based on our personalities.
By developing decentralized digital identity standards, it becomes possible to regain control over our information while ensuring better protection of our privacy.
Carbonado
Created by the team behind the NFT platform DIBA, Carbonado is a decentralized storage system designed to replace centralized storage systems such as Microsoft Azure, AWS, etc.
The goal of this storage system is to archive consensus data in an encrypted and durable manner.
Carbonado shares similarities with the Nostr relay system, with which it is compatible, but its primary objective is to store and encrypt end-to-end the RGB data held in wallets (smart contracts, stashes, invoices, files related to RGB-21, etc). The development of Carbonado is still ongoing.
Bifrost
The Bifrost protocol plays a crucial role in implementing RGB functionalities on the Lightning Network. Bifrost is an extension of the Lightning Network that enables the transmission of client-side validation data.
Thus, Bifrost allows RGB-20 transactions to occur on the Lightning Network and paves the way for more efficient features such as decentralized exchanges (DEX), decentralized finance (DeFi) applications, etc.
While Bifrost is not directly integrated into RGB, it makes mobile RGB wallets compatible with the Lightning Network. Bifrost enables users to interact with the Lightning Network without running a full node, improving the user experience and expanding the use cases for RGB.
Independent of RGB, Bifrost was created to make the Lightning Network compatible with miniscript and the Taproot update.
Storm
Storm, which works in tandem with the Bifrost protocol, also plays a crucial role in facilitating the transmission of messages and decentralized storage on the Lightning Network.
Storm enhances decentralized data storage by utilizing special payment channels and RGB smart contracts.
Indeed, it provides solutions for compensating storage providers, protecting against data loss, and ensuring that payments are made fairly.