Skip to content

Determinism & Limits

Canontra is explicit about what it proves mathematically and where static analysis stops.

By Rice’s Theorem, no algorithm can decide whether two arbitrary programs always produce the same output for every possible input. Canontra does not claim to solve general program equivalence.

Instead, Canontra guarantees exact equivalence under a documented, finite set of normalization rules:

If F4(P1)=F4(P2), then P1 and P2 have the exact same canonical representation under Canontra’s finite rule set.\text{If } F_4(P_1) = F_4(P_2), \text{ then } P_1 \text{ and } P_2 \text{ have the exact same canonical representation under Canontra's finite rule set.}

Two programs that compute the same answer using completely different algorithms (for example, iterative vs. recursive Fibonacci) will intentionally produce different F1 and F4 fingerprints.

Canontra’s verification suite (test/Canontra/MetamorphicSpec.hs, 795 passing tests under stack test --pedantic) tests seven properties across Python, JavaScript/TypeScript, Go, and Rust:

  1. Cosmetic Invariance: Formatting, comments, docstrings, dead pass statements, and independent helper function order keep F1, F2, F_T, and F4 identical.
  2. Mutation Sensitivity: Logic edits (operator flips, constant changes, negated branch conditions, signature edits) change F1 and F4.
  3. Local Rename Invariance: Renaming local variables preserves F1, F_DF, and F4 under language-specific rules (canonicalizeAlphaModuleForLang), while F2 remains sensitive to exported function and parameter names.
  4. Guarded Algebraic Equivalence: Pure non-trapping integer/bitwise swaps (a + b vs b + a), relational flips (b > a vs a < b), and double negations (not (not x) vs x) keep F1 identical; isNonTrappingPureExpr and containsFloatOperand block unsafe reordering of side-effecting calls, trapping expressions, or IEEE-754 floats.
  5. Control-Flow Equivalence: Flipped branches and early-return guard clauses with identical execution paths produce identical F_CF digests under Lengauer-Tarjan dominator and RPO numbering.
  6. Type Contract Compatibility: Backwards-compatible extensions (such as extra optional fields) update F2 while staying subtype-compatible under F_T; breaking width (i32 vs i64) or mutability (&T vs &mut T) changes diverge F_T.
  7. Impact Reachability Soundness: computeBatchImpactSliceCSR returns every symbol reachable from modified files along directed call edges, avoiding false negatives in test selection.

Bit-Identical Results Across Operating Systems

Section titled “Bit-Identical Results Across Operating Systems”

The same repository produces identical SHA-256 hashes on Linux (x86_64/ARM64), macOS (Apple Silicon), and Windows (AMD64/ARM64):

  • Line Ending Normalization: 256-bit ByteString/SWAR/SIMD scanning (Canontra.Canonical.SIMDScan) converts \r\n to \n before parsing.
  • Unicode NFC Normalization: Identifiers normalize to Unicode Canonical Composition (NFC) via Canontra.Canonical.Unicode.
  • IEEE-754 Float Normalization: -0.0 normalizes to +0.0, and all NaN payloads normalize to a single quiet NaN bit pattern (Canontra.Canonical.Float).
  • Big-Endian Serialization: Integers, lengths, and 1-byte AST tags serialize in network byte order regardless of CPU endianness (Canontra.Canonical.Serialize).
  • Case-Folded POSIX Path Sorting: Paths normalize to / and sort deterministically across case-sensitive Linux (ext4) and case-insensitive Windows (NTFS).

To bound memory usage and prevent crashes on malformed or adversarial repositories (Canontra.Security.Path):

Resource Guard Limit Behavior When Exceeded
Maximum Single File Size 50 MB (52,428,800 bytes) File is skipped and reported
Maximum Directory Depth 64 levels Deeper directories are rejected
Symlink and Junction Loop Detection FileNodeIdentity (fniVolumeID, fniFileID) Circular links are cut before recursion overflows
Graph and Dominator Passes Finite bounded iteration Guaranteed termination on cyclic control-flow graphs
Null-Byte Path Guard \0 prohibited Rejected immediately with Exit Code 4
  • Dynamic Evaluation: Runtime features such as Python eval() / exec() / getattr(), JavaScript Proxy / dynamic import(), or Go reflect are hashed as literal AST calls; Canontra does not execute code or guess dynamic call targets.
  • Rust Macro Expansion: macro_rules! and procedural macros (#[derive(...)], attribute macros) are hashed at their surface syntax and token-tree structure rather than expanded with rustc, because Canontra never invokes external compilers.
  • Not a Taint Security Scanner: Canontra computes deterministic code fingerprints and test impact slices; it does not replace inter-procedural security taint engines such as CodeQL.