Architecture
Voltaire is a multi-language Ethereum primitives and cryptography library. This guide covers the codebase structure and key architectural decisions.
Directory Structure
Module System
Zig Modules
Each major area has a root.zig entry point:
Import Convention
Never use relative imports across module boundaries.
This enables:
- Clean dependency tracking
- Easy refactoring
- Consistent import style across codebase
File Colocation Pattern
Each primitive type has colocated implementations:
Why Colocation?
- Discoverability: Find all related code in one place
- Consistency: TS and Zig implementations stay synchronized
- Testing: Tests live next to implementation
- Documentation: Docs update with code changes
Layered Architecture
TypeScript Layer
- Branded
Uint8Array types for type safety
- Namespace pattern for tree-shaking
- Dual exports (internal
_method + wrapper)
FFI/WASM Layer
- Bun FFI for native performance
- WASM fallback for browser/non-Bun environments
- Automatic memory management
Zig Core
- Performance-critical implementations
- Direct memory control
- Cross-compilation support
Native Libraries
- Rust via Cargo: arkworks curves, keccak-asm
- C libs: blst (BLS12-381), c-kzg-4844 (KZG)
Dependency Graph
precompiles depends on both primitives and crypto
crypto depends on primitives (for types like Hash)
- Both depend on C/Rust libraries for performance-critical ops
Build Outputs
Design Principles
1. Zero-Cost Abstractions
Branded types have no runtime cost. They’re purely compile-time TypeScript constructs.
2. Memory Ownership
Zig code returns memory to caller. Caller is responsible for deallocation.
3. No Hidden Allocations
Functions that allocate take an explicit allocator parameter.
4. Fail Fast
Invalid inputs cause immediate errors. No silent failures or defaults.
5. Cross-Validate
Implementations are tested against reference libraries (noble, ethers, viem).