Skip to content

Objects

Wire-format specification for lema.core/v4 canonical JSON objects, expression DAGs, bounds, realizations, and receipts.

All mathematical and executable content in a Lema store is represented as immutable, content-addressed lema.core/v4 JSON objects (crates/lema-core). Source files (.lema and .lean) are parsed and elaborated only at the store boundary; once accepted, the store persists and replays source-free lema.core/v4 objects.

ConstantValue
Schema identifier"lema.core/v4"
Hash domain prefixLEMA-TYPED-CORE-v4\0 (19 bytes)
Pinned Lean kernelLean 4.34.1 (5045d0056413266e57c625dcd7c365b10e377c52)
Object ID format64 lowercase hexadecimal characters (SHA-256(domain || canonical_json))

Canonical JSON and object IDs

Every lema.core/v4 object is serialized as canonical UTF-8 JSON before hashing or storage. The validator in crates/lema-core checks canonical form strictly and never normalizes malformed input on the fly.

RuleRequirement
EncodingValid UTF-8 with no byte-order mark (BOM).
WhitespaceZero whitespace outside string literals (no spaces, tabs, or newlines).
Object keysSorted in strict lexicographic UTF-8 byte order with no duplicate keys.
StringsMinimal JSON escaping (\", \\, \b, \f, \n, \r, \t, or lowercase \u00xx for control bytes < 0x20). Printable characters above 0x1F must not be \u-escaped.
NumbersNon-negative base-10 integers only, with no leading zeros (0 is "0"), no + or - signs, no fractions, and no exponents.
Optional fieldsOmitted entirely when empty or absent rather than set to null or [], except where an array is required by the object kind.

To compute an object’s 64-hex-character ID:

id = hex_lower(SHA-256("LEMA-TYPED-CORE-v4\0" || canonical_json_bytes))

The conformance test suite in crates/lema-core enforces these invariants across golden test groups R1 through R21 (structural and typing rejections), S1 through S4 (satisfaction and realization checks), and D1 through D3 (hash domain and canonical serialization vectors).


Bounds

To keep kernel replay and store validation bounded, crates/lema-core enforces hard structural limits on every lema.core/v4 object before the Lean kernel is invoked.

ParameterMaximum limitNotes
Serialized canonical JSON size1,048,576 bytes (1 MiB)Per individual lema.core/v4 object.
Expression DAG nodes (nodes array)65,536 nodesIndexed 0 .. nodes.len() - 1.
Universe level DAG nodes (levels array)1,024 nodesIndexed 0 .. levels.len() - 1.
Universe parameter names (level_params)32 parametersDistinct valid identifiers.
Object references (refs array)1,024 entriesSorted by referenced object ID.
Template slots (slots array)256 slotsUsed by template objects.
String literal length (string node)65,536 UTF-8 bytesPer string node in the expression DAG.
Natural literal length (nat node)1,024 decimal digitsBase-10 string representation.
Record fields (fields array)256 fieldsPer record object.
Inductive constructors (constructors array)256 constructorsPer family object.
Inductive parameters (num_params)64 parametersPer family object.
Inductive indices (num_indices)64 indicesPer family object.

Object kinds

Every lema.core/v4 object carries "schema": "lema.core/v4" and a "kind" field selecting one of nine object kinds.

KindPurposeKernel replay behavior
namespaceHierarchical name prefix (parent?, segment).Validated structurally in Rust; forms canonical names for declarations and externals.
externalTrusted primitive or Lean Init constant (namespace, name, level_params, type, kind).Verified against the pinned Lean 4.34.1 environment and allowed primitive table.
statementProposition or type signature (level_params, type).Checked that type is a well-typed Sort u (Prop or Type u) in the kernel.
templateParameterized proposition or type with typed holes (slots, level_params, type).Checked by extending the local context with slots and verifying type.
proofProof term discharging a statement (statement, level_params, value, axioms).Kernel checks value : statement.type and verifies the transitive axiom footprint equals axioms.
satisfactionWitness that an implementation satisfies a template (template, level_params, fillings, realizations?, proof, axioms).Substitutes fillings into template.slots, checks realizations, and verifies proof establishes the instantiated statement.
declarationNamed definition or abbreviation (namespace?, name, level_params, type, value, hints, safety).Kernel type-checks value : type and adds the constant (with reducibility hints) to the replay environment. Single self-recursive definitions elaborated via well-founded recursion are reconstructed as whole units.
recordSingle-constructor structure type (namespace, name, level_params, num_params, type, constructor, fields).Kernel checks the inductive structure declaration and generates projections and recursors.
familySingle inductive type family, optionally indexed (namespace, name, level_params, num_params, num_indices, type, constructors).Kernel checks strict positivity, universe constraints, and constructor types for single (non-mutual, non-nested) inductive families.

Expression and universe DAG encoding

Types and terms inside lema.core/v4 objects are encoded as flat, bottom-up directed acyclic graphs (DAGs). Within a nodes array (or levels array), a node at index i may only reference child indices j < i. This invariant guarantees acyclicity in a single linear pass without recursion.

Universe level nodes (levels)

TagFieldsMeaning
"zero"NoneUniverse 0 (Prop).
"succ""of": <level_idx>u + 1.
"max""lhs": <level_idx>, "rhs": <level_idx>max u v.
"imax""lhs": <level_idx>, "rhs": <level_idx>Impredicative maximum imax u v (0 if v = 0, else max u v).
"param""index": <u32>Reference to level_params[index].

Expression nodes (nodes)

TagFieldsMeaning
"bvar""de_bruijn": <u32>Bound variable with 0-based de Bruijn index.
"sort""level": <level_idx>Sort u (Prop when u = 0, Type (u - 1) when u > 0).
"const""ref": <ref_idx>, "levels": [<level_idx>, ...]Reference to refs[ref] instantiated at universe levels.
"app""fn": <node_idx>, "arg": <node_idx>Function application fn arg.
"lam""binder_info": <info>, "domain": <node_idx>, "body": <node_idx>Lambda abstraction fun (x : domain) => body.
"forall""binder_info": <info>, "domain": <node_idx>, "body": <node_idx>Dependent arrow (x : domain) -> body.
"let""domain": <node_idx>, "value": <node_idx>, "body": <node_idx>Local binding let x : domain := value; body.
"proj""ref": <ref_idx>, "field": <u32>, "struct": <node_idx>Structure projection of field field from record type refs[ref].
"nat""value": "<digits>"Kernel natural number literal.
"string""value": "<utf8>"Kernel UTF-8 string literal.
"slot""index": <u32>Template hole reference slots[index] (valid only inside template objects).

Valid "binder_info" strings are "default", "implicit", "strict_implicit", and "inst_implicit".


References and realizations

Objects reference other objects through their "refs" array. Every entry in "refs" binds a referenced object ID and its expected kind ("declaration", "record", "family", "external", or "inductive_member" for constructors and recursors such as Nat.zero or Eq.rec).

Realizations

When a theorem or contract refers to an interface projection (such as a contract type’s carrier or operation), a satisfaction object or a lema.contract/v1 selection record can pin how abstract projections map to concrete declarations via a "realizations" array:

JSON
"realizations": [
  {
    "from": "3f9a...c102",
    "to": "8b14...e77a"
  }
]

During acceptance and witness verification (Store::check_witness), the store verifies that every realization mapping is type-compatible and that the witness proof discharges the target statement after substituting the realized declarations.

Example lema.core/v4 statement and proof

JSON
{
  "kind": "statement",
  "level_params": [],
  "levels": [
    {"tag": "zero"}
  ],
  "nodes": [
    {"level": 0, "tag": "sort"},
    {"de_bruijn": 0, "tag": "bvar"},
    {"binder_info": "default", "body": 1, "domain": 0, "tag": "forall"},
    {"de_bruijn": 1, "tag": "bvar"},
    {"de_bruijn": 1, "tag": "bvar"},
    {"binder_info": "default", "body": 3, "domain": 4, "tag": "forall"}
  ],
  "refs": [],
  "schema": "lema.core/v4",
  "type": 5
}

In this statement (∀ (P : Prop), P → P), node 0 is Prop (Sort 0), node 5 is the root forall expression, and no external references or axioms are required.


Receipts and acceptance

An object is accepted into the store only after both structural validation (crates/lema-core) and kernel replay (crates/lema-lean-check) succeed within the store’s axiom policy.

When acceptance succeeds, the store writes the canonical object bytes and records a verification receipt binding:

  • The accepted object’s 64-hex-character ID and kind.
  • The transitive axiom footprint reported by the kernel (axioms: subset of propext, Quot.sound, Classical.choice).
  • The pinned Lean kernel version (4.34.1) and distribution hash (DISTRIBUTION_SHA).
  • For sandboxed native calls, the runtime execution ledger call ID (CALL-result.json).

You can inspect an object’s verification receipt at any time with lema call receipts '{"id":"<object-id>"}' or re-verify the entire store from scratch using lema reverify.


Executable LemaIR code identity

Executable functions that run in the register VM (crates/lema-vm) are compiled directly from accepted declaration, record, and family objects into lema.ir/v1 (crates/lema-ir). Because LemaIR is lowered from the canonical lema.core/v4 expression DAG rather than surface syntax, two source declarations that elaborate to the same lema.core/v4 object ID always compile to identical LemaIR bytecode and carry the same content-addressed identity.

Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility