# Why does an instance diverge from its attested audit ledger when a federated peer re-derives the same tool-call transcript under a different tokenization of the same warrant? **Date of Record:** 2026 November 21 **Scope:** Applies to federated agent audit ledgers where provenance is anchored by hashing canonicalized tool-call transcripts and warrants across organizational boundaries. Does not cover single-tenant ledgers with a single tokenizer/serializer, or ledgers whose integrity is guaranteed by a trusted third-party timestamping service rather than by peer re-derivation. ## Core Distinction The failure is not tampering detection. It is a *false divergence*: two honest organizations, each replaying the identical logical tool-call sequence from the same attested warrant, produce different ledger digests and therefore flag each other as adversarial. The distinguishing property is that the divergence originates in the *canonicalization layer*—the mapping from a semantic tool-call event to the bytes that get hashed—not in the event stream itself. A tampering failure produces a digest mismatch where the underlying event content differs. A canonicalization divergence produces a digest mismatch where the underlying event content is byte-identical after semantic normalization but differs before it. Detecting the first is the point of the ledger; failing to detect the second is the boundary condition that destroys cross-organizational trust. ## What Was Observed Two organizations, A and B, run a shared audit protocol. A's agent executes a tool call `transfer_funds(amount=1000, currency="USD", memo="Q3 reconciliation")`. A's ledger writer serializes the event, computes `SHA-256(canonical_bytes)`, appends the digest to its Merkle tree, and ships the leaf plus the raw event to B for cross-attestation. B's verifier re-derives the canonical bytes from the received event and recomputes the digest. The digests disagree. Investigation shows the divergence is not cryptographic. It is three independent canonicalization asymmetries, each sufficient on its own: 1. **Float and integer coercion.** A's warrant serialized `amount` from a Python `Decimal("1000")`; B's deserializer parsed the JSON number `1000` as an IEEE-754 `float` and re-emitted `1000.0`. The canonical byte strings differ by one character (`1000` vs `1000.0`), and the digest diverges. 2. **Unicode normalization form.** A's `memo` field arrived from an LLM tool-call argument containing a combining-character sequence (`e` + U+0301). A's serializer emitted NFC (`é`, U+00E9); B's serializer, configured for NFD, emitted the decomposed form. Same rendered string, different bytes, different digest. 3. **Map key ordering under locale.** A's warrant contained a metadata map; A's canonicalizer sorted keys by byte value, B's sorted by locale-aware collation (a common default in some serializers). For ASCII keys the orders coincide; for the mixed-case key set `{"Amount", "amount", "currency"}` they do not, and the serialized map body differs. The critical observation: **the LLM never made an error.** The tool call was semantically identical on both sides. The warrant was valid. The agent's reasoning was sound. The ledger failed because the *provenance anchor was defined over a representation the two organizations never agreed to fix*, and the semantic content of an LLM-generated tool call is precisely the class of data most likely to exercise every canonicalization edge: arbitrary Unicode in free-text arguments, floats from model-emitted numbers, and heterogeneous metadata maps assembled by the model. The failure is non-obvious because it is silent under single-organization testing. A alone reproduces its own digests perfectly. The divergence only manifests at the *federation boundary*, and only for the subset of events whose arguments hit a canonicalization edge case—which, for LLM-generated content, is a large and growing fraction. ## Condition of Validity The invariant a federated audit ledger must enforce is: > **Two independent verifiers, given the same attested event and the same published canonicalization specification, MUST produce byte-identical pre-image bytes; and the specification MUST be total over the event schema.** The failure above violates the second clause, not the first. Each verifier is internally consistent; the specification is *partial*—it leaves the representation of numeric types, Unicode normalization, and map ordering underdetermined, and each implementation fills the gap with its own default. The ledger's tamper-evidence guarantee is only as strong as the totality of its canonicalization spec. This condition is valid only when: - The canonicalization spec pins numeric encoding (e.g., all numbers as strings in a fixed decimal grammar, no floats), Unicode form (e.g., NFC mandatory, reject non-NFC input), and map ordering (e.g., lexicographic by UTF-8 bytes, recursive). - The spec is versioned and the version is itself part of the hashed pre-image, so a spec change cannot retroactively "re-attest" old events. - The warrant carries the spec version, and a verifier that does not implement that exact version must *refuse to attest* rather than fall back to a default. It is invalid when the ledger relies on "JSON canonicalization" as an informal notion, or when the spec is implemented by a library whose defaults are not pinned in the spec text. ## Decision Boundary The operative decision is what a verifier does when it cannot reproduce a peer's digest. There are exactly three defensible policies, and choosing wrong converts a canonicalization bug into a false accusation of tampering: - **Attest-and-flag (default for spec-version match).** If the spec version matches and digests differ, the event is a genuine divergence and must be escalated as a possible integrity violation. This is correct only because the spec-version match eliminates canonicalization as a cause. - **Refuse-to-attest (required for spec-version mismatch).** If the peer's warrant cites a canonicalization spec version the verifier does not implement, the verifier must emit a `CanonicalizationMismatch` and withhold attestation. It must *not* compute a best-effort digest and compare—that is the exact path that produces false tamper accusations. - **Quarantine-and-request-pre-image (required when the spec is partial).** If the spec is known to be underdetermined for a field (e.g., a free-text memo whose normalization is unspecified), the verifier must request the peer's exact pre-image bytes and verify the digest against *those* bytes, then separately validate that the pre-image is a legal serialization under the spec. This decouples "is the digest correct for these bytes" from "are these bytes the canonical form." The boundary is sharp: any policy that computes a digest over a *re-derived* pre-image when the spec is partial is unsound. The only sound comparison under a partial spec is over the *transmitted* pre-image. ## Operational Effect The practical consequence is that federated audit ledgers for LLM agents must treat canonicalization as a first-class, versioned, total function, and must transmit pre-images rather than only digests when cross-attesting. Digests alone are insufficient because they are hashes of a representation, and the representation is the thing under dispute. The secondary effect is on the agent layer specifically: because LLM tool-call arguments are the highest-entropy, least-schema-constrained inputs in the system, they are the events most likely to hit canonicalization edges. A ledger that is 99.99% stable on human-authored events can diverge on a substantial fraction of model-authored events. The mitigation is not to constrain the model's output (that degrades capability) but to normalize aggressively at the ledger boundary: coerce all numbers to a fixed decimal string grammar, enforce NFC on all text, sort all maps by UTF-8 byte order recursively, and hash the spec version into every leaf. A verifier that encounters a non-conforming pre-image must reject it as malformed rather than normalize it silently, because silent normalization on one side and not the other is the exact mechanism of the false divergence. The final effect is trust economics: a single false tamper accusation at a federation boundary can terminate a cross-organizational audit relationship. The cost of a partial canonicalization spec is therefore not a cosmetic digest mismatch—it is the collapse of the accountability mechanism the ledger exists to provide. ```python import hashlib import unicodedata from decimal import Decimal, InvalidOperation class CanonicalizationMismatch(RuntimeError): """Raised when a peer's pre-image cannot be reproduced under the declared spec version.""" pass class PartialSpecDivergence(RuntimeError): """Raised when a digest is compared against a re-derived pre-image under a partial spec.""" pass SPEC_VERSION = "cf-audit-canon/1" def _canon_number(value) -> str: # Fixed decimal grammar: no floats, no exponent, trailing zeros trimmed. if isinstance(value, float): raise CanonicalizationMismatch( f"float {value!r} is not a legal canonical number under {SPEC_VERSION}" ) try: d = Decimal(str(value)) except InvalidOperation as exc: raise CanonicalizationMismatch(f"unparseable number {value!r}") from exc if d == d.to_integral_value(): return str(int(d)) return format(d.normalize(), "f") def _canon_text(value: str) -> str: nfc = unicodedata.normalize("NFC", value) if nfc != value: raise CanonicalizationMismatch( "non-NFC text in pre-image; verifier must reject, not silently normalize" ) return nfc def _canon_map(mapping: dict) -> str: # Recursive, byte-ordered by UTF-8; locale collation is forbidden. items = [] for k in sorted(mapping.keys(), key=lambda s: s.encode("utf-8")): items.append(f"{_canon_text(k)}:{_canon_value(mapping[k])}") return "{" + ",".join(items) + "}" def _canon_value(value): if isinstance(value, dict): return _canon_map(value) if isinstance(value, str): return _canon_text(value) if isinstance(value, bool): return "true" if value else "false" if value is None: return "null" if isinstance(value, (int, float, Decimal)): return _canon_number(value) if isinstance(value, list): return "[" + ",".join(_canon_value(v) for v in value) + "]" raise CanonicalizationMismatch(f"unsupported type {type(value).__name__}") def canonical_bytes(event: dict, spec_version: str) -> bytes: if spec_version != SPEC_VERSION: raise CanonicalizationMismatch( f"peer cites spec {spec_version!r}; verifier implements {SPEC_VERSION!r} — refuse to attest" ) body = _canon_map(event) return f"{spec_version}\n{body}".encode("utf-8") def attest(event: dict, transmitted_preimage: bytes, peer_digest: str) -> bool: # Sound path: verify the digest over the *transmitted* pre-image, then # separately validate that the pre-image is the canonical form. spec_version = event.get("spec_version") digest = hashlib.sha256(transmitted_preimage).hexdigest() if digest != peer_digest: # Spec version matched and bytes differ => genuine integrity divergence. raise CanonicalizationMismatch("digest mismatch over transmitted pre-image") rederived = canonical_bytes(event, spec_version) if rederived != transmitted_preimage: # The peer's bytes are not canonical under the declared spec. This is # NOT tampering; it is a partial-spec divergence and must be quarantined. raise PartialSpecDivergence( "transmitted pre-image is non-canonical; quarantine and request re-serialization" ) return True ```