| Crates.io | toka |
| lib.rs | toka |
| version | 0.0.0 |
| created_at | 2026-01-16 07:27:20.201272+00 |
| updated_at | 2026-01-16 07:27:20.201272+00 |
| description | Capability-bounded stack VM for secure distributed computing |
| homepage | |
| repository | https://github.com/nickspiker/toka |
| max_upload_size | |
| id | 2048103 |
| size | 88,529 |
Status: v0.0 - Early Development
Toka is a stack-based virtual machine designed for executing signed, capability-bounded bytecode in distributed systems. It provides deterministic execution, cryptographic verification, and zero platform-specific behavior.
Key Features:
Toka is a stack machine with:
VSF Capsule (signed bytecode)
↓ Verify VSF
↓ Verify ed25519 signature
↓ Parse bytecode
↓ Grant declared capabilities
Rune VM Execution
↓ Stack operations
↓ Spirix arithmetic
↓ Capability-checked I/O
Canvas Rendering (viewport coords)
↓ Browser: Canvas 2D API
↓ Native: Spirix GPU kernels
Pixels on Screen
A capsule is an immutable, signed executable bundle:
VSF File:
<
z3◖6◗ Version
y3◖5◗ Backward compat
eu◖timestamp◗ Created
hp3◖31◗ BLAKE3 hash ◖32 bytes◗
ge◖signature◗ Ed25519 signature
n3◖sections◗ Section count
>
[bytecode
(main:{ps}s44◖0.5◗{ps}s44◖0.3◗{fc}{ht})
(render:{cc}u5◖0xFFFFFFFF◗{fr}{ht})
]
[metadata
(name:l◖"MyApp"◗)
(version:z◖1◗)
]
Security Model:
Rune supports these stack value types:
| Type | Description | Size | Range |
|---|---|---|---|
s44 |
Spirix F4E4 (default numeric) | 32-bit | ±2^±32768, 65K fraction values |
s53 |
Spirix F5E3 (extended precision) | 40-bit | ±2^±128, 4B fraction values |
u3-u7 |
Unsigned integers | 8-256 bit | 0 to 2^(2^N)-1 |
i3-i7 |
Signed integers | 8-256 bit | -2^(2^N-1) to 2^(2^N-1)-1 |
l |
ASCII label/string | Variable | Metadata, names |
x |
Huffman text (Unicode) | Variable | Compressed strings |
Color |
RGBA color | 32-bit | 0xRRGGBBAA |
Bool |
Boolean | 1 bit | true/false |
Handle |
Capability reference | 64-bit | Opaque ID |
No IEEE-754 floats. Spirix provides deterministic, platform-independent arithmetic without IEEE edge cases (±0, NaN fingerprinting, denormal branches).
No usize/isize. Explicit integer sizes (u3-u7) ensure same bytecode produces identical results on 16/32/64-bit platforms.
S44 (ScalarF4E4) = 16-bit fraction + 16-bit exponent = 32 bits total
Advantages:
No IEEE nonsense:
// IEEE f32 edge cases that waste cycles:
-0.0 == 0.0 // true, but different bit patterns
NaN != NaN // breaks transitivity
0.1 + 0.2 != 0.3 // rounding errors
// Spirix S44 is clean:
Zero is Zero (one bit pattern)
Undefined states are deterministic ([℘ ⬇/⬇] always same bits)
Math that works like math (a × b = 0 iff a = 0 or b = 0)
Opcodes: Two lowercase ASCII characters in braces Operands: VSF-encoded values with ◖◗ notation
{op} → Opcode with no operands (4 bytes)
{op}type◖value◗ → Opcode with VSF operand (variable length)
Example:
{ps}s44◖0.5◗ → Push S44 scalar (0.5)
{ad} → Add top two stack values
{ht} → Halt execution
Stack Manipulation (6 ops)
{ps} value - Push constant to stack
{po} - Pop (discard top)
{du} - Duplicate top value
{sw} - Swap top two values
{rt} - Rotate top three (a b c → b c a)
Local Variables (4 ops)
{la} count - Allocate N local slots
{lg} index - Push local[index] to stack
{ls} index - Pop stack to local[index]
{lt} index - Copy top to local[index] without popping
Arithmetic (8 ops - all Spirix)
{ad} - Add (pop b, a; push a + b)
{sb} - Subtract (pop b, a; push a - b)
{ml} - Multiply (pop b, a; push a * b)
{dv} - Divide (pop b, a; push a / b)
{md} - Modulo (pop b, a; push a % b)
{ng} - Negate (pop a; push -a)
{mn} - Min (pop b, a; push min(a,b))
{mx} - Max (pop b, a; push max(a,b))
Drawing (8 ops - viewport relative 0.0-1.0)
{cc} - Clear canvas (pop: color)
{fr} - Fill rect (pop: color, h%, w%, y%, x%)
{fc} - Fill circle (pop: color, r%, cy%, cx%)
{dl} - Draw line (pop: width%, color, y2%, x2%, y1%, x1%)
{dt} - Draw text (pop: size%, y%, x%, string)
{sc} - Set color (pop: color)
{sr} - Stroke rect (pop: width%, color, h%, w%, y%, x%)
{sl} - Stroke circle (pop: width%, color, r%, cy%, cx%)
Control Flow (4 ops)
{br} target - Branch to instruction index
{bi} target - Branch if true (pop condition)
{ht} - Halt execution
{np} - No operation
Debug (2 ops)
{dp} - Debug print (pop value, print to console)
{ds} - Debug stack (print entire stack state)
Draw red circle:
{ps}s44◖0.5◗ # Push x (center)
{ps}s44◖0.3◗ # Push y (center)
{ps}s44◖0.2◗ # Push radius
{ps}u5◖0xFF0000FF◗ # Push red color
{fc} # Fill circle
{ht} # Halt
Add two numbers:
{ps}s44◖100.0◗ # Push 100
{ps}s44◖42.0◗ # Push 42
{ad} # Add (result: 142)
{dp} # Debug print
{ht} # Halt
Loop with locals:
{la}u3◖2◗ # Allocate 2 locals (counter, sum)
{ps}s44◖0◗{ls}u3◖0◗ # local[0] = 0 (counter)
{ps}s44◖0◗{ls}u3◖1◗ # local[1] = 0 (sum)
# Loop start (instruction 0)
{lg}u3◖0◗ # Push counter
{ps}s44◖10◗ # Push limit
{lt} # counter < 10?
{bi}u4◖exit◗ # Branch if false to exit
{lg}u3◖1◗ # Push sum
{lg}u3◖0◗ # Push counter
{ad} # sum += counter
{ls}u3◖1◗ # Store sum
{lg}u3◖0◗ # Push counter
{ps}s44◖1◗ # Push 1
{ad} # counter + 1
{ls}u3◖0◗ # Store counter
{br}u4◖0◗ # Loop back
# Exit
{lg}u3◖1◗ # Push final sum
{dp} # Print it
{ht} # Halt
All drawing uses viewport-relative coordinates (0.0-1.0):
(0.0, 0.0) ────────────────── (1.0, 0.0)
│ │
│ │
│ VIEWPORT │
│ │
│ │
(0.0, 1.0) ────────────────── (1.0, 1.0)
Benefits:
Font Size Calculation:
viewport_area = width_px × height_px
font_size_px = sqrt(size_fraction × viewport_area)
Example: size=0.01 (1% of viewport) on 1920×1080 screen:
area = 1920 × 1080 = 2,073,600
font_px = sqrt(0.01 × 2,073,600) = sqrt(20,736) ≈ 144px
All external resources accessed via handles (opaque u64 IDs):
// Capability declaration in capsule metadata:
[capabilities
(canvas_draw:true)
(file_read:false)
(network_access:false)
]
// Runtime checks:
{rh}u4◖canvas_handle◗ // read_handle - checks canvas_draw capability
{wh}u4◖file_handle◗ // write_handle - DENIED (file_write not granted)
Handle types:
canvas - Drawing operationsfile - File I/O (read/write)network - Photon transportbuffer - Memory allocationfont - Font loadingSecurity properties:
Rune has no linear memory model. Only handles.
This eliminates:
Storage options:
Target: Browser WASM (Chrome, Firefox, Safari)
Features:
Build:
wasm-pack build --target web --out-dir www/pkg
Usage:
import init, { RuneVM } from './pkg/rune.js';
await init();
const canvas = document.getElementById('canvas');
const bytecode = new Uint8Array([/* VSF capsule */]);
const vm = new RuneVM(canvas, bytecode);
// Run 1000 instructions per frame
function animate() {
if (vm.run(1000)) {
requestAnimationFrame(animate);
}
}
animate();
Target: Native browser with GPU stack
Features:
Performance:
No IEEE-754 anywhere in the pipeline.
rune/
├── src/
│ ├── lib.rs # WASM entry point, public API
│ ├── main.rs # Native CLI runner (testing)
│ ├── value.rs # Value type system
│ ├── stack.rs # Stack implementation
│ ├── instruction.rs # Instruction enum + decoder
│ ├── vm.rs # VM executor
│ ├── canvas.rs # Canvas backend (WASM + native)
│ ├── bytecode.rs # VSF bytecode parser
│ └── error.rs # Error types
├── www/
│ ├── index.html # WASM test harness
│ └── pkg/ # wasm-pack output
├── Cargo.toml
├── OPCODES.md # Full instruction reference
├── SCAFFOLD.md # Architecture overview
└── README.md # This file
[dependencies]
vsf = { path = "../vsf" } # VSF serialization
spirix = { path = "../spirix" } # Spirix arithmetic
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["CanvasRenderingContext2d", "HtmlCanvasElement"] }
# Native build
cargo build --release
cargo run
# WASM build
wasm-pack build --target web --out-dir www/pkg
# Test
cargo test
# Serve WASM locally
python3 -m http.server 8000
# Open http://localhost:8000/www/
Unit Tests:
Integration Tests:
WASM Tests:
| Feature | WASM | JVM | Rune |
|---|---|---|---|
| Arithmetic | IEEE-754 f32/f64 | IEEE-754 float/double | Spirix S44 (deterministic) |
| Memory Model | Linear memory | Garbage collected heap | Handle-only (no pointers) |
| Security | Sandboxed | Security manager | Capability-based |
| Verification | SHA-256 (optional) | JAR signing (optional) | BLAKE3 + ed25519 (mandatory) |
| Determinism | Platform-dependent NaNs | GC timing varies | Fully deterministic |
| Graphics | WebGL/Canvas via JS | Java2D/JavaFX | Native viewport coords |
| Size overhead | Moderate | Large (JVM runtime) | Minimal (VM + bytecode) |
Same bytecode must produce identical results everywhere:
usize, isize)Implications:
Less mechanism = less attack surface:
Capabilities instead of ACLs:
Not "fast despite safety" but "fast because of safety":
v0.0 (Current) - Portal MVP
v0.0 - Expanded Instructions
v0.2 - Security & I/O
v0.3 - Full Instruction Set
v0.x+ - Nautilus Integration
Custom open-source (see LICENSE):
Hardware implementation rights reserved - contact for licensing.
Nick Spiker nick@verichrome.cc
Status: Early development. Not production-ready. API will change.
Contribute: Issues and PRs welcome at https://github.com/fractaldecoder/rune (when public)
Learn More: https://holdmyoscilloscope.com/rune/