Architecture

Overview

lessVM is a stack-based virtual machine designed specifically for the Solana blockchain. It features a simple instruction set with stack manipulation, arithmetic operations, memory access, control flow, and Solana-specific operations.

Core Components

Stack

#[repr(C, align(64))]
struct Stack {
    data: [Value; 32],
    top: usize,
}
  • → 32 entries deep
  • → 64-bit values
  • → LIFO (Last In, First Out)
  • → Overflow protection

Memory

#[repr(C, align(64))]
struct Memory {
    data: [u8; 1024],
    size: usize,
}
  • → 1024 bytes linear memory
  • → Bounds checking
  • → Zero-initialized
  • → Memory expansion tracking

Gas Metering

struct GasConfig {
    base_cost: u64,
    memory_cost: u64,
    solana_op_cost: u64,
    spl_op_cost: u64,
    cpi_cost: u64,
    gas_limit: u64,
}
  • → Operation-based costs
  • → Memory expansion costs
  • → CPI operation costs
  • → Gas limit enforcement

Program Counter

struct VM {
    pc: usize,
    code: &[u8],
    // ...
}
  • → Instruction pointer
  • → Sequential execution
  • → Jump validation
  • → Bounds checking

Security Features

Memory Safety

  • → Stack overflow protection
  • → Memory bounds checking
  • → Zero-initialized memory

Account Safety

  • → Account ownership verification
  • → Write permission checks
  • → Lamport balance checks

Execution Safety

  • → Gas metering
  • → Jump target validation
  • → CPI depth tracking