Architecture - UnitBuilds-CC/Merkles-World GitHub Wiki

Architecture

Condensed from docs/01-architecture.md.

Status: architecture specified. A-01 contracts/coords.rs is frozen (2026-10-11, on ADR-029's sign-off) โ€” every layer may now implement against the coordinate surface. The rest of contracts/ is not frozen. A layer whose subsystem doc cites an open SPEC/OQ is a description, not a build target.

The stack

Layer Choice Property
Engine runtime Rust + WebGPU/WGSL memory-safe, cross-platform, browser-capable
Coordinates HDCS: i64 global + camera-relative f32 infinite range, bit-identical across machines
Macro state Merkle ledger + localized octree roots, LSM-style compaction world bounded by hash/disk, not RAM/tick rate
Micro edits Sparse delta mask, bitpacked u64 in slabs O(1) write, cleared at commit
Memory Slab allocator, bump pointer, L1 VRAM / L2 RAM, LRU zero fragmentation, O(1) mass reset
Rendering GPU compute SDF raymarching no meshes, no textures, infinite detail
Culling Spatial BVH keyed to slabs O(log N) entity skip
Physics Analytic โˆ‡SDF gradient queries normals without vertex buffers
Animation Domain deformation over time no skeletons
Audio Sphere-traced SDF occlusion sound knows the geometry, nothing baked
Circuits Compiled graph topology f(inputs, t) zero wire latency, runs while unloaded
Macro simulation Time functions + bounded CA + event tags lazy, fast-forwarded at observation
Logic & mods Polyglot WASM behind WIT contracts deterministic, sandboxed, hot-reloaded
Assets RON/JSON/KDL/TOML authored โ†’ FlatBuffers runtime human to write, zero-copy to run
Multiplayer Signed intent streams + rollback + epoch root verification 32 bytes proves world equality

Data lifecycle

AUTHORING (RON ยท JSON ยท KDL ยท TOML ยท Rust/TS/C++/Python/Go ยท WGSL)
      โ”‚  assetc: parse once, validate, emit binary   (<5 ms, never at frame time)
      โ–ผ
CONTRACTS (FlatBuffers .fbs + WIT worlds)            โ† the only thing the runtime trusts
      โ”‚  mmap / memcpy โ†’ GPU storage buffers
      โ–ผ
ENGINE RUNTIME  (ledger ยท slabs ยท BVH ยท gradients ยท WASM ยท graphs)
      โ”‚  per frame, camera-relative f32
      โ–ผ
RENDER PROJECTION (WGSL compute raymarcher โ†’ pixels)

The rule this encodes: text exists only to the left of the compile step. The runtime never parses.

Two-layer state

        GLOBAL MERKLE LEDGER   (slow, cheap, authoritative, hashable)
                    โ–ฒ commit at epoch / sleep
   LOCAL DELTA MASK โ”˜โ”€โ”€โ–บ GPU RENDER PROJECTION   (fast, local, disposable)

The ledger records what happened as transactions and named event tags. The projection computes what you see from MerkleRoot_N โŠ• LocalDelta for this frame's frustum.

Core equations

Name Form
view-time state BlockState = f(Position, CurrentTick) โŠ• PlayerDelta
rendered state Final = S_base โŠ• M_local
epoch commit S_new = S_old โŠ• M_local, then M_local = โˆ…
render pass pixels = Render(SlabState(FrustumSlabs), C_global) โ€” state arrives by buffer, the shader only projects it
clock circuit state(t) = โŒŠ(t + ฯ†)ยทฯ‰โŒ‹ mod 2
factory output items = โˆซ[t_start โ†’ t_sleep] ProductionRate(t) dt
epoch proof EpochHash = MerkleHash(BaseGenesisRoot โŠ• CommittedSlabs)
surface normal N = โˆ‡SDF(p) (central differences, 6 evaluations)
camera transform P_local = P_global โˆ’ C_global

Note on the render-pass row. The source wrote it as VoxelOutput = ComputeShader(XYZ, MerkleRoot_N) โŠ• LocalDelta โ€” the GPU deriving voxel state from a Merkle root. That form is rejected (SPEC-02, ADR-017): f(pos, epoch) runs in deterministic Rust/WASM, because WGSL float math differs per adapter and two GPUs would produce two roots. The row above is the sanctioned reading; the original is kept here so the correction is visible rather than silent.

Invariants

  1. One coordinate truth โ€” every subsystem resolves space through HDCS; no private axes.
  2. Simulation never reads the GPU โ€” gradients come from SDF source on CPU/WASM, not VRAM.
  3. Hot path is allocation-free โ€” pre-reserved slab slots only.
  4. Runtime parses nothing โ€” FlatBuffers / static WASM memory.
  5. Deterministic or not shipped โ€” canonical state uses integers, fixed-point, or deterministic WASM float ops whose result nothing hashes; nothing a hash depends on comes from a shader (ADR-017, the fix for the design's most dangerous inconsistency).
  6. The delta mask is the memory โ€” player changes survive in M_local or a committed epoch; untouched base land is regenerable and never treated as storage.
  7. Epochs are total โ€” mid-epoch truth is always base โŠ• pending.
  8. Mods are transactions โ€” never direct block-array writes.
  9. Contracts change by ADR only.

What it buys, what it costs

Buys: world scale bounded by disk/hashes; no state loading screens (fast-forwarding centuries is a hash-and-flag update); near-zero storage for untouched terrain; a visibly aged world without per-entity pathfinding; every asset expressible as text; verifiable multiplayer in 32 bytes.

Costs (each tracked as an open question, not a footnote): traditional redstone-style sequential logic is unsolved (OQ-02); distant causality needs a mechanism nobody has proven (OQ-01 โ€” the spike that can invalidate the design); SDF raymarching costs fill-rate and lives or dies on culling discipline; and the world gives up exact mid-simulation history in exchange for endpoint correctness.