Skip to main content

KISS VM

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

Grammar

GrammarDescription
ADDRESSADDRESS ( BLOCK )
BLOCKSTATEMENT_1 STATEMENT_2 ... STATEMENT_n
STATEMENTLET VARIABLE = EXPRESSION |
LET ( EXPRESSION_1 EXPRESSION_2 ... EXPRESSION_n ) = EXPRESSION |
IF EXPRESSION THEN BLOCK [ELSEIF EXPRESSION THEN BLOCK]* [ELSE BLOCK] ENDIF |
WHILE EXPRESSION DO BLOCK ENDWHILE |
EXEC EXPRESSION |
MAST EXPRESSION |
ASSERT EXPRESSION |
RETURN EXPRESSION
EXPRESSIONRELATION
RELATIONLOGIC AND LOGIC | LOGIC OR LOGIC |
LOGIC XOR LOGIC | LOGIC NAND LOGIC |
LOGIC NOR LOGIC | LOGIC NXOR LOGIC | LOGIC
LOGICOPERATION EQ OPERATION | OPERATION NEQ OPERATION |
OPERATION GT OPERATION | OPERATION GTE OPERATION |
OPERATION LT OPERATION | OPERATION LTE OPERATION | OPERATION
OPERATIONADDSUB & ADDSUB |
ADDSUB | ADDSUB |
ADDSUB ^ ADDSUB |
ADDSUB
ADDSUBMULDIV + MULDIV |
MULDIV - MULDIV |
MULDIV % MULDIV |
MULDIV << MULDIV |
MULDIV >> MULDIV |
MULDIV
MULDIVPRIME * PRIME |
PRIME / PRIME |
PRIME
PRIMENOT PRIME |
NEG PRIME |
~PRIME |
BASEUNIT
BASEUNITVARIABLE | VALUE | -NUMBER | GLOBAL | FUNCTION | ( EXPRESSION )
VARIABLE[a-z]+
VALUENUMBER | HEX | STRING | BOOLEAN
NUMBER^[0-9]+(\.[0-9]+)?
HEX0x[0-9a-fA-F]+
STRING[UTF8_String]
BOOLEANTRUE | FALSE
FALSE0
TRUENOT FALSE
GLOBAL@BLOCK | @BLOCKMILLI | @CREATED | @COINAGE | @INPUT |
@AMOUNT | @ADDRESS | @TOKENID | @COINID |
@SCRIPT | @TOTIN | @TOTOUT
FUNCTIONFUNC ( EXPRESSION_1 EXPRESSION_2 .. EXPRESSION_n )
FUNCCONCAT | LEN | REV | SUBSET | GET | EXISTS | OVERWRITE |
REPLACE | SUBSTR | ADDRESS | SETLEN |
BOOL | HEX | NUMBER | STRING | UTF8 | ASCII |
ABS | CEIL | FLOOR | MIN | MAX | INC | DEC | SIGDIG | POW | SQRT |
BITSET | BITGET | BITCOUNT | PROOF | SHA2 | SHA3 |
SIGNEDBY | MULTISIG | CHECKSIG |
FUNCTION | SUMINPUT | SUMOUTPUT |
GETOUTADDR | GETOUTAMT | GETOUTTOK | GETOUTKEEPSTATE | VERIFYOUT |
GETINADDR | GETINAMT | GETINTOK | GETINID | VERIFYIN |
STATE | PREVSTATE | SAMESTATE

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 )Length of the data
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 ( NUMBER NUMBER STRING )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 ( HEX | STRING )Returns the KECCAK value of the HEX value.
SHA2 ( HEX | STRING )Returns the SHA2 value of the HEX value.
SHA3 ( HEX | STRING )Returns the SHA3 value of the HEX value.
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.