Components of a Contract Operation
Let's now deep-dive into all the components of a contract operation, which are capable of changing the state of the contract and which are ultimately verified client-side by the legitimate recipient in a deterministic manner.
With the help of the comprehensive diagram above, it's important to point out that any contract operation is composed of some components related to the New State and some components that reference the Old State being updated.
The New state is represented by:
Assignments, which are composed by:
In addition, we also have several operation-specific fields:
ContractId
the 32-byte number that references theOpId
of the Genesis of the contract. Naturally, it's only present in State Transitions, but not in Genesis.Testnet
is a boolean variable indicating the use of Bitcoin Testnet or Mainnet. It is only present in Genesis.
OpId
ContractId
Contract State
A single Global State
One or more Owned State(s) that are controlled by some contract participants
State update methods and rules
An important feature of RGB, which affects both Global and Owned States, is the way the state is modified. Basically, States may exhibit two different behaviors:
A Mutable behavior, in which each state transition discards the previous state and assigns a new one.
An Accumulating behavior, in which each state transition adds a new state to the previous state.
In all cases where the Contract State is neither Mutated nor Accumulated, the respective components are left empty, meaning that no repetition of data takes place in a Contract Operation.
The table below provides a summary of the rules regarding the permitted modification of Global/Owned States by each Contract Operation, if allowed by contract schema:
Genesis
State Transition
Adds Global State
✓
✓
Mutates Global State
✗
✓
Adds Owned State
✓
✓
Mutates Owned State
✗
✓
As a final consideration of this section, in the following table we provide a summary of the main scope-related properties that the various kind of state data elements exhibit in the RGB protocol.
Metadata
Global state
Owned state
Scope
Defined per contract operation
Defined per contract globally
Defined per single-use-seal (Assignment)
Who can update
Not updatable
Operation creators
Controlled by right owners (parties able to close single-use-seal)
Time scope
Defined just for a single operation
State is defined after/as a result of the operation
State is defined before the operation (when the seal definition is embedded in the previous operation)
Global State
Each component of a Global State consists of a 2-field structure that includes:
The actual Data expressing the property.
The
ticker
.The full name of the token:
name
.The precision of decimal digits:
precision
.The issued supply of the token:
issuedSupply
.A text with some legal disclaimer:
terms
.
Assignments
Each Assignment consists of the following components:
The
AssignmentType
which is the identifier of the digital property that is stored in the Assignment (e.g.assetOwner
, which identifies a token allocation with its amount).The
Seal Definition
which is a sub-construct containing the reference to the UTXO.The
Owned State
which specifies how the properties associated with theAssignmentType
are modified.
Seal Definition
txptr
is a more complex object than a simple hash of a Bitcoin Transaction. In particular, it can have two distinct kinds:Txid
: a regular bitcoin transaction identifier
The
WitnessTx
value only applies to operations that have a witness transaction, which is not always the case. So we have different names for seals depending on whether it's allowed:Graph seal
, in which both kinds are supported:Txid
, which leads to what we call a "blinded transfer"WitnessTx
, that results in a so-called "witness transfer". This is useful for instance in Lighting channel updates and when the recipient doesn't have any available UTXOs.
vout
is the transaction output number within the Transaction whichtxptr
refers to. Thetxptr
field together withvout
field constitute an extension of the standard outpoint representation of Bitcoin transactions.blinding
is a random number of 8 bytes, which allows the seal data to be effectively hidden once they have been hashed, providing privacy to the recipient at least until the allocation is later spent again.
SHA-256(SHA-256(seal_tag) || SHA-256(seal_tag) || txptr || vout || blinding)
Where:
seal_tag = urn:lnp-bp:seals:secret#2024-02-03
Notes:
A
BlindSeal
in whichTxPtr
is bound to be aTxid
is calledGenesisSeal
A
BlindSeal
in whichTxPtr
can be either aTxid
or the special valueWitnessTx
is calledGraphSeal
Owned States
This second Assignment component is responsible for defining and storing the data assigned by the Seal Definition. Before proceeding with the features of Owned States, a brief digression about Conceal/Reveal
feature of this construct is necessary. Unlike the Global State, Owned States come in two forms:
Public Owned States: in which related data must always be kept and transferred in a revealed form by their owner recursively. For example, they may apply to some image files that must be bound to ownership, but are always publicly shown. This form can be described by the phrase: "someone owns, everybody knows".
Private Owned States: in which related data is kept hidden and revealed only if it is part of the history for validation purposes. For example, the number of tokens transferred in a token contract is generally kept private. This form can be summarized by the sentence: "someone owns, nobody knows".
In RGB, an Owned State can only be defined with one of the three StateTypes: Declarative
, Fungible
, Structured
:
Fungible
is the StateType that allows for the transfer of fungible units such as those in a token contract; it consists of a singleamount
field.Structured
is a State Type that can accommodate ordered and limited data collections of arbitrary content, which can be used as input for complex contract validation schemes. Its maximum storage size is limited to a maximum of 64 KiB.
The diagram below shows a summary of the three state types with their content:
In addition, a summary of the technical characteristics of each StateType is provided in the table below:
Data
None
64-bit signed/unsigned integer
Any strict data type
Type info
None
Signed/unsigned
Strict Types
Size limits
N/A
256 Byte
Up to 64 kByte
Inputs
Similar to Bitcoin Transactions, Inputs represent the "other half" of the Assignment construct. They have the basic role of referencing Assignments from a previous State Transition or Genesis. Inputs are not present in Genesis and consist of the following fields:
PrevOpId
containing the identifier of the previous Assignment operation being referenced.AssignmentType
containing the identifier of the contract property being modified by the referenced Assignment.Index
is the index number of the Assignment being referenced within the Assignment list of thePrevOpId
. TheIndex
is calculated implicitly from the lexicographic sorting of the hashes of the Concealed Seal of the referenced Assignments.
As a natural property, Genesis has no Inputs as well as all State Transitions that don't change some Owned States of any kind. For example, a State Transition that changes only the Global State has no Inputs.
Metadata
The metadata construct is a particular field that contains all the information that is not useful to be stored as part of the contract state history. It has a maximum size of 64 KiB and can be used, for example, to host temporary data from a complex contract validation procedure by the AluVm engine.
Last updated