# 13. Contracts and Unsafe Boundaries ## 1. Contracts Functions may declare preconditions and postconditions. Types/modules may declare invariants. ```aji fn append(log: mut, data: slice) -> Result requires { len(data) <= 16 MiB } ensures { result.is_ok() => log.offset >= old(log.offset) } effects [fs.write] { ... } ``` The verifier reports each contract as one of: ```text PROVEN_STATICALLY CHECKED_AT_RUNTIME ASSUMED_UNSAFE UNPROVEN ``` A high-assurance profile may reject runtime-only or unproven obligations. ## 2. Assertions and guards `assert condition` is a runtime-visible correctness check unless statically proven. Failure traps. `guard condition` both checks the condition as required by its form and introduces a path fact to the verifier. `assume condition` is unsafe-only because it introduces a proof fact without checking it. ## 3. Unsafe Unsafe operations occur only in an explicit `unsafe` block/function/module. Unsafe does not disable the type system globally. It enables specific operations whose safety obligations cannot be established by the normal verifier. Typical unsafe facilities: ```text addr dereference pointer arithmetic FFI direct syscalls inline assembly manual Send/Share declarations custom synchronization primitives ``` ## 4. Unsafe proof obligations Unsafe code must document applicable obligations, including: - valid allocation/provenance; - alignment; - initialization; - lifetime; - aliasing; - synchronization; - ABI assumptions; - resource-state assumptions. Violation of an unsafe precondition may cause Undefined Aji Behavior. ## 5. Unsafe dependency report The toolchain should produce a machine-readable report containing: ```text application unsafe blocks unsafe standard-library modules raw dereference sites inline assembly sites FFI boundaries manual Send/Share declarations ``` This report is part of the audit surface for agent-generated systems.