Testnet launching soon!Join the Community

Reference

Async VM Instruction Set Reference

The Async VM is Firechain's virtual machine and execution engine. It is a stack-based VM that executes smart contract code. The Async VM natively supports asynchronous execution, which allows Firechain to execute smart contracts in parallel. This page provides a reference for the instructions available in the Async VM. Many of the instructions supported by the Async VM are similar or identical to those of the Ethereum Virtual Machine (EVM). However, there are some major differences that are important to understand.

For example, the Async VM handles CALLs asynchronously. This means that a CALL instruction will not block the execution of the current smart contract. Instead, it will return a message ID immediately and the execution of the current smart contract will continue. The CALL might be executed in parallel with the current smart contract, at a later point, or not at all, and it's therefore not guaranteed when or if it will return or have any observable effects. This is a major difference between the Async VM and the EVM. If your contract depends on the result of a CALL, you should use the CALL instruction in combination with the WAIT instruction. The WAIT instruction will block the execution of the current smart contract until the CALL returns or the deadline passes.

Instruction Set

The following table lists the instructions supported by the Async VM. The table is organized by instruction category. Each instruction is listed with its opcode, name, and description.

Arithmetic

The following instructions perform arithmetic operations on the stack.

OpcodeNameDescription
0x01ADDAdd two operands and return the sum.
0x02MULMultiply two operands and return the product.
0x03SUBSubtract two operands and return the difference.
0x04DIVPerform integer division on two operands and return the quotient.
0x05SDIVSame as DIV, but for signed integers.
0x06MODPerform integer modulus on two operands and return the remainder.
0x07SMODSame as MOD, but for signed integers.
0x08ADDMODAdd two operands and return the sum modulo a third operand.
0x09MULMODMultiply two operands and return the product modulo a third operand.
0x0aEXPRaise a base to an exponent and return the result.
0x0bSIGNEXTENDExtend the length of a signed integer.

Comparison and Bitwise Logic

The following instructions perform comparison and bitwise logic operations on the stack.

OpcodeNameDescription
0x10LTReturn 1 if the first operand is less than the second operand, otherwise return 0.
0x11GTReturn 1 if the first operand is greater than the second operand, otherwise return 0.
0x12SLTSame as LT but for signed operands.
0x13SGTSame as GT but for signed operands.
0x14EQReturn 1 if the operands are equal, otherwise return 0.
0x15ISZEROReturn 1 if the operand is zero, otherwise return 0.
0x16ANDBitwise AND two operands and return the result.
0x17ORBitwise OR two operands and return the result.
0x18XORBitwise XOR two operands and return the result.
0x19NOTBitwise NOT the operand and return the result.
0x1aBYTEReturn the nth byte of the operand.
0x1bSHLShift the operand left by the number of bits specified by the second operand.
0x1cSHRShift the operand right by the number of bits specified by the second operand.
0x1dSARArithmetic right shift. The sign bit is copied.

Hashing and Cryptography

The following instructions perform synchronous hashing and cryptography operations on the stack. Note that there are many other cryptographic operations supported through the use of precompiled contracts which are not listed here, including functionality related to zero-knowledge proofs and elliptic curve cryptography.

OpcodeNameDescription
0x20SHA3Compute the SHA3-256 hash of the operand and return the result.
0x21SHA256Compute the SHA256 hash of the operand and return the result.
0x22BLAKE2BCompute the BLAKE2B hash of the operand and return the result.
0x23RIPEMD160Compute the RIPEMD160 hash of the operand and return the result.
0x24KECCAK256Compute the KECCAK256 hash of the operand and return the result.

Environment

The following instructions provide information about the environment in which the smart contract is executing.

OpcodeNameDescription
0x30ADDRESSReturn the address of the current account context.
0x31BALANCEReturn the balance of an account. Accepts an address and token ID as operands.
0x32ORIGINReturn the address of the current message's sender or event source.
0x33CALLERSame as ORIGIN but returns the current account's address in an event listener.
0x34CALLVALUEReturn the token value of the current message. Accepts a token ID as an operand.
0x35CALLDATALOADReturn the data from the current message's body. Accepts an offset and length as operands.
0x36CALLDATASIZEReturn the size of the current message's body.
0x37CALLDATACOPYCopy the data from the current message's body to memory. Accepts an offset and length as operands.
0x38CODESIZEReturn the size of the current contract's code.
0x39CODECOPYCopy the current contract's code to memory. Accepts an offset and length as operands.
0x3aHEATReturn the amount of heat generated by the current message.
0x3bRANDReturn a random number. Always returns a fresh random number.
0x3cRRANDReturn a random number. Always returns the same number within the same execution context.
0x3dRETURNDATASIZEReturn the size of an external call's return data, or 0 if not available. Accepts a message ID as an operand.
0x3eRETURNDATACOPYCopy an external call's return data to memory. Accepts a message ID, data offset and length as operands.
0x40MSGHASHReturn the ID of the current message.
0x41COINBASEReturn the address of the current validator.
0x42TIMESTAMPReturn the current execution's timestamp. Will change if execution is suspended.
0x43HEIGHTReturn the current account's height, including the current message.
0x44LCVCOUNTReturn the number of validators in the local consensus group.
0x45GCVCOUNTReturn the number of validators in the global consensus group.
0x46QUEUETIMEReturn the timestamp when the current message was added to the queue.
0x47COMMITTIMEReturn the timestamp when the current message was committed by the LCG.
0x48CONFTIMEReturn the timestamp when the current message was first globally confirmed. Returns 0 if not yet confirmed.
0x49MSGTIMEReturn the timestamp from the current message's header.
0x4aCHAINIDReturn the chain ID of the current chain.
0x4bCONFDEPTHReturn the number of global confirmations. Returns 0 if not yet confirmed.

Stack and Memory

The following instructions manipulate the stack and memory.

OpcodeNameDescription
0x50POPRemove the top item from the stack.
0x51MLOADLoad a word from memory. Accepts an offset as an operand.
0x52MSTOREStore a word to memory. Accepts an offset as an operand.
0x53MSTORE8Store a byte to memory. Accepts an offset as an operand.
0x54SLOADLoad a word from storage. Accepts a key as an operand.
0x55SSTOREStore a word to storage. Accepts a key and a value as operands.
0x56JUMPDESTMark a valid jump destination.
0x57JUMPJump to a label. Accepts a label as an operand.
0x58JUMPIJump to a label if the top item on the stack is not zero. Accepts a label as an operand.
0x59PCReturn the current program counter.
0x5aMSIZEReturn the current size of memory.

PUSH (Push a value onto the stack)

OpcodeNameDescription
0x60PUSH1Push a 1-byte value onto the stack.
0x61PUSH2Push a 2-byte value onto the stack.
0x62PUSH3Push a 3-byte value onto the stack.
.........
0x7dPUSH30Push a 30-byte value onto the stack.
0x7ePUSH31Push a 31-byte value onto the stack.
0x7fPUSH32Push a 32-byte value onto the stack.

DUP (Duplicate an item on the stack)

OpcodeNameDescription
0x80DUP1Duplicate the top item on the stack.
0x81DUP2Duplicate the 2nd item on the stack.
0x82DUP3Duplicate the 3rd item on the stack.
.........
0x8dDUP14Duplicate the 14th item on the stack.
0x8eDUP15Duplicate the 15th item on the stack.
0x8fDUP16Duplicate the 16th item on the stack.

Swap (Swap two items on the stack)

OpcodeNameDescription
0x90SWAP1Swap the top two items on the stack.
0x91SWAP2Swap the 1st and 3rd items on the stack.
0x92SWAP3Swap the 1st and 4th items on the stack.
.........
0x9dSWAP14Swap the 1st and 15th items on the stack.
0x9eSWAP15Swap the 1st and 16th items on the stack.
0x9fSWAP16Swap the 1st and 17th items on the stack.

Logging

The following instructions are used to log data. Logs are stored in the current message's receipt and can be retrieved by the sender.

OpcodeNameDescription
0xa0LOG0Log an event with no topics. Accepts a memory offset and length as operands.
0xa1LOG1Log an event with one topic. Accepts a memory offset, length and topic as operands.
0xa2LOG2Log an event with two topics. Accepts a memory offset, length and two topics as operands.
0xa3LOG3Log an event with three topics. Accepts a memory offset, length and three topics as operands.
0xa4LOG4Log an event with four topics. Accepts a memory offset, length and four topics as operands.

System operations

The following instructions are used to interact with the system.

OpcodeNameDescription
0xf0CALLCreate an async request to a remote contract. Accepts a target account, token id, token value, and message data as operands. Returns a message ID.
0xf1WAITWait for the result of a request. Accepts a message ID and deadline as operands.
0xf2RETURNReturn from the current function. Accepts a value, length and offset as operands.
0xf3REVERTRevert the current message. Accepts a value, length and offset as operands.
0xf4FREEZEFreeze the current account. Suspends job execution, disables outbound messages, and freezes storage.
0xf5UNFREEZEUnfreeze the current account. Resumes scheduled job execution, enables outbound messaging, and restores storage.

Notes

  • The CALL opcode is used to create a new message to a remote contract. The message is not executed synchronously, but is added to the message queue of the target account. The message ID is returned as the result of the CALL opcode. The message ID can be used to query the status of the message, and to retrieve the return data of the message, however the return data is only available after the message has been confirmed by the global consensus group.
  • Several time-related opcodes are available to contracts. These opcodes return the timestamp when the current execution started, when the message was committed to the account's chain by the local consensus group, when the message was first globally confirmed, and the timestamp indicated by the message itself. These opcodes can be used to implement time-based logic in contracts.
Previous
Zero Knowledge Proofs