StoffelLang Overview
StoffelLang is a modern programming language designed specifically for secure Multi-Party Computation (MPC) applications. With syntax inspired by Rust, Python, and JavaScript, it provides a familiar development experience while offering powerful features for privacy-preserving computation.Design Goals
StoffelLang is designed with the following principles:- Familiar Syntax: Draws from popular languages to reduce learning curve
- Type Safety: Strong static typing with type inference for reliability
- MPC Native: Built-in support for secret and public data distinctions
- Performance: Compiles to efficient StoffelVM bytecode
- Developer Experience: Clear error messages and tooling integration
Key Features
Modern Language Features
- Static Typing: Strong type system with inference to catch errors early
- Pattern Matching: Powerful pattern matching for control flow
- Closures: First-class functions with lexical scoping
- Memory Safety: Automatic memory management without garbage collection overhead
- Generics: Parametric polymorphism for reusable code
MPC-Specific Features
- Secret Types: Native support for
secrettype annotations - Reveal Operations: Explicit operations for transitioning from secret to public
- Protocol Agnostic: Works with different MPC protocol backends
- Optimized Compilation: Generates efficient MPC-aware bytecode
Syntax Overview
Basic Syntax
MPC-Specific Syntax
Advanced Features
Type System
Primitive Types
int64: 64-bit signed integers (primary integer type)bool: Boolean values (true,false)string: UTF-8 stringsnil: Null/empty value
Collection Types
- Objects: Structured data with named fields
- Enums: Enumerated types with named variants
- Lists: Dynamic arrays (planned)
- Tuples: Fixed-size heterogeneous collections (planned)
Secret Types
Any type can be made secret by prefixing withsecret:
Function Types
Compilation Process
StoffelLang follows a multi-stage compilation process:Compilation Stages
- Lexical Analysis: Tokenizes source code
- Parsing: Builds Abstract Syntax Tree (AST)
- Type Checking: Verifies type correctness and infers types
- Optimization: Applies various optimization passes
- Code Generation: Generates StoffelVM bytecode
Optimization Levels
Integration with StoffelVM
StoffelLang compiles to StoffelVM bytecode, which includes:- Rich Type Information: Preserves type metadata for runtime
- Function Definitions: Complete function metadata and instructions
- Constant Pools: Efficient storage for literals and constants
- Debug Information: Line numbers and variable names for debugging
Binary Format
The compiler generates.stfbin files that contain:
Development Tools
Compiler CLI
Integration with Stoffel CLI
The StoffelLang compiler is integrated with the main Stoffel CLI:Examples
Hello World
Secure Addition
Complex Data Structures
Basic Computation
Future Features
Planned enhancements for StoffelLang:- Pattern Matching: Powerful pattern matching for complex data
- Generics: Parametric polymorphism for reusable code
- Async/Await: Asynchronous programming support
- Macros: Compile-time code generation
- Package System: Module imports and dependency management
- Standard Library: Comprehensive built-in functions and types
Language Server
A Language Server Protocol (LSP) implementation is planned to provide:- Syntax Highlighting: Rich syntax highlighting in editors
- Error Reporting: Real-time error checking and suggestions
- Auto-completion: Intelligent code completion
- Go-to Definition: Navigate to symbol definitions
- Refactoring: Automated code refactoring tools
Next Steps
To learn more about StoffelLang:- Syntax and Examples: Detailed syntax guide with examples
- Compilation: Understanding the compilation process