Canonical Wire & Artifacts

Architectura defines two complementary serialization contracts:

  1. Canonical Semantic Wire (archsem_core::canonical): A deterministic, serde-independent binary encoding used for content-addressed semantic fingerprints (fragment and whole-function dual fingerprints).
  2. Versioned Artifact Envelopes (archsem_core::artifact, archsem-ir, archsem-symex, archsem-conformance): Self-identifying, resource-bounded JSON/RON envelopes for runtime-loaded semantic programs, decode tables, symbolic execution reports, proof obligations, and oracle exchanges.

Canonical Binary Wire (archsem_core::canonical)

Defined normatively in CANONICAL_WIRE.md, CanonicalEncode requires every encoded struct field and enum variant to be named explicitly—adding a Rust enum variant never silently assigns a wire tag.

Primitive & Aggregate Encodings

TypeWire Format
u8, u16, u32, u64, u128, i64Fixed-width little-endian two's complement
usizeAdmitted only if it fits u64; encoded as little-endian u64 (lengths only)
bool0x00 (false) or 0x01 (true)
Byte strings & UTF-8 textu64 byte length `
Enum tagsNormative UTF-8 tag strings
Option<T>0x00 (absent) or `0x01
Wide bitvectorsu16 width `
Sequencesu64 item count `
MapsSorted lexicographically by the complete canonical bytes of each key (duplicate canonical keys rejected)

Recursive semantic-program encoding is bounded by MAX_CANONICAL_NESTING and the caller's byte limit.

Dual Fingerprints (Definition vs. Lift Instance)

archsem-ir fragments and complete Functions expose two SHA-256 canonical projections (current core canonical wire revision 2, embedded by neutral fragment schema 2.2 and neutral function schema 2.2):

ProjectionRetainedRedacted
Semantic-DefinitionWide constants, architectural choices, ordered events, unified control shape, semantic sites, origin-DAG topology, relocatable PC + displacement basis/displacement, dense first-occurrence InstructionExecutionGroup ordinals (or group-id-redacted on standalone fragments)Concrete instruction address, exact bytes, decode-context instance, direct control addresses, concrete relocatable PC base/value
Lift-InstanceEverything in definition plus specification revision, exact architecture/decode-state identity, bytes/address, decoder options, code epoch, semantic-program revision, exact InstructionExecutionGroup IDs, and concrete relocatable basesNone

[!NOTE] Schema major 1 (which embedded serde_json wire) is intentionally rejected by revision 2. Within a major version, existing tags, widths, and field orders never change; additive IR vocabulary increments the minor version (e.g., 2.1 added extract-element / insert-element; 2.2 added instruction-execution-group). Golden fixtures pin the exact canonical bytes and SHA-256 digests.

Versioned JSON & RON Artifact Envelopes

Runtime-loaded programs and decode tables cross an explicit trust boundary in archsem_core::artifact (serde feature):

  • Envelope: ArtifactEnvelope<T> carries:
    • schema: "archsem.semantic-artifact" (ARCHSEM_ARTIFACT_SCHEMA)
    • version: SchemaVersion { major: 1, minor: 0 } (ARCHSEM_ARTIFACT_VERSION)
    • kind: ArtifactKind::SemanticProgram ("semantic_program") or ArtifactKind::DecodeTable ("decode_table")
    • payload: OwnedProgram or OwnedDecodeTable
  • Loaders: load_program_json, load_program_ron, load_decode_table_json, load_decode_table_ron.
  • Fail-Closed Admission:
    1. Checks ResourceLimits::input_bytes before parsing.
    2. Rejects wrong schema, incompatible major version, and newer unsupported minor versions (never assuming unknown fields are inert).
    3. Validates the decoded payload structurally (ExecutableProgram / OwnedTableDecoder) before returning or leaking any process-lifetime state.
  • Legacy Undef Rejection: Artifacts containing removed pre-v0.2 Undef encodings are rejected at admission rather than silently mapped to Choice.

Other versioned bounded artifacts in the workspace follow the same hostile-input admission pattern:

  • archsem-symex: ExecutionReportArtifact, ConcolicExecutionArtifact, ProofObligationArtifact, InstructionValidationArtifact, InstructionCounterexampleArtifact
  • archsem-conformance: ExternalOracleRequest / ExternalOracleResponse, OracleDisagreementArtifact
  • archsem-lang / archsemc: .asemc portable semantic packages