text
stringlengths
0
1.08k
* The left and right nodes of the upper right branch (in the same example they are: `tHAB` and `tHC`) if the `Tapret` commitment is on the left side of the tree.
* The [nonce](https://docs.rgb.info/deterministic-bitcoin-commitments-dbc/tapret#nonce-optimization), if used, to optimize the Partner node part of the proof.
In the next section, we will introduce concepts purely concerning the off-chain part of RGB, i.e. contracts, giving an abstract view of the partially replicated finite state machine that gives RGB a much greater expressiveness than can be achieved through Bitcoin Script without sacrificing confidentiality.
***
# Introduction to Smart Contracts and their States
Before addressing the technical implementation of **RGB states** and the related data structure, it is important to remember that the ordered sequence of [single-use seals](https://docs.rgb.info/annexes/glossary#single-use-seal) is intended to provide the ability to properly implement the various [Contract Operations](...
\
After a brief introduction to [smart contracts](https://docs.rgb.info/annexes/glossary#contract) and [state](https://docs.rgb.info/annexes/glossary#contract-state) concepts, we will devote our attention to the mechanism behind **Contract Operations** from the the Client-side perspective and the related bridging *points...
## Smart Contracts and Digital Bearer Rights
Since RGB allows for the implementation of **smart contracts** in Bitcoin, it is a good time to define what a smart contract actually is.
> A **smart contract** is an agreement which is automatically and computationally enforced between the parties.
This means that the enforcement of the terms agreed upon between the parties **does not require human intervention** and that such enforcement is carried out by mathematical and computerized means.
Furthermore, a question arises. To achieve the highest degree of automation, decentralization, and privacy, is it possible to forfeit the use of a centralized registry that stores ownership and contract information? The affirmative answer lies back at the origins.
![RGB enables digital version of bearer instruments.](https://160813645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaUAGORrT1fl6qzaZSTKt%2Fuploads%2Fgit-blob-c377da02745ea474cffa1c4be9a908d38c1935aa%2Forenoque-contract.png?alt=media)
Not long times ago, contracts, such as securities, were **bearer instruments**. Indeed, the widespread use of asset registers that imply a custodial relationship with some institution on behalf of the client is a fairly recent development in economic history. **The bearer nature of contracts is, in fact, a centuries-ol...
## Introduction to States
A wider range of smart contract programmability issues were considered in the design of RGB, in particular:
1. **A contract can be associated with a digital asset or a token, but it's not limited to it**. A broader range of applications and extensions of the *smart contract* concept can be implemented in RGB.
2. Unlike the approach of other public blockchains to smart contracts, in **RGB there is a clear separation between the different** [parties](https://docs.rgb.info/annexes/glossary#contract-participant) **related to a contract and their rights**: e.g. the creator/issuer of the contract and the different kinds of users ...
* the ability to *observe* certain properties or operations performed by other parties on the contract;
* the ability to *execute a set of operations* permitted by the contract.
**No other counterparty can interact** with the operations performed on the contract unless it is authorized by the rightful parties. Within RGB this feature means that there is always an [owner](https://docs.rgb.info/annexes/glossary#ownership) that has the right to perform certain operations on the contract, which ar...
These properties combined allow for two of the most important properties at the heart of the RGB value proposition, which are: **scalability** and **censorship resistance** at unprecedented levels.
In order to achieve these goals, an RGB contract is composed of two main components:
* **State**
* **Business Logic (Behavior)**
The [Business Logic](https://docs.rgb.info/annexes/glossary#business-logic) of the contract represents the rules that allow the entitled parties to change the state of the contract. We will find out later that the **Business Logic** is embedded in a particular structure of the contract called the [Schema](https://docs....
![In order to evolve, smart contract states must fallow a business logic.](https://160813645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaUAGORrT1fl6qzaZSTKt%2Fuploads%2Fgit-blob-a55f3330118cef820f7ac38ce9670f6ba28220ac%2Fstate-business-logic.png?alt=media)
Without going into the specific details of RGB implementation, which will be covered [later](https://docs.rgb.info/rgb-state-and-operations/state-transitions), an initial and fundamental definition of [State](https://docs.rgb.info/annexes/glossary#contract-state) is required. Simply put:
> A **State** can be defined as a unique configuration of information or data that represents the conditions of a contract at a specific point in time.
Therefore, a [Contract Operation](https://docs.rgb.info/annexes/glossary#contract-operation), in general terms, represents any **first creation/update of data** from an **old state** to a **new state** following the **rules inscribed into the contract** constituting its **Business Logic**.
<figure><img src="https://160813645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaUAGORrT1fl6qzaZSTKt%2Fuploads%2Fgit-blob-31f433b11521c654b5171df3906e1dc5c8030326%2Fold2new_state.png?alt=media" alt=""><figcaption><p><strong>State Transitions (among Contract Operations) apply business logic to an...
The chain of Contract Operations in RGB is the ordered path that evolves the contract data from the **first contract definition**, called [Genesis](https://docs.rgb.info/annexes/glossary#genesis), to the Terminal State that represents the most up-to-date state at the end of the [DAG](https://docs.rgb.info/annexes/gloss...
The ordering relationship within the DAG is maintained by operations committing to their inputs and guaranteed by their anchors to the Bitcoin Blockchain which, in turn, provides timestamping capabilities. It's worth noting that a given chain of RGB transitions does necessarily correspond to a chain of Bitcoin transact...
***
# Contract Operations
## State Transitions and their mechanics
The approach followed in this paragraph is the same as that developed in the [TxO2 Client-side Validation chapter](https://docs.rgb.info/commitment-layer/commitment-schemes#txo2-client-side-validation) using our beloved cryptographic characters Alice and Bob.
This time the explanation **contains an important difference**: Bob is not simply validating the client-side validated data that Alice shows him. He is actually asking Alice to add some additional data that **will give Bob some degree of ownership** over the contract expressed as a hidden reference to one of his Bitcoi...
1. Alice has a [stash](https://docs.rgb.info/annexes/glossary#stash) of client-side validated data, which references a Bitcoin UTXO owned by her. This means that in her client-side validated data there is a [seal definition](https://docs.rgb.info/annexes/glossary#seal-definition) that points to one of her UTXOs.
<figure><img src="https://160813645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaUAGORrT1fl6qzaZSTKt%2Fuploads%2Fgit-blob-b591415b6fd30546076fe690d04b41082974efe4%2Fstab1.png?alt=media" alt=""><figcaption><p>At the beginning of the State Transition, Alice possesses a certain stash and a UTXO. Th...
2. Bob, in turn, also has unspent UTXOs. These UTXOs are completely unrelated to Alice's, which means that there is no direct spending event that creates a link between them. **If Bob doesn't possess any UTXO it is also possible to spend towards him the witness transaction** output containing the commitment to the clie...
<figure><img src="https://160813645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaUAGORrT1fl6qzaZSTKt%2Fuploads%2Fgit-blob-760a0592d8d348007d7fc221f57db2071f9f7d57%2Fstab2b.png?alt=media" alt=""><figcaption><p><strong>Bob also owns some UTXOs. Moreover, they are unrelated to Alice's. This UTXO is...
3. Bob, through some informational data, encoded in an [invoice](https://docs.rgb.info/annexes/glossary#invoice), instructs Alice to create a **New state** that follows the rules of the contract and which embeds a **new seal definition** pointing to one of his UTXOs in a concealed form (more on that [later](https://doc...
<figure><img src="https://160813645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaUAGORrT1fl6qzaZSTKt%2Fuploads%2Fgit-blob-3fd278a116371e785bea5898825b91506460e359%2Fstab3.png?alt=media" alt=""><figcaption><p><strong>Bob shares with Alice the necessary data to build the State Transition that assi...
4. After that, Alice, using some [PSBT](https://docs.rgb.info/annexes/glossary#partially-signed-bitcoin-transaction-psbt) wallet tool, prepares a transaction that spends the UTXO that was indicated by the previous seal definition (the very same one that granted her ownership of some elements of the contracts). In this ...
5. Before transmitting the transaction thus prepared, Alice passes to Bob a data packet called [Consignment](https://docs.rgb.info/rgb-state-and-operations/state-transitions) which contains the organized stash of client-side data already in possession of Alice in addition to the new state. Bob, at this point, using RGB...
* **Validates every RGB state transition** in the Consignment, including the one creating some New State assigned to his own UTXO.
* **Verifies** that every RGB state transition **is committed to in a valid** [**witness transaction**](https://docs.rgb.info/annexes/glossary#witness-transaction), ensuring **legitimacy** and **uniqueness** of the whole history from Genesis to the new state.
6. After checking the correctness of the Consignment, Bob may optionally give Alice a "go-ahead" signal (e.g., by GPG signing the [consignment](https://docs.rgb.info/annexes/glossary#consignment)). Alice, even without Bob's clearance, can now broadcast this last witness transaction, containing the New State. Once confi...
For the detailed process of a contract transfer with the RGB stack, see the [related section](https://docs.rgb.info/annexes/contract-transfers).
<figure><img src="https://160813645-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaUAGORrT1fl6qzaZSTKt%2Fuploads%2Fgit-blob-7ecafdf1c618be20155d4ef6e5eac0c2cc53ae2d%2Fstab4.png?alt=media" alt=""><figcaption><p>T<strong>he new state points to Bob's UTXO by assigning him the digital property once in...
It's useful to see the full details of a DAG of two RGB contract operations - ([Genesis](https://docs.rgb.info/annexes/glossary#genesis) + a [State Transition](https://docs.rgb.info/annexes/glossary#state-transition)) - both from the RGB client-side components, which will be covered in the next few paragraphs, and from...
![A representation of RGB Layer (red) and Bitcoin Commitment Layer (orange) and their respective connections during contract operations. The diagram shows the combination of two contract operations: a Genesis, constructing a Seal Definition, and a State Transition which closes the seal previously defined in the Genesis...