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 components of the New state are:
The Assignments in which are defined:
The Old State is referenced through:
In addition, we also have several operation-specific fields:
ContractId
the 32-byte number that references the processedOpId
of the Genesis of the contract. Naturally, it's present in State Transitions and Extensions, 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 can belong to two different categories:
Private States
Public States
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:
Genesis
State Extension
State Transition
Adds Global State
+
*
+
Mutates Global State
n/a
*
+
Adds Owned State
+
*
+
Mutates Owned State
n/a
No
+
Adds Valencies
+
+
+
+ = if allowed by Contract Schema * = if Confirmed by a State Transition
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 maximum supply of the token:
issuedSupply
.The date of issuance:
created
.A text with some Legal disclaimer:
data
.
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. theassetOwner
declaration used to declare the transfer function in token transfers).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.
Revealed / Concealed form
Seal Definition
txptr
is a more complex object than a simple hash of a Bitcoin Transaction. In particular, it can have two distinct kinds:Graph seal
which can have, itself, two separate forms:A simpler case where, as in in
Genesis seal
, thetxid
points to the UTXO chosen as a seal.A
WitnessTx
form which should be interpreted as a "self-referenced" definition. The use of this construct means that the transaction used as the seal definition coincides with the witness transaction that includes the present Assignment. Since the finaltxid
of the transaction depends on all the state transition data, includingtxptr
, it would be impossible to compute it because of the implied circular reference. In practice theWitnessTx
is a null field that has become necessary to handle several situations where no external UTXO is available: a notable example is the generation and update of Lightning Network's commitment transactions or when the recipient doesn't have any available UTXO.
vout
is the transaction output number of the Transaction Id entered intxptr
, and it is only present iftxptr
is aGraph seal
. Thetxptr
field together withvout
field constitute 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, improving resistance to brute-force attacks.
SHA-256(SHA-256(seal_tag) || SHA-256(seal_tag) || txptr || vout || blinding || method)
Where:
seal_tag = urn:lnp-bp:seals:secret#2024-02-03
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 four StateTypes: Declarative
, Fungible
, Structured
, Attachments
, each of which has its concealed and Revealed form:
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 Revealed form is simply the blob of data serialized into bytes, while the concealed form is the SHA-256 tagged hash of that data blob:SHA-256(SHA-256(tag_data) || SHA-256(tag_data) || blob)
, wheretag_data = urn:lnp-bp:rgb:state-data#2024-02-12
.Attachments
type is used to attach an arbitrary file with a defined purpose, such as a media file, audio file, text, binary, etc. The actual file is kept separated by the Owned State construct itself, as, in revealed form, the Attachment structure contains three fields: the SHA-256file_hash
, the MIMEmedia type
and asalt
factor that provides additional privacy. In concealed form, this StateType is the SHA-256 tagged hash of the three fields just described:SHA-256(SHA-256(tag_attachment) || SHA-256(tag_attachment) || file_hash || media_type || salt)
, wheretag_attachment = urn:rgb:state-attach#2024-02-12
.
The diagram below shows a summary of the four state types and their Concealed and Revealed forms:
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
Any file
Type info
None
Signed/unsigned
Strict Types
MIME type
Confidentiality
Not Required
Pedersen commitment
Hashing with blinding
Hashed file id
Size limits
N/A
256 Byte
Up to 64 kByte
Up to ~500 GByte
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 State Extension Operation 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.
Valencies
Redeems
Redeems are similar to State Transition's Inputs for Valencies. They are included only in State Extensions and are responsible for "activating" the digital right embedded in the Valency itself. An example of Redeem might be the execution of a coinswap or a distributed issuance. Redeems consist of two fields:
The 32-byte
PrevOpId
field that refers to the hash of the Operation in which the Valency to be redeemed is defined.The 16-bit
ValencyType
field that is retrieved from the previous operation in which the Valency is defined. Each ValencyType can be redeemed only once within the same State Extension.
Last updated