StoffelVM Overview
StoffelVM is a register-based virtual machine specifically designed and optimized for secure Multi-Party Computation (MPC). It provides a flexible and efficient foundation for executing MPC protocols while maintaining protocol agnosticism.Key Features
Register-Based Architecture
Unlike stack-based VMs, StoffelVM uses a register-based design that enables:- Easy Optimization: Direct mapping to physical hardware registers
- Efficient Compilation: Cleaner code generation from high-level languages
- MPC Optimization: Separate handling of clear and secret values
Rich Type System
StoffelVM supports a comprehensive set of value types:- Primitives:
i64integers, fixed-point floats, booleans, strings - Collections: Arrays and objects with dynamic sizing
- Functions: Closures with true lexical scoping and upvalue capture
- Foreign Objects: FFI integration with host language objects
- Unit Type: Void/null values for control flow
MPC Integration
The VM is designed with MPC in mind:- Clear/Secret Separation: Distinct register spaces for public and private data
- Protocol Agnosticism: Works with different MPC protocol implementations
- Efficient Sharing: Optimized handling of secret-shared values
Current Status
🚧 Development Status StoffelVM is currently functional with some quirks. The core VM operations work well, but full MPC functionality is still in development.Working Features:
- ✅ Complete instruction set implementation
- ✅ Register management and memory operations
- ✅ Arithmetic and bitwise operations
- ✅ Control flow (jumps, calls, returns)
- ✅ Object and array manipulation
- ✅ Closure system with lexical scoping
- ✅ Foreign function interface (FFI)
- ✅ Built-in standard library functions
- 🚧 Full MPC protocol integration
- 🚧 Automatic memory management/garbage collection
- 🚧 Exception handling system
- 🚧 Dynamic library loading/unloading
- 🚧 Tail call optimization
Architecture Overview
Value Types
Primitive Types
Complex Types
Instruction Set
Memory Operations
Arithmetic Operations
Bitwise Operations
Control Flow
Usage Patterns
Embedding in Applications
The VM is designed to be embedded in larger applications:CLI Usage
The VM can also be used via the CLI to run compiled programs:Standard Library
StoffelVM includes essential built-in functions:print: Output values to consolecreate_object: Create new objectscreate_array: Create new arraysget_field/set_field: Object/array field accessarray_length/array_push: Array operationscreate_closure/call_closure: Closure operationsget_upvalue/set_upvalue: Upvalue managementtype: Runtime type information
Hook System
The VM provides a configurable hook system for:- Instruction Execution: Intercept and monitor individual instructions
- Register Access: Track register reads and writes
- Activation Stack: Monitor function calls and returns
- Memory Operations: Debug object and array operations
- MPC Integration: Protocol-specific hooks for secret operations
Performance Characteristics
Register-Based Advantages
- Fewer Instructions: Direct register operations reduce instruction count
- Better Optimization: Easier to optimize compared to stack machines
- Hardware Mapping: Natural mapping to CPU registers
MPC Optimizations
- Separate Register Spaces: Efficient handling of clear vs. secret data
- Batched Operations: Group operations for better protocol efficiency
- Memory Layout: Optimized for secret sharing and reconstruction
Integration with Ecosystem
StoffelLang Compilation
The VM executes bytecode generated by the StoffelLang compiler:Python SDK Integration
The Python SDK provides high-level bindings to the VM:MPC Protocol Integration
The VM integrates with MPC protocols for secure computation:Future Development
Planned enhancements for StoffelVM:- Full MPC Integration: Complete protocol integration for secure computation
- Garbage Collection: Automatic memory management for objects and arrays
- Exception Handling: Structured error handling and recovery
- Tail Call Optimization: Efficient recursive function calls
- Just-In-Time Compilation: Runtime optimization for hot code paths
- Debugging Tools: Enhanced debugging and profiling capabilities
Next Steps
To learn more about StoffelVM:- Instructions and Types: Detailed instruction set reference
- Using the VM: Practical examples and integration patterns
- Built-in Functions: Standard library reference