Neo VM Core
Core virtual machine implementation for Neo zkVM.
Features
- Full Neo N3 opcode support
- Gas metering
- Execution tracing for proof generation
- Cryptographic operations (SHA256, RIPEMD160, ECDSA)
Quick Start
use ;
// Create a VM with 1M gas limit
let mut vm = new;
// Load a script: 2 + 3 = 5
vm.load_script.unwrap;
// Execute until halt
while !matches!
// Get the result
assert_eq!;
Script Format
Scripts are byte vectors containing Neo N3 opcodes. Common operations:
0x10-0x20: Push integers 0-160x0F: Push -10x0B: Push Null0x9E: ADD0x9F: SUB0xA0: MUL0xA1: DIV0xA2: MOD0x40: RET (return)
Example: Simple Arithmetic
use ;
// Compute 5 * 4 = 20
let script = vec!;
let mut vm = new;
vm.load_script.unwrap;
while !matches!
assert_eq!;
Example: Hash Computation
use ;
// Compute SHA256 of "hello"
let script = vec!;
let mut vm = new;
vm.load_script.unwrap;
while !matches!
if let Some = vm.eval_stack.pop
Example: Gas Metering
use ;
let mut vm = new; // Very low gas limit
// Create a script that will exhaust gas (multiple operations)
let script = vec!; // Multiple PUSH1 operations
vm.load_script.unwrap;
// Execute until out of gas or halt
while !matches!
// VM may halt normally or fault due to gas depending on execution
assert!;
Example: Error Handling
The VM correctly handles errors like division by zero:
use ;
let mut vm = new;
// Division by zero should cause a fault
// Script: PUSH5, PUSH0, DIV, RET
let script = vec!;
vm.load_script.unwrap;
while !matches!
assert!;