Skip to content

NeoVM Execution Model

Back to Runtime Specification

The Neo Virtual Machine (NeoVM) is a stack-based virtual machine designed for executing smart contracts on the Neo N3 blockchain. The embedded runtime in neo-solc faithfully emulates this execution model for local testing.

Stack Machine Architecture

NeoVM uses two stacks for computation:

  • Evaluation Stack -- the primary operand stack. All instructions consume operands from and push results to this stack. Stack items can be integers (arbitrary precision), byte arrays, booleans, arrays, structs, maps, or interop handles.
  • Alt Stack -- an auxiliary stack for temporary storage. Items can be moved between the evaluation stack and alt stack using TOALTSTACK and FROMALTSTACK.

Slots

NeoVM provides three categories of indexed variable slots, initialized per execution context:

Slot TypeOpcodesPurpose
LocalLDLOC0-LDLOC6, LDLOC, STLOC0-STLOC6, STLOCFunction-local variables
ArgumentLDARG0-LDARG6, LDARG, STARG0-STARG6, STARGFunction parameters
StaticLDSFLD0-LDSFLD6, LDSFLD, STSFLD0-STSFLD6, STSFLDContract-level static storage

Slots are allocated with INITSLOT (locals + arguments) or INITSSLOT (static slots). Each slot holds a single stack item of any type.

Execution Contexts

Each function call creates a new execution context containing:

  • Its own evaluation stack frame
  • Local and argument slots (sized by INITSLOT)
  • An instruction pointer into the script bytecode
  • Exception handling state (try/catch/finally frames)

The CALL instruction pushes a new context; RET pops it and returns control to the caller.

MIT Licensed