Using the VM
This guide covers how to run compiled StoffelLang programs using StoffelVM, including command-line options, debugging techniques, and integration with MPC protocols.Running Programs
Basic Execution
After compiling a StoffelLang program to bytecode, usestoffel-run to execute it:
program.stfbin: Path to the compiled bytecode filemain: Name of the entry function to execute (optional, defaults tomain)
Output
A successful execution returns the program’s result:nil:
Command-Line Flags
Debugging Flags
StoffelVM provides detailed tracing for debugging program execution:| Flag | Description |
|---|---|
--trace-instr | Trace instructions before and after execution |
--trace-regs | Trace register read and write operations |
--trace-stack | Trace function calls and stack operations |
Instruction Tracing
- Instruction address
- Opcode and operands
- Register assignments
Register Tracing
- Register reads and writes
- Values being stored and retrieved
- Clear vs secret register operations
Stack Tracing
- Function call entries and exits
- Stack frame allocation
- Return addresses and values
Combined Tracing
For comprehensive debugging, combine multiple flags:Bytecode File Format
File Extensions
| Extension | Description |
|---|---|
.stfbin | Binary bytecode format (recommended) |
.stfb | Alternative binary extension |
.bc | Text-based bytecode (for debugging) |
Binary Structure
The.stfbin file contains:
- Header: Magic bytes, version, metadata
- Constants pool: Literal values and strings
- Main chunk: Entry point bytecode
- Function chunks: Compiled function bodies
Execution Modes
Local Execution
For development and testing without MPC:- Secret values are computed directly (not distributed)
- Useful for logic testing before MPC deployment
- Full debugging support available
MPC Execution
For distributed secure computation:- Values are secret-shared across parties
- HoneyBadger protocol handles Byzantine fault tolerance
- Requires network configuration (see Rust SDK)
Integration with MPC Protocols
HoneyBadger Integration
StoffelVM integrates with the HoneyBadger MPC protocol for secure multi-party computation:Configuration Requirements
For MPC execution, all parties must agree on:| Parameter | Constraint | Example |
|---|---|---|
n_parties | Number of compute nodes | 5 |
threshold | Max faulty parties | 1 |
instance_id | Unique computation ID | 12345 |
n_parties >= 3 * threshold + 1
Valid configurations:
- 4 parties, threshold 1:
4 >= 4✓ - 5 parties, threshold 1:
5 >= 4✓ (recommended minimum) - 7 parties, threshold 2:
7 >= 7✓
ClientStore Integration
When running with MPC, the VM’sClientStore is populated with client shares:
Error Handling
Common Errors
“Error loading binary”- Verify the file path is correct
- Ensure the file was compiled successfully
- Check the entry function name matches what’s in the source
- Use
--trace-instrto see available functions
- Check for infinite recursion
- Consider iterative alternatives for deep recursion
- Verify operand types match expected types
- Check for mixing clear and secret values incorrectly
Debugging Workflow
-
Start with instruction tracing:
-
Add register tracing for value issues:
-
Add stack tracing for call issues:
Performance Considerations
Register Architecture
StoffelVM uses a dual-register architecture:- Clear registers: Fast operations on public values
- Secret registers: MPC-protected operations on private values
Optimization Levels
When compiling with StoffelLang, use optimization flags:Examples
Simple Arithmetic
Fibonacci with Debugging
MPC Integration Test
Next Steps
- Built-in Functions: Reference for available builtins
- Instructions: Complete instruction set documentation
- Rust SDK: Integrate with Rust applications
- MPC Protocols: Understand the underlying cryptography