Skip to content

3.4 Topology Digest

Raul Cardenas Montoya edited this page Sep 19, 2026 · 1 revision

Topology Digest

Relevant source files

The following files were used as context for generating this wiki page:

Purpose and Scope

The topology digest subsystem provides a versioned, deterministic cryptographic fingerprint (TopologyDigest) for the logical graph structure represented by SynapticGraph src/topology/mod.rs:5-7. Replay synchronization, checkpoint provenance verification, and cross-runtime consistency checks require a stable identifier of the logical graph topology that remains invariant across CSR (Compressed Sparse Row) insertion orders, internal hash-map iteration sequences, memory pointer layouts, host architectures, and JSON serialization formatting src/topology/digest.rs:5-8.

Sources: src/topology/mod.rs:3-8(), src/topology/digest.rs:3-8()


Schema v1 Specification & Preimage Construction

Schema v1 defines the printable manifest string format and the canonical byte layout fed into the SHA-256 hash function src/topology/digest.rs:9-35.

Printable String Format

The printable representation conforms to the following grammar:

synaptic-wiring.topology.digest.v1:sha256:<64 lowercase hex chars>

Where:

Preimage Byte Layout

The cryptographic preimage constructed prior to hashing consists of the following sequential components:

  1. Domain Separator: [TOPOLOGY_DIGEST_DOMAIN] encoded as UTF-8 bytes, immediately terminated by a NUL byte (DOMAIN_TERMINATOR, 0x00) to prevent prefix collisions src/topology/digest.rs:17-20.
  2. Schema Version: [TOPOLOGY_DIGEST_SCHEMA_VERSION] (u16) encoded in little-endian format src/topology/digest.rs:21.
  3. Neuron Count: Total number of neurons in the graph (u64) encoded in little-endian format src/topology/digest.rs:22.
  4. Edge Count: Total number of edges in the graph (u64) encoded in little-endian format src/topology/digest.rs:23.
  5. Sorted Edge Records: Exactly 23 bytes per logical edge, sorted in strict canonical order (source, target, delay, polarity_tag, weight_bits) src/topology/digest.rs:24-33 where:

Diagram: Data Flow from SynapticGraph to TopologyDigest

graph TD
    A["SynapticGraph"] -->|calls| B["SynapticGraph::topology_digest"]
    B -->|invokes| C["canonical_edges"]
    C -->|sorts canonical order| D["Edge Records: source, target, delay, polarity, weight_bits"]
    D -->|feeds preimage| E["hash_v1"]
    E -->|uses| F["sha2::Sha256"]
    F -->|produces| G["TopologyDigest"]
Loading

Sources: src/topology/digest.rs:9-35(), src/topology/digest.rs:54-92(), src/topology/digest.rs:190-198(), src/topology/mod.rs:5-22()


Float Canonicalization & Invariant Rules

To guarantee cross-platform determinism, floating-point weights are canonicalized via their IEEE 754 binary bit patterns (f32::to_bits) rather than numerical evaluation src/topology/digest.rs:37-43.

Invariant Checks

Sources: src/topology/digest.rs:37-43(), tests/topology_digest.rs:127-149()


Key Types, Functions, and Serialization

The topology digest module defines core structs and traits facilitating inspection, parsing, and serialization src/topology/digest.rs:68-189.

Core Structs and Methods

Parsing and Serialization Workflow

TopologyDigest implements fmt::Display, FromStr, Serialize, and Deserialize to allow transparent embedding in JSON checkpoints and manifests src/topology/digest.rs:125-168.

Diagram: Parsing and Validation Workflow

graph TD
    H["String / JSON Manifest"] -->|parse via FromStr / Deserialize| I["TopologyDigest::from_str"]
    I -->|splits manifest| J["split_manifest"]
    J -->|validates domain and algorithm| K{"Valid Format?"}
    K -->|No| L["TopologyDigestParseError"]
    K -->|Yes| M["hex_decode_sha256"]
    M -->|returns| G["TopologyDigest"]
Loading

Sources: src/topology/digest.rs:68-189(), src/topology/digest.rs:190-198()


Determinism Guarantees and Test Suite

The test harness in tests/topology_digest.rs validates insertion-order permutation invariance, golden fixtures, signed zero distinction, and invalid float rejections tests/topology_digest.rs:3-165.

Verification Suites

Sources: tests/topology_digest.rs:1-165()

Clone this wiki locally