Skip to content

9+4 Fingerprint Tiers

Canontra computes 9 separate SHA-256 fingerprints for each file (F0 through F4), plus 4 repository-wide fingerprints (F_R, F_WCG, F_WDF, F_W4) that capture cross-file structure. Each fingerprint isolates one aspect of the code so downstream tools only react to the kind of change they care about.

TierJSON FieldHaskell AccessorWhat It HashesUnchanged When
F0sourcef0SourceExact raw bytes of the fileNothing (behaves like sha256sum or git hash-object)
F1structuralf1StructuralCleaned syntax tree in CanonicalProgram (trivia removed, local variables renamed via canonicalizeAlphaModuleForLang, safe math reordered, independent pure functions sorted)Comments, whitespace, CRLF/LF line endings, docstrings, local variable renames, pure helper order, and pure integer a + b vs b + a
F2declarationf2DeclarationPublic function, class, interface, and trait names, parameter lists, default values, and return annotationsPrivate helper edits, changes inside function bodies, and local variable renames
F3dependencyf3DependencySorted list of external imports, package names, and import aliasesReordering import statements, formatting changes, and body edits
F_CGcall_graphfCGCallGraphWhich functions call which functions inside the file, including recursive calls and call countsExpression math changes, formatting, and local variable names
F_CFcontrol_flowfCFControlFlowCanonical branch and loop pathways ordered by Lengauer-Tarjan dominators (computeDominators), dominance frontiers, and Reverse Post-Order (RPO)Flipped conditions (if (!c) B else A), guard-clause early returns, and dead code after return
F_DFdata_flowfDFDataFlowVariable assignment-to-use chains (SSA def-use chains) using normalized @v<d>.<o> local namesLocal variable renames, formatting, and comments
F_Ttype_contractfTTypeContractPublic type shapes: exact scalar widths (i32 vs u64), Mutability (&T vs &mut T), ordered TypeTuple, flattened unions/intersections, positional generics (α0, α1), sorted record fieldsGeneric parameter renames (<K, V> vs <Key, Val>), union order, and record field order
F4compositef4CompositeCombined hash SHA-256(F1 || F2 || F3 || F_CG || F_CF || F_DF || F_T)All formatting/comment trivia, local variable renames, safe math swaps, and flipped branch shapes

The composite digest F4F_4 intentionally excludes F0F_0 (raw source bytes) and hashes only the seven normalized semantic digests in fixed length-prefixed big-endian order:

F4=SHA-256 ⁣(F1∥F2∥F3∥FCG∥FCF∥FDF∥FT)F_4 = \text{SHA-256}\!\left(F_1 \parallel F_2 \parallel F_3 \parallel F_{CG} \parallel F_{CF} \parallel F_{DF} \parallel F_T\right)

Because F0F_0 is left out, edits that change file bytes without changing any semantic tier keep F4F_4 bit-identical across runs and operating systems.

In v0.4.0, F_T tracks ABI-level details so breaking type edits never collide with safe edits:

  • Exact Scalar Widths: Fixed-width primitives (i32 vs u64, f32 vs f64) produce different hashes.
  • Mutability Qualifiers (Mutability): Distinguishes read-only vs. mutable borrows and references (&T vs &mut T).
  • Ordered Tuples (TypeTuple): Keeps positional tuple order ((A, B) ≠\neq (B, A)), while still flattening and sorting commutative unions (makeUnion) and intersections (makeIntersection).

Running canontra fp <file> --json outputs a Manifest object whose fingerprints field matches Canontra.Types.FingerprintBundle:

{
"file": "src/service.py",
"language": "python",
"engine_version": "0.4.0",
"fingerprints": {
"source": "8b1a9953c4611296...",
"structural": "4c2d01a8e7f93310...",
"declaration": "91e4f0c27b8d4e15...",
"dependency": "3a7c8d9e1f02b4c5...",
"call_graph": "7f12a3b4c5d6e708...",
"control_flow": "19e8d7c6b5a49382...",
"data_flow": "605f4e3d2c1b0a9f...",
"type_contract": "c1d2e3f4a5b60718...",
"composite": "f4e3d2c1b0a9f8e7..."
}
}

Whole-Repository Tiers (F_R, F_WCG, F_WDF, F_W4)

Section titled “Whole-Repository Tiers (F_R, F_WCG, F_WDF, F_W4)”
TierNameUnderlying Data StructureScope and Behavior
F_RRepository Merkle RootSorted POSIX file tree hash combining every module composite F4 digest and folder structureIdentical across Windows NTFS, macOS APFS, and Linux ext4 for the same semantic repository
F_WCGWhole-Repository Call GraphCompact CSR graph (csrRowOffsets, csrColIndices, csrEdgeFlags) merging Go package directories and resolving JS/TS barrel exportsTracks cross-file function calls, strongly connected components, and CNTR\x07 summary synthesis
F_WDFWhole-Repository Data FlowCross-file variable flow edges built from CSR graphs and cached FileGraphSummary payloadsTracks how values pass across module boundaries and callers
F_W4Composite Workspace IdentityCombined root hash of F_R, F_WCG, and F_WDFSingle 64-character SHA-256 fingerprint for the entire multi-language repository

Composite-Aware F_R and Cross-File Resolution

Section titled “Composite-Aware F_R and Cross-File Resolution”
  • Composite F4 Folding: In v0.4.0, repository root F_R folds each module’s composite F4 digest along with normalized case-folded POSIX paths. Any semantic, control-flow, data-flow, or type-contract change in any indexed file updates F_R.
  • Package and Barrel Resolution: F_WCG and F_WDF merge Go package directory symbols and resolve TypeScript/JavaScript barrel re-exports, eliminating false cross-file call edges based on matching names alone.