interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / spec / quantities-and-modular.md

116 lines · 8627 bytes Raw Blame History Source

SPECIFICATION: Distinct Semantic Domains for Bounded Quantities and Modular Words

Document ID:     SPEC-OMEGA-QUANTITY-DOMAINS
Classification:  Sovereign Semantic Specification
Target Substrate: Typed AST, Seeded Compiler (seed/omc), and Semantic Value Graphs
Status:          PROPOSED (Refs #756, Essay Priority 3)

1. Problem and Purpose

Omega distinguishes ownership and certain bounds checks, but its integer types (ulong, uint, ushort, uchar) implement modular arithmetic modulo $2^w$ ($w \in {64, 32, 16, 8}$).

Modular arithmetic with wrapping is necessary and intentional for cryptography:

However, treating resource counters, buffer lengths, object offsets, memory quotas, and loop bounds as wrapping modular words is hazardous:

This specification defines the separation of Omega's numeric types into distinct semantic domains, specifies the conversion and arithmetic rules, establishes the slice validation invariant, and guarantees the preservation of modular crypto.


2. Distinct Semantic Domains

Omega recognizes three distinct numeric and resource domains:

2.1 Modular Words (ulong, uint, ushort, uchar)

2.2 Bounded Quantities (qty)

2.3 Object-Indexed Offsets and Slices (qoff, qslice)


3. Conversion Discipline

3.1 Prohibition of Implicit Conversions

There are no implicit conversions between modular words and bounded quantities:

  1. An operation combining a modular word and a quantity (e.g. add ulong_val qty_val) is rejected at compile time (error 7).
  2. Assigning a modular word to a quantity variable, or a quantity to a modular word variable, is rejected at compile time (error 7).
  3. Passing a modular word to a parameter declared as qty, or a quantity to a parameter declared as ulong, is rejected at compile time (error 7).
  4. Returning a modular word from a function declaring a qty return type (or vice versa) is rejected at compile time (error 7).

3.2 Explicit Checked Ingress and Egress

  1. Modular to Quantity (qty(w)): Explicit conversion from an unsigned modular word w to qty is valid across the full unsigned 64-bit range. Converting a signed integer to qty requires checking that the sign bit is clear; a negative value traps with trap 5 (out of range) or returns a declared error status before any assignment.
  2. Quantity to Modular (ulong(q)): Explicit conversion from qty to ulong is permitted to mark intentional transition into a modular computation domain (e.g., feeding a message length into a SHA padding block).
  3. Narrowing Conversions: Converting qty to a narrower scalar (such as uint or uchar) requires checking that no higher-order bits are set. If q >= 2^w, the conversion traps (trap 5) or returns a declared refusal before effects.

The seeded syntax is prefix conversion (q = qty w, w = ulong q). Integer literals settle to qty in a quantity context, including add q 1 and add q qty 1; const ONE qty 1 is an integer quantity constant. Floating literals, floating values, and fsqrt, fabs, fmin, or fmax on quantities are refused with error 7, not interpreted as quantity bit patterns. Permanent host regressions are in tests/quantity/ and seed/qualification/om2/baseline/language.cases.


4. Checked Arithmetic and Slice Invariants

4.1 Addition and Multiplication

4.2 Slices and Subviews

To construct a slice or view of length $k$ at offset $o$ from an object of length $L$:

  1. The check $o \le L$ is evaluated first. If false, execution traps immediately (trap 3: index/bounds violation).
  2. The remaining capacity $R = L - o$ is computed. Because $o \le L$, $R$ cannot underflow.
  3. The check $k \le R$ (i.e. $k \le L - o$) is evaluated. If false, execution traps immediately (trap 3).
  4. Prohibition of Wrapped Bounds Check: The check MUST NOT be implemented as $o + k \le L$. In 64-bit modular arithmetic, if $o = 2^{64} - 2$ and $k = 4$, $o + k = 2$, which trivially satisfies $2 \le L$, leading to severe memory safety violations. Evaluating $o \le L$ followed by $k \le L - o$ prevents arithmetic wrapping entirely.

5. Preservation of Modular Cryptography

Nothing in this specification alters the semantics of existing modular types:


6. Implementation Status and Roadmap