| title | Deterministic Lua (EchoLua Profile) |
|---|
- Goals
- Compilation Pipeline
- Deterministic Runtime Profile
- Standard Library (Deterministic Subset)
- RNG
- Linter / Compiler Rules
- Proof / Trailer Integration
- Open Implementation Notes
EchoLua defines a deterministic execution profile for Lua used in GATOS policies and folds. It locks down semantics so the same inputs yield the same bytes across platforms.
This document is normative where called out by SPEC and TECH-SPEC; elsewhere it is strongly RECOMMENDED.
- Pure, total, side-effect-free fold execution.
- Cross-platform bit-for-bit deterministic results.
- Portable compiled form for long-term verification.
Lua source ──parse/normalize──► AST ──lower──► ELC (Echo Lua IR; deterministic IR)
│
└─► DAG-CBOR bytes (CBOR-encoded DAG; fold_root = sha256(ELC_bytes))
- Normalize: remove syntactic sugar, canonical constant folding, resolve upvalues.
- Lower: emit a small, explicitly typed IR + minimal VM op set.
- Serialize: ELC encoded as DAG-CBOR;
fold_root = sha256(ELC_bytes). - Prohibition: Stock Lua bytecode (luac) is NOT portable and MUST NOT be used on disk or for signing.
| Area | Default Lua | EchoLua profile (deterministic) |
|---|---|---|
| Time/OS | os.clock, os.time, io.* | Removed (forbidden) |
| Random | math.random (MT) | rng(seed) intrinsic only; no global state |
| Numbers | Host IEEE-754 | Fixed-point Q32.32 with ties-to-even; canonical NaN handling (N/A) |
| Iteration | pairs() unspecified | dpairs(t) sorts keys; ipairs allowed |
| Table hashing | Randomized seed | Fixed seed; do not rely on hash order |
| Coroutines | yield anywhere | Disallowed in folds/policy eval |
| Metamethods | __gc etc. | __gc and __pairs forbidden; compile-time error |
| FFI/dlopen | via add-ons | Forbidden |
| Math lib | Host-lib variance | Deterministic lib; exp/log/sin/cos pinned or disallowed |
Additional invariants:
- Canonical JSON: UTF-8 NFC; lexicographic key sort; fixed number encoding (no
-0, no trailing zeros). - Resource caps: fuel/step counters (MUST terminate within limits).
table:dkeys,dvalues,dsort,dpairs(t)(sorted iteration).json:encode_canonical,decode_strict.math: +, −, ×, ÷ in Q32.32 (division rounds toward zero). Transcendentals (sin/exp/log/…) are not permitted in v1 folds; perform in jobs (PoE) instead.set,counter: deterministic CRDT (Conflict-free Replicated Data Type)-style helpers for folds.- No
debug,package,io,osmodules.
- No ambient RNG. Provide
rng(seed_bytes)which expands a user-supplied seed into a deterministic stream. - Normative algorithm:
pcg32@1. Implementations MUST record RNG id and version via theFold-Enginestring and SHOULD includeFold-RNGtrailer when RNG is used. - Canonical seed helper:
seed64 = trunc64(blake3(inputs_root || policy_root || fold_root)). - Use discouraged in folds; if used, caller MUST pass explicit seed material.
Hard-fail on:
- use of
pairs,coroutine,__gc,__pairs,math.random,os.*,io.*,debug.*,package.*. - non-canonical numeric literals; non-deterministic table traversal.
- State checkpoints MUST include
Fold-Root: sha256:<hex>trailers. - RECOMMENDED trailers:
Fold-Math: fixed-q32.32@<libver>,Fold-RNG: <alg>@<ver>. - PoF (Proof of Fold) envelopes SHOULD include
fold_rootand verifiers MUST recompute from ELC bytes when present.
- Transcendentals: when required, ship a pinned deterministic math library and record its version in
Fold-Engine. - Performance: heavy data operators should be implemented as deterministic native intrinsics, invoked from EchoLua.