Application-Specific Primitives
TVM Instructions Content List
- Overview
- Stack Manipulation
- Tuple, List and Null
- Constants and Literals
- Arithmetic Operations
- Data Comparison
- Cell Manipulation
- Continuation and Control Flow
- Exception Generation and Handling
- Dictionary Manipulation
- Application-specific Primitives
- Miscellaneous
...
Opcode | Fift syntax | Stack | Description | Gas |
---|---|---|---|---|
Please enter a search query | ||||
No results found |
Application-Specific Primitives
Gas-related primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
F800 | ACCEPT | - | Sets current gas limit g_l to its maximal allowed value g_m , and resets the gas credit g_c to zero, decreasing the value of g_r by g_c in the process.In other words, the current smart contract agrees to buy some gas to finish the current transaction. This action is required to process external messages, which bring no value (hence no gas) with themselves. | 26 |
F801 | SETGASLIMIT | g - | Sets current gas limit g_l to the minimum of g and g_m , and resets the gas credit g_c to zero. If the gas consumed so far (including the present instruction) exceeds the resulting value of g_l , an (unhandled) out of gas exception is thrown before setting new gas limits. Notice that SETGASLIMIT with an argument g >= 2^63-1 is equivalent to ACCEPT . | 26 |
F80F | COMMIT | - | Commits the current state of registers c4 (“persistent data'') and c5 (“actions'') so that the current execution is considered “successful'' with the saved values even if an exception is thrown later. | 26 |
Pseudo-random number generator primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
F810 | RANDU256 | - x | Generates a new pseudo-random unsigned 256-bit Integer x . The algorithm is as follows: if r is the old value of the random seed, considered as a 32-byte array (by constructing the big-endian representation of an unsigned 256-bit integer), then its sha512(r) is computed; the first 32 bytes of this hash are stored as the new value r' of the random seed, and the remaining 32 bytes are returned as the next random value x . | 26+\|c7\|+\|c1_1\| |
F811 | RAND | y - z | Generates a new pseudo-random integer z in the range 0...y-1 (or y...-1 , if y<0 ). More precisely, an unsigned random value x is generated as in RAND256U ; then z:=floor(x*y/2^256) is computed.Equivalent to RANDU256 256 MULRSHIFT . | 26+\|c7\|+\|c1_1\| |
F814 | SETRAND | x - | Sets the random seed to unsigned 256-bit Integer x . | 26+\|c7\|+\|c1_1\| |
F815 | ADDRAND RANDOMIZE | x - | Mixes unsigned 256-bit Integer x into the random seed r by setting the random seed to Sha of the concatenation of two 32-byte strings: the first with the big-endian representation of the old seed r , and the second with the big-endian representation of x . | 26 |
Configuration primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
F82i | [i] GETPARAM | - x | Returns the i -th parameter from the Tuple provided at c7 for 0 <= i <= 15 . Equivalent to c7 PUSHCTR FIRST [i] INDEX .If one of these internal operations fails, throws an appropriate type checking or range checking exception. | 26 |
F823 | NOW | - x | Returns the current Unix time as an Integer. If it is impossible to recover the requested value starting from c7 , throws a type checking or range checking exception as appropriate.Equivalent to 3 GETPARAM . | 26 |
F824 | BLOCKLT | - x | Returns the starting logical time of the current block. Equivalent to 4 GETPARAM . | 26 |
F825 | LTIME | - x | Returns the logical time of the current transaction. Equivalent to 5 GETPARAM . | 26 |
F826 | RANDSEED | - x | Returns the current random seed as an unsigned 256-bit Integer. Equivalent to 6 GETPARAM . | 26 |
F827 | BALANCE | - t | Returns the remaining balance of the smart contract as a Tuple consisting of an Integer (the remaining Gram balance in nanograms) and a Maybe Cell (a dictionary with 32-bit keys representing the balance of “extra currencies''). Equivalent to 7 GETPARAM .Note that RAW primitives such as SENDRAWMSG do not update this field. | 26 |
F828 | MYADDR | - s | Returns the internal address of the current smart contract as a Slice with a MsgAddressInt . If necessary, it can be parsed further using primitives such as PARSEMSGADDR or REWRITESTDADDR .Equivalent to 8 GETPARAM . | 26 |
F829 | CONFIGROOT | - D | Returns the Maybe Cell D with the current global configuration dictionary. Equivalent to 9 GETPARAM . | 26 |
F830 | CONFIGDICT | - D 32 | Returns the global configuration dictionary along with its key length (32). Equivalent to CONFIGROOT 32 PUSHINT . | 26 |
F832 | CONFIGPARAM | i - c -1 or 0 | Returns the value of the global configuration parameter with integer index i as a Cell c , and a flag to indicate success.Equivalent to CONFIGDICT DICTIGETREF . | |
F833 | CONFIGOPTPARAM | i - c^? | Returns the value of the global configuration parameter with integer index i as a Maybe Cell c^? .Equivalent to CONFIGDICT DICTIGETOPTREF . |
Global variable primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
F840 | GETGLOBVAR | k - x | Returns the k -th global variable for 0 <= k < 255 .Equivalent to c7 PUSHCTR SWAP INDEXVARQ . | 26 |
F85_k | [k] GETGLOB | - x | Returns the k -th global variable for 1 <= k <= 31 .Equivalent to c7 PUSHCTR [k] INDEXQ . | 26 |
F860 | SETGLOBVAR | x k - | Assigns x to the k -th global variable for 0 <= k < 255 .Equivalent to c7 PUSHCTR ROTREV SETINDEXVARQ c7 POPCTR . | 26+\|c7’\| |
F87_k | [k] SETGLOB | x - | Assigns x to the k -th global variable for 1 <= k <= 31 .Equivalent to c7 PUSHCTR SWAP k SETINDEXQ c7 POPCTR . | 26+\|c7’\| |
Hashing and cryptography primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
F900 | HASHCU | c - x | Computes the representation hash of a Cell c and returns it as a 256-bit unsigned integer x . Useful for signing and checking signatures of arbitrary entities represented by a tree of cells. | 26 |
F901 | HASHSU | s - x | Computes the hash of a Slice s and returns it as a 256-bit unsigned integer x . The result is the same as if an ordinary cell containing only data and references from s had been created and its hash computed by HASHCU . | 526 |
F902 | SHA256U | s - x | Computes Sha of the data bits of Slice s . If the bit length of s is not divisible by eight, throws a cell underflow exception. The hash value is returned as a 256-bit unsigned integer x . | 26 |
F910 | CHKSIGNU | h s k - ? | Checks the Ed25519-signature s of a hash h (a 256-bit unsigned integer, usually computed as the hash of some data) using public key k (also represented by a 256-bit unsigned integer).The signature s must be a Slice containing at least 512 data bits; only the first 512 bits are used. The result is -1 if the signature is valid, 0 otherwise.Notice that CHKSIGNU is equivalent to ROT NEWC 256 STU ENDC ROTREV CHKSIGNS , i.e., to CHKSIGNS with the first argument d set to 256-bit Slice containing h . Therefore, if h is computed as the hash of some data, these data are hashed twice, the second hashing occurring inside CHKSIGNS . | 26 |
F911 | CHKSIGNS | d s k - ? | Checks whether s is a valid Ed25519-signature of the data portion of Slice d using public key k , similarly to CHKSIGNU . If the bit length of Slice d is not divisible by eight, throws a cell underflow exception. The verification of Ed25519 signatures is the standard one, with Sha used to reduce d to the 256-bit number that is actually signed. | 26 |
Miscellaneous primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
F940 | CDATASIZEQ | c n - x y z -1 or 0 | Recursively computes the count of distinct cells x , data bits y , and cell references z in the dag rooted at Cell c , effectively returning the total storage used by this dag taking into account the identification of equal cells. The values of x , y , and z are computed by a depth-first traversal of this dag, with a hash table of visited cell hashes used to prevent visits of already-visited cells. The total count of visited cells x cannot exceed non-negative Integer n ; otherwise the computation is aborted before visiting the (n+1) -st cell and a zero is returned to indicate failure. If c is Null, returns x=y=z=0 . | |
F941 | CDATASIZE | c n - x y z | A non-quiet version of CDATASIZEQ that throws a cell overflow exception (8) on failure. | |
F942 | SDATASIZEQ | s n - x y z -1 or 0 | Similar to CDATASIZEQ , but accepting a Slice s instead of a Cell. The returned value of x does not take into account the cell that contains the slice s itself; however, the data bits and the cell references of s are accounted for in y and z . | |
F943 | SDATASIZE | s n - x y z | A non-quiet version of SDATASIZEQ that throws a cell overflow exception (8) on failure. |
Currency manipulation primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
FA00 | LDGRAMS LDVARUINT16 | s - x s' | Loads (deserializes) a Gram or VarUInteger 16 amount from Slice s , and returns the amount as Integer x along with the remainder s' of s . The expected serialization of x consists of a 4-bit unsigned big-endian integer l , followed by an 8l -bit unsigned big-endian representation of x .The net effect is approximately equivalent to 4 LDU SWAP 3 LSHIFT# LDUX . | 26 |
FA01 | LDVARINT16 | s - x s' | Similar to LDVARUINT16 , but loads a signed Integer x .Approximately equivalent to 4 LDU SWAP 3 LSHIFT# LDIX . | 26 |
FA02 | STGRAMS STVARUINT16 | b x - b' | Stores (serializes) an Integer x in the range 0...2^120-1 into Builder b , and returns the resulting Builder b' . The serialization of x consists of a 4-bit unsigned big-endian integer l , which is the smallest integer l>=0 , such that x<2^(8l) , followed by an 8l -bit unsigned big-endian representation of x . If x does not belong to the supported range, a range check exception is thrown. | 26 |
FA03 | STVARINT16 | b x - b' | Similar to STVARUINT16 , but serializes a signed Integer x in the range -2^119...2^119-1 . | 26 |
Message and address manipulation primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
FA40 | LDMSGADDR | s - s' s'' | Loads from Slice s the only prefix that is a valid MsgAddress , and returns both this prefix s' and the remainder s'' of s as slices. | 26 |
FA41 | LDMSGADDRQ | s - s' s'' -1 or s 0 | A quiet version of LDMSGADDR : on success, pushes an extra -1 ; on failure, pushes the original s and a zero. | 26 |
FA42 | PARSEMSGADDR | s - t | Decomposes Slice s containing a valid MsgAddress into a Tuple t with separate fields of this MsgAddress . If s is not a valid MsgAddress , a cell deserialization exception is thrown. | 26 |
FA43 | PARSEMSGADDRQ | s - t -1 or 0 | A quiet version of PARSEMSGADDR : returns a zero on error instead of throwing an exception. | 26 |
FA44 | REWRITESTDADDR | s - x y | Parses Slice s containing a valid MsgAddressInt (usually a msg_addr_std ), applies rewriting from the anycast (if present) to the same-length prefix of the address, and returns both the workchain x and the 256-bit address y as integers. If the address is not 256-bit, or if s is not a valid serialization of MsgAddressInt , throws a cell deserialization exception. | 26 |
FA45 | REWRITESTDADDRQ | s - x y -1 or 0 | A quiet version of primitive REWRITESTDADDR . | 26 |
FA46 | REWRITEVARADDR | s - x s' | A variant of REWRITESTDADDR that returns the (rewritten) address as a Slice s , even if it is not exactly 256 bit long (represented by a msg_addr_var ). | 26 |
FA47 | REWRITEVARADDRQ | s - x s' -1 or 0 | A quiet version of primitive REWRITEVARADDR . | 26 |
Outbound message and output action primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
FB00 | SENDRAWMSG | c x - | Sends a raw message contained in Cell c , which should contain a correctly serialized object Message X , with the only exception that the source address is allowed to have dummy value addr_none (to be automatically replaced with the current smart-contract address), and ihr_fee , fwd_fee , created_lt and created_at fields can have arbitrary values (to be rewritten with correct values during the action phase of the current transaction). Integer parameter x contains the flags. Currently x=0 is used for ordinary messages; x=128 is used for messages that are to carry all the remaining balance of the current smart contract (instead of the value originally indicated in the message); x=64 is used for messages that carry all the remaining value of the inbound message in addition to the value initially indicated in the new message (if bit 0 is not set, the gas fees are deducted from this amount); x'=x+1 means that the sender wants to pay transfer fees separately; x'=x+2 means that any errors arising while processing this message during the action phase should be ignored. Finally, x'=x+32 means that the current account must be destroyed if its resulting balance is zero. This flag is usually employed together with +128 . | 526 |
FB02 | RAWRESERVE | x y - | Creates an output action which would reserve exactly x nanograms (if y=0 ), at most x nanograms (if y=2 ), or all but x nanograms (if y=1 or y=3 ), from the remaining balance of the account. It is roughly equivalent to creating an outbound message carrying x nanograms (or b-x nanograms, where b is the remaining balance) to oneself, so that the subsequent output actions would not be able to spend more money than the remainder. Bit +2 in y means that the external action does not fail if the specified amount cannot be reserved; instead, all remaining balance is reserved. Bit +8 in y means x:=-x before performing any further actions. Bit +4 in y means that x is increased by the original balance of the current account (before the compute phase), including all extra currencies, before performing any other checks and actions. Currently x must be a non-negative integer, and y must be in the range 0...15 . | 526 |
FB03 | RAWRESERVEX | x D y - | Similar to RAWRESERVE , but also accepts a dictionary D (represented by a Cell or Null) with extra currencies. In this way currencies other than Grams can be reserved. | 526 |
FB04 | SETCODE | c - | Creates an output action that would change this smart contract code to that given by Cell c . Notice that this change will take effect only after the successful termination of the current run of the smart contract. | 526 |
FB06 | SETLIBCODE | c x - | Creates an output action that would modify the collection of this smart contract libraries by adding or removing library with code given in Cell c . If x=0 , the library is actually removed if it was previously present in the collection (if not, this action does nothing). If x=1 , the library is added as a private library, and if x=2 , the library is added as a public library (and becomes available to all smart contracts if the current smart contract resides in the masterchain); if the library was present in the collection before, its public/private status is changed according to x . Also, 16 can be added to x to enable bounce transaction on failure. Values of x other than 0...2 (+16 possible) are invalid. | 526 |
FB07 | CHANGELIB | h x - | Creates an output action similarly to SETLIBCODE , but instead of the library code accepts its hash as an unsigned 256-bit integer h . If x!=0 and the library with hash h is absent from the library collection of this smart contract, this output action will fail. | 526 |
TVM Instructions Content List
- Overview
- Stack Manipulation
- Tuple, List and Null
- Constants and Literals
- Arithmetic Operations
- Data Comparison
- Cell Manipulation
- Continuation and Control Flow
- Exception Generation and Handling
- Dictionary Manipulation
- Application-specific Primitives
- Miscellaneous
...