text stringlengths 0 1.08k |
|---|
Just to give an introduction to the context of the above diagram, let us introduce terminology that will be discussed [later](https://docs.rgb.info/rgb-state-and-operations/components-of-a-contract-operation) in greater technical detail: |
* The [Assignment](https://docs.rgb.info/annexes/glossary#assignment) construct, which is pointed at Alice (in this example by the Genesis), and later used by Alice and pointed at Bob, is responsible for two things: |
* The [Seal Definition](https://docs.rgb.info/annexes/glossary#seal-definition) which points to a specific UTXO (to Alice's first, by the Genesis created by a contract issuer, and later to Bob's by Alice herself). |
* The association of the Seal Definition to specific sets of data called [Owned States](https://docs.rgb.info/annexes/glossary#owned-state) which, depending on the properties of the contract, can be chosen from several types. To give a simple context example, the amount of tokens transferred is a common kind of Owned... |
* [Global State](https://docs.rgb.info/annexes/glossary#global-state), on the other hand, reflects general and **public properties** of a contract that are not meant to be owned, such as the total issued supply for a inflatable fungible asset. |
As mentioned [earlier](https://docs.rgb.info/intro-smart-contract-states#introduction-to-states), a State Transition represents the main form within [Contract Operations](https://docs.rgb.info/annexes/glossary#contract-operation) (in addition to [Genesis](https://docs.rgb.info/annexes/glossary#genesis)). **State Transi... |
 tree: |
* A [Transition Bundle](#transition-bundle) collects all transitions that refer to a given contract. State Transition details may be selectively revealed to different recipients, while the input map structure we will describe later ensures that allocations can be spent only once. |
* The Transition Bundle is hashed to produce its [BundleId](#bundleid), which is included in a leaf of the [MPC](https://docs.rgb.info/annexes/glossary#multi-protocol-commitment-mpc) Tree at a position that is determined by its contract ID. |
* When all bundles are included in the tree, the empty leaves are filled with random data and its merkle root is computed. The MPC commitment, composed by the merkle root and parameters used in the tree construction, is finally included into a Tapret or Opret output thanks to [DBC](https://docs.rgb.info/annexes/glossar... |
* The [Anchor](https://docs.rgb.info/commitment-layer/anchors) represents the *connection point* between the Bitcoin Blockchain and the RGB client-side validation structure. |
In the following paragraphs, we will delve into all the elements and processes involved in the State Transition operation. All topics discussed from now on belong to RGB Consensus, which is encoded in the [RGB Core Library](https://docs.rgb.info/annexes/rgb-library-map#rgb-core). |
## Transition Bundle |
A transition bundle is essentially the collection of all state transitions in a given witness transaction that operate on a certain contract. **In the simplest case, such as the one shown above between Alice and Bob, a Transition Bundle consists of a single state transition**. |
However, RGB natively supports batching operations, so that one or more payers can send assets to one or more payees and multiple transition types and state types are involved (e.g. atomically sending tokens and inflation rights). In these cases, all the operations involving a certain contract would belong to the same ... |
A Transition Bundle contains: |
* `input_map`, which maps all the [Assignments](https://docs.rgb.info/annexes/glossary#assignment) being spent to the State Transition spending each of them; it contains all the information that needs to be committed onchain |
* `known_transitions`, a subset of all transitions in the bundle whose details are explicitly provided; the remaining ones are said to be *concealed* |
``` |
TransitionBundle { |
input_map: Map<Opout, OpId>, |
known_transitions: Vec<KnownTransition>, |
} |
``` |
Assignments are identified by the `Opout` structure, which contains: |
* the Identifier of the Operation that created this Assignment |
* assignment Type, distinguishing for instance token ownership from issuance Rights |
* assignment Number, the index of this assignment within the previous operation, akin to bitcoin's `vout` |
``` |
Opout { |
op: OpId, |
ty: AssignmentType, |
no: u16, |
} |
``` |
### BundleId |
From a more technical angle, the `BundleId` to be inserted in the leaf of the [MPC](https://docs.rgb.info/rgb-state-and-operations/state-transitions) is obtained from a tagged hash of the strict serialization of the `input_map` field of the bundle in the following way: |
`BundleId = SHA-256( SHA-256(bundle_tag) || SHA-256(bundle_tag) || input_map )` |
Where: |
* `bundle_tag = urn:lnp-bp:rgb:bundle#2024-02-03` |
The input map gets serialized in the following way: |
``` |
input_map = |
N Opout_1 OpId_1 Opout_N OpId_N |
|__________||_____________________________________||____________| ... |_____________________________________||____________| |
16-bit LE 32-byte hash + 16-bit LE + 16-bit LE 32-byte hash 32-byte hash + 16-bit LE + 16-bit LE 32-byte hash |
|__________||___________________________________________________| ... |___________________________________________________| |
MapSize MapElement_1 MapElement_N |
``` |
Where: |
* `N` is the total number of opouts spent by some transition in the current bundle. |
* `Opout_i` is the `i`-th spent Assignment, which contains: |
* 32-byte previous operation ID |
* 16-bit assignment type, e.g. 4000 for nia assets |
* 16-bit assignment number |
* `OpId_i` is the Operation Identifier of the State Transition which spends the `i`-th Assignment |
* `Opouts` are sorted lexicographically to obtain a deterministic `BundleId` |
**Note:** A given `OpId` may appear multiple times if a transition spends multiple assignments, but the opposite is not true. An `Opout` can only be spent by a single State Transition, which guarantees the absence of double spends if we consider that the corresponding seal is closed by the witness transaction. As a con... |
## State Generation and Active State |
State transitions, just covered in the previous sections, allow the transfer of ownership of certain state properties from one party to another. However, state transitions are only one of the [Contract Operations](https://docs.rgb.info/annexes/glossary#contract-operation) allowed in RGB. The other one, which allows to ... |
The following figure shows the three components of contract operations along with their position in the RGB contract DAG, linked to their respective anchors in the Bitcoin Blockchain. State Transitions are represented by the red blocks. |
{% @mermaid/diagram content="block-beta |
columns 7 |
block:group1:3 |
columns 3 |
space t1(\["RGB Contract"]) space |
space G("Genesis") space |
space space space |
space C0(" ") C1(" ") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.