Skip to main content

Appendix

Here is a breakdown of the simple and complete KISSVM language.

Grammar

GrammarDescription
ADDRESSADDRESS ( BLOCK )
BLOCKSTATEMENT_1 STATEMENT_2 ... STATEMENT_n
STATEMENTLET VARIABLE = EXPRESSION \
EXPRESSIONRELATION
LOGICOPERATION EQ OPERATION \
OPERATIONADDSUB & ADDSUB \
ADDSUBMULDIV + MULDIV \
MULDIVPRIME * PRIME \
PRIMENOT PRIME \
BASEUNITVARIABLE \
VARIABLE[a-z]+
VALUENUMBER \
NUMBER^[0-9]+(\\.[0-9]+)?
HEX0x[0-9a-fA-F]+
STRING[UTF8_String]
BOOLEANTRUE \
FALSE0
TRUENOT FALSE
GLOBAL@BLOCK \
FUNCTIONFUNC ( EXPRESSION_1 EXPRESSION_2 .. EXPRESSION_n )
FUNCCONCAT \

Globals

GlobalDescription
@BLOCKthe current block number
@BLOCKMILLIthe current block time in milliseconds since Jan 1 1970
@CREATEDthe block this coin was created in
@COINAGEthe difference in @BLOCK and @CREATED
@INPUTInput index of a coin used in the transaction. First input coin has an index of 0.
@COINIDthe coinid
@AMOUNTthe amount
@ADDRESSthe address
@TOKENIDthe tokenid
@SCRIPTthe script of this coin
@TOTINthe total number of input coins
@TOTOUTthe total number of output coins

Functions

FunctionDescription
CONCAT ( HEX_1 HEX_2 ... HEX_n )Concatenate the HEX values.
LEN ( HEX\SCRIPT )
REV ( HEX )Reverse the data
SUBSET ( HEX NUMBER NUMBER )Return the HEX subset of the data - start - length
OVERWRITE ( HEX NUMBER HEX NUMBER NUMBER)Copy bytes from the first HEX and pos to the second HEX and pos, length the last NUMBER
GET ( NUMBER NUMBER .. NUMBER )Return the array value set with LET ( EXPRESSION EXPRESSION .. EXPRESSION )1
EXISTS ( NUMBER NUMBER .. NUMBER )Does the array value exists
ADDRESS ( STRING )Return the address of the script
REPLACE ( STRING STRING STRING )Replace in 1st string all occurrence of 2nd string with 3rd
SUBSTR ( STRING NUMBER NUMBER )Get the substring
CLEAN ( STRING )Return a CLEAN version of the script
UTF8 ( HEX )Convert the HEX value to a UTF8 string
ASCII ( HEX )Convert the HEX value to an ASCII string
BOOL ( VALUE )Convert to TRUE or FALSE value
HEX ( SCRIPT )Convert SCRIPT to HEX
NUMBER ( HEX )Convert HEX to NUMBER
STRING ( HEX )Convert a HEX value to SCRIPT
ABS ( NUMBER )Convert SCRIPT to HEX
NUMBER ( HEX )Return the absolute value of a number
CEIL ( NUMBER )Return the number rounded up
FLOOR ( NUMBER )Return the number rounded down
MIN ( NUMBER NUMBER )Return the minimum value of the 2 numbers
MAX ( NUMBER NUMBER )Return the maximum value of the 2 numbers
INC ( NUMBER )Increment a number
DEC ( NUMBER )Decrement a number
POW ( NUMBER NUMBER )Returns the power of N of a number. N must be a whole number.
SIGDIG ( NUMBER NUMBER )Set the significant digits of the number
BITSET ( HEX NUMBER BOOLEAN )Set the value of the BIT at that Position to 0 or 1
BITGET ( HEX NUMBER )Get the BOOLEAN value of the bit at the position.
BITCOUNT ( HEX )Count the number of bits set in a HEX value
PROOF ( HEX HEX HEX )Check the data, mmr proof, and root match. Same as mmrproof on Minima.
KECCAK ( HEXSTRING )
SHA2 ( HEXSTRING )
SHA3 ( HEXSTRING )
SIGNEDBY ( HEX )Returns true if the transaction is signed by this public key
MULTISIG ( NUMBER HEX1 HEX2 .. HEXn )Returns true if the transaction is signed by N of the public keys
CHECKSIG ( HEX HEX HEX)Check public key, data and signature
GETOUTADDR ( NUMBER )Return the HEX address of the specified output
GETOUTAMT ( NUMBER )Return the amount of the specified output
GETOUTTOK ( NUMBER )Return the token id of the specified output
GETOUTKEEPSTATE ( NUMBER )Is the output keeping the state
VERIFYOUT ( NUMBER HEX NUMBER HEX BOOL )Verify the output has the specified address, amount, tokenid and keepstate
GETINADDR ( NUMBER )Return the HEX address of the specified input
GETINAMT ( NUMBER )Return the amount of the specified input
GETINTOK ( NUMBER )Return the token id of the specified input
VERIFYIN ( NUMBER HEX NUMBER HEX )Verify the input has the specified address, amount and tokenid
STATE ( NUMBER )Return the state value for the given number
PREVSTATE ( NUMBER )Return the state value stored in the coin MMR data - when the coin was created.
SAMESTATE ( NUMBER NUMBER )Return TRUE if the previous state and current state are the same for the start and end positions
SUMINPUTS ( HEX )Sum the input values of this token type
SUMOUTPUTS ( HEX )Sum the output values of this token type
FUNCTION ( STRING VALUE1 VALUE2.. VALUEn )Generic Function. Run the script after replacing $1, $2.. $n in the script with the provided parameters and use the variable 'returnvalue' as the returned result.