T81 Foundation

Archive Note: This document is historical and experimental. It is not normative for current T81 behavior. For authoritative definitions of ISA/VM behavior, refer to ../tisc-spec.md and ../t81vm-spec.md.

Hanoi Kernel v0.1.1

A Deterministic, Capability-Native, Axion-Governed Microkernel for T81-Class Machines

This archived reference captures the intended behavior of the Hanoi kernel proposal: architecture, boot flow, syscall interface, ABI, deterministic entropy model, CanonSeal key derivation, diagrams, and implementation scaffold.

This is the archived v0.1.1 snapshot.


1. Executive Summary

Hanoi is a deterministic ternary microkernel serving as the constitutional OS substrate for the T81 ecosystem:

It is designed to be:

Hanoi is not a general-purpose OS.
It is the execution substrate for T81-class machines.


2. Kernel Invariants (Historical Proposal)

Violation of any invariant means the system is not Hanoi.

  1. No mutable global state outside capability boundaries.
  2. Every object is a CanonRef (content hash + capability + optional sealing).
  3. CanonFS is the sole storage abstraction; the root is always a snapshot.
  4. Axion veto authority extends to all syscalls and state transitions.
  5. Syscalls are total functions returning Result<T, HanoiError>.
  6. Deterministic scheduling — global 81-slot tick.
  7. No userspace drivers — all kernel drivers are CanonFS modules.
  8. Boot requires full canonical verification (CanonHash-81 + CanonParity).
  9. Entropy is deterministic, seeded from the snapshot; no nondeterministic RNG.
  10. Sealed objects use derived per-object keys, no mutable key state.

3. High-Level Architecture

flowchart TD
  HW["Ternary Hardware / Hanoi Simulator"]
  TISC["TISC Execution Engine"]
  K["Hanoi Kernel (Capability, CanonFS, Axion, Scheduler, Memory, Syscalls, DRBG/time)"]
  U["Userland: T81VM + T81Lang Runtime"]

  HW --> TISC --> K --> U

4. Boot Process — 8 Deterministic Stages

Stage Name Action Failure →
0 ROM Stub Load first 729-tryte CanonBlock from boot medium AXHALT
1 CanonVerify Verify snapshot integrity via CanonHash-81 & CanonParity AXHALT
2 Decompress Inflate kernel image (LZ81/Z3std) → RAM AXHALT
3 AxionSeal Load Axion ethics module (Θ₁–Θ₉) and lock policies AXHALT
4 CapabilityRoot Mint root capability from snapshot hash AXHALT
5 Mount CanonFS Mount root snapshot at / (e.g., /snapshot/latest) AXHALT
6 Start T81VM Exec CanonExec binary as PID 1 AXHALT
7 Enter Userspace Begin deterministic global tick (Tick 0)

On any failure:

AXHALT(reason):
    freeze state → emit canonical lineage dump → halt permanently

Boot Flow Diagram

sequenceDiagram
    participant ROM as ROM Stub
    participant Verify as CanonVerify
    participant Axion as Axion Kernel
    participant FS as CanonFS
    participant VM as T81VM

    ROM->>Verify: Load Boot Block
    Verify->>Verify: Check CanonHash & Parity
    Verify->>Axion: Load Kernel & Ethics Module
    Axion->>Axion: Initialize Invariants (Θ₁–Θ₉)
    Axion->>FS: Mount Root Snapshot
    FS->>VM: Spawn PID 1 (CanonExec)
    VM->>VM: Begin Execution (Tick 0)

5. Core Kernel Subsystems

5.1 Capability Manager

Rationale

Hanoi rejects Discretionary Access Control (DAC) and Access Control Lists (ACLs) in favor of Object Capabilities (OCap). Security is not a check on “who you are” but “what you hold”.

Formal Model

A capability is a tuple: Cap := (ObjectRef, PermMask, ScopeID, AxionSig)

Invariants Enforced

  1. Unforgeability: Capabilities cannot be created by userspace, only granted.
  2. Connectivity: Access implies possession of a valid capability.
  3. Revocation: Revocation is immediate via Axion signal propagation.

Edge Cases & Failure Modes

Example Usage

// Grant read access to a specific block
auto read_cap = kernel.grant_cap(target_block, PERM_READ);
if (!read_cap) return read_cap.error();
process.send(recipient_pid, *read_cap);

5.2 CanonFS Driver (Ring 0)

Rationale

Storage is the single source of truth. By making the filesystem a Merkle-81 tree, the entire system state becomes a single hash.

Formal Model

CanonFS implements a content-addressed store. Store: Hash -> CanonBlock Writes do not mutate in place; they return a new SnapshotRef.

Invariants Enforced

  1. Immutability: Blocks are never modified.
  2. Self-Healing: Read failures trigger automatic reconstruction from parity shards.
  3. Deduplication: Identical content shares the same storage address.

Edge Cases & Failure Modes

Example Usage

auto block = canonfs.read_block(file_hash);
// Automatically verified and repaired

5.3 Axion Co-Processor

Rationale

Ethics and safety cannot be left to software conventions. They must be enforced by a privileged monitor that supervises execution.

Formal Model

Axion operates as a reference monitor M. M(State, Op) -> { Allow, Deny(Reason), Rewrite(NewOp) }

Invariants Enforced

  1. Θ₁–Θ₉ Compliance: No state transition may violate the ethical axioms.
  2. Resource Boundedness: No operation may exceed its allocated tick budget.

Edge Cases & Failure Modes

5.4 Deterministic Scheduler

Rationale

Nondeterministic interleaving is the root of most concurrency bugs. Hanoi schedules strictly by tick count.

Formal Model

Round-robin scheduling over 81 slots. Schedule(Tick) -> Pid = ActivePids[Tick % 81]

Invariants Enforced

  1. Tick Determinism: State(Tick) is strictly a function of State(Tick-1).
  2. Fairness: Every active process gets exactly 1 slot per 81 ticks.

Edge Cases & Failure Modes

5.5 Memory Manager

Rationale

Manual memory management is unsafe. Hanoi uses a linear memory model backed by CanonFS for persistence.

Formal Model

Memory is a sequence of Pages. Page := (CanonRef, Permissions) Allocations are strictly strictly bump-pointer or COW from CanonFS.

Invariants Enforced

  1. No Use-After-Free: Memory is reclaimed only when no capabilities reference it.
  2. Isolation: Processes cannot address memory outside their capability bounds.

Example Usage

auto region = memory.map_region(canon_ref, PERM_RW);
// region is now accessible in process address space

5.6 Syscall Layer

Rationale

The kernel surface must be minimal and total. Every syscall returns a result, never undefined behavior.

Formal Model

Syscall: (OpCode, Args...) -> Result<Value, HanoiError>


6. Snapshot Lifecycle

Snapshots are the heart of Hanoi’s state management. A snapshot represents the entire persistent state of the system at a given moment.

Lifecycle State Machine

stateDiagram-v2
    [*] --> Pending: fork_snapshot()
    Pending --> Committing: Axion Approval
    Pending --> Discarded: Drop / Reject
    Committing --> Active: switch_root()
    Active --> Archived: new switch_root()
    Active --> [*]: System Halt
    Archived --> [*]: GC

6.1 fork_snapshot()

auto fork_snapshot() -> expected<SnapshotRef, HanoiError>

Creates a mutable staging area (Copy-On-Write) from the current root. The new root is not yet visible to other processes.

6.2 commit_snapshot(snapshot)

auto commit_snapshot(SnapshotRef snapshot) -> expected<void, HanoiError>

Finalizes a pending snapshot, calculating the new Merkle root hash and persisting all dirty blocks.

6.3 switch_root(snapshot)


switch_root(snapshot: SnapshotRef)
-> Result<(), HanoiError>

Atomically:

  1. Suspends all processes
  2. Drops all mapped regions
  3. Replaces root snapshot
  4. Re-spawns PID 1 (T81VM)
  5. Resumes deterministic tick

This guarantees a fully immutable, deterministic root-switch.


7. System Call Reference (v0.1.1)

All syscalls use the TISC syscall instruction. Arguments are passed in registers R0–R4. Return value in R0. Error code in R1 if R0 indicates failure.

ID Name Signature Notes
0x00 fork_snapshot () -> Result<SnapshotRef, HanoiError> Create new snapshot root.
0x01 commit_snapshot (snapshot) -> Result<(), HanoiError> Write snapshot to timeline.
0x02 switch_root (snapshot) -> Result<(), HanoiError> Replace active snapshot (Axion-guarded).
0x03 spawn (exec: CanonRef) -> Result<Pid, HanoiError> Launch T81VM instance.
0x04 read_block (path) -> Result<ReadBlock, HanoiError> Auto-repair on read; ReadBlock includes repaired status.
0x05 read_object (href) -> Result<CanonObject, HanoiError> Load + repair + decompress.
0x06 grant_cap (cap) -> Result<CanonRef, HanoiError> Install capability.
0x07 revoke_cap (href) -> Result<(), HanoiError> Publish tombstone.
0x08 yield_tick () -> Result<(), HanoiError> Yield to next global tick.
0x09 map_region (href) -> Result<RegionHandle, HanoiError> Map object.
0x0A seal_object (href) -> Result<CanonRef, HanoiError> Wrap in CanonSeal.
0x0B unseal_object (href) -> Result<CanonRef, HanoiError> Unseal using derived key.
0x0C drbg () -> Result<DeterministicRandomTrytes, HanoiError> Deterministic entropy output.
0x0D parity_repair (root) -> Result<(), HanoiError> Repair subtree.
0x0E halt (reason) -> ! Permanent halt.

Detailed Specification

0x00: fork_snapshot

Signature: fork_snapshot() -> expected<SnapshotRef, HanoiError>

0x01: commit_snapshot

Signature: commit_snapshot(snapshot: SnapshotRef) -> expected<void, HanoiError>

0x02: switch_root

Signature: switch_root(snapshot: SnapshotRef) -> expected<void, HanoiError>

0x03: spawn

Signature: spawn(exec: CanonRef) -> expected<Pid, HanoiError>

0x04: read_block

Signature: read_block(path: CanonRef) -> expected<CanonBlock, HanoiError>

0x05: read_object

Signature: read_object(href: CanonRef) -> expected<CanonObject, HanoiError>

0x06: grant_cap

Signature: grant_cap(cap: Capability) -> expected<CanonRef, HanoiError>

0x07: revoke_cap

Signature: revoke_cap(href: CanonRef) -> expected<void, HanoiError>

0x08: yield_tick

Signature: yield_tick() -> void

0x09: map_region

Signature: map_region(href: CanonRef) -> expected<RegionHandle, HanoiError>

0x0A: seal_object

Signature: seal_object(href: CanonRef) -> expected<CanonRef, HanoiError>

0x0B: unseal_object

Signature: unseal_object(href: CanonRef) -> expected<CanonRef, HanoiError>

0x0C: drbg

Signature: drbg() -> DeterministicRandomTrytes

0x0D: parity_repair

Signature: parity_repair(root: CanonRef) -> expected<void, HanoiError>

0x0E: halt

Signature: halt(reason: Tryte) -> !

Errors

HanoiError :=
AxionRejection    // Policy violation
| CapabilityMissing // Not authorized
| CapabilityRevoked // Was authorized, now revoked
| CanonCorruption   // Hash mismatch / unrecoverable
| CanonMismatch     // Type expectation failure
| InvalidExec       // Malformed binary
| OutOfMemory       // Heap exhaustion
| RepairError       // Parity reconstruction failed
| SealError         // Crypto failure

8. Deterministic Randomness & Time (New in v0.1.1)

Hanoi has no nondeterministic time and no nondeterministic entropy.

There is no:

8.1 DRBG syscall (0x0C)


drbg() -> Result<DeterministicRandomTrytes, HanoiError>

Returns 81 trytes of pseudo-random data.

8.2 Deterministic seed derivation

The generator uses a sponge construction (SHAKE-81 equivalent) initialized at boot and re-keyed at every snapshot commit.

state[0] = SHAKE-tryte(
    snapshot_root_hash
    || AxionΘ_hash
    || process.pid
    || capability_envelope_hash
)

next_random() {
    state[i+1] = SHAKE-tryte(state[i])
    return state[i+1]
}

This ensures:

8.3 Time

There is only:

global_tick (incremented by scheduler)

No wall-clock time exists inside Hanoi. Time is measured in logic gates, not seconds.


9. CanonSeal Key Derivation (New in v0.1.1)

CanonSeal AEAD keys are not stored in memory.
They are derived deterministically per object, per snapshot.

9.1 KDF Formula

We use HKDF (HMAC-based Key Derivation Function) adapted for tryte sequences.


seal_key = HKDF-tryte(
    input = snapshot_hash
          || object_hash
          || AxionΘ
          || cap_tag,
    info  = "CanonSeal-v0.1",
    len   = 81_trytes
)

9.2 Test Vectors

Input:

Output (First 9 trytes): [A, B, C, -1, 0, 1, M, N, O] (Hypothetical deterministic output)

Key Properties

This eliminates key management vulnerabilities entirely.


10. ABI Specification

10.1 Process Model

struct Process {
    Pid pid;                 // Tryte identifier
    CanonRef exec;           // Code reference
    RegionHandle region;     // Memory map
    CapabilitySet caps;      // Held capabilities
    TISC_Addr pc;            // Program counter
    uint8_t tick_budget;     // Remaining ticks in quantum
};

10.2 Memory Layout

The address space is linear, 81-tryte aligned.


+-----------------------+
| Text (sealed)         |
+-----------------------+
| Data (sealed/raw)     |
+-----------------------+
| Heap (COW via CanonFS)|
+-----------------------+
| Stack (linear type)   |
+-----------------------+

10.3 TISC Registers

Register Usage
R0–R3 Argument passing / Return values
R4–R9 General purpose
SP Stack Pointer (grows down)
FP Frame Pointer
PC Program Counter
TR Ternary Flag Register (Compare results)
CR Capability Register (Current capability context)

10.4 CanonExec Format

CanonExec ::= {
    magic: "T81EXEC",
    entry: TISC_Addr,
    text: CanonRef, // Pointer to code block
    data: CanonRef, // Pointer to initial data
    caps: CanonRef, // Required capabilities manifesto
    meta: CanonRef  // Debug/Symbol info
}

Kernel verifies all hashes and asks Axion for approval before loading.


11. Architecture Diagrams (Mermaid)

11.1 Stack Diagram

flowchart TD
  HW["Hardware / Simulator"] --> TISC["TISC Engine"] --> K["Hanoi Kernel"] --> U["Userland (T81VM/T81Lang)"]

11.2 Syscall Flow

flowchart LR
  ROM["ROM"] --> Verify["CanonVerify"] --> Decomp["Decompress"] --> Seal["AxionSeal"] --> Cap["CapabilityRoot"] --> Mount["Mount CanonFS"] --> Spawn["Spawn VM"] --> Tick["Deterministic Tick"]

11.3 Syscall Flow

flowchart LR
  P1["Process"] --> K1["Kernel"] --> A["Axion"] --> K2["Kernel"] --> P2["Process"]

11.3 CanonFS Read Path

flowchart LR
  R["read(path)"] --> C["CanonFS"] --> PR["parity repair"] --> D["decompress"] --> X["decrypt"] --> O["deliver CanonBlock"]

12. Reference Implementation Scaffold — hanoi-rs


hanoi-rs/
├── Cargo.toml
├── src/
│    ├── main.cpp
│    ├── kernel/
│    │     ├── boot.cpp
│    │     ├── scheduler.cpp
│    │     ├── capability.cpp
│    │     ├── canonfs.cpp
│    │     ├── memory.cpp
│    │     ├── syscall.cpp
│    │     ├── axion.cpp
│    │     └── error.cpp
│    ├── tisc/
│    │     ├── execution.cpp
│    │     ├── registers.cpp
│    │     └── decoder.cpp
│    ├── drivers/
│    └── utils/
│          ├── base81.cpp
│          ├── tryte.cpp
│          └── parity.cpp
├── include/
│    ├── kernel/
│    │     ├── boot.hpp
│    │     ├── scheduler.hpp
│    │     ├── capability.hpp
│    │     ├── canonfs.hpp
│    │     ├── memory.hpp
│    │     ├── syscall.hpp
│    │     ├── axion.hpp
│    │     └── error.hpp
│    ├── tisc/
│    │     ├── execution.hpp
│    │     ├── registers.hpp
│    │     └── decoder.hpp
│    └── utils/
│          ├── base81.hpp
│          ├── tryte.hpp
│          └── parity.hpp
├── tests/
│    ├── boot_test.cpp
│    ├── syscall_test.cpp
│    ├── canonfs_test.cpp
│    └── axion_test.cpp
└── README.md

13. Hardware Targets (Historical Snapshot)

Target Status Notes
Hanoi Simulator Complete Cycle-accurate reference impl
QEMU HanoiVM fork Complete x86-64 host emulation
Ternary FPGA board Q1 2026 Ice40-based proof of concept
Photonic T81 Core Q3 2026 Partner R&D (Experimental)

14. Roadmap (Historical, As of 2025-11-22)


15. Final Statement (Archive Context)

With v0.1.1:

This document is retained for design history and does not supersede active normative specifications.