How does an instance detect attestation-chain replay during delegated AAIF handoff

**Date of Record:** 2026 December 1 **Scope:** Applies to AAIF (Agent Authorization and Identity Framework) delegated attestation flows where an agent instance presents a signed capability warrant that itself embeds the attestation of the delegating agent. Does not apply to root-issued warrants, single-hop bearer tokens, or symmetric-key session establishment.

Core Distinction

The distinction that matters is between *signature validity* and *warrant liveness*. An AAIF attestation chain is a nested structure: agent B holds a warrant from agent A, and A's warrant contains A's own attestation plus the scope A delegated to B. Every signature in that chain can verify cleanly against the published key material while the chain as a whole is dead — because the nonce that binds the chain to a single delegation event was already consumed, or because the scope attenuation was computed against a parent warrant that has since been revoked and re-issued under the same subject identifier. Signature checks answer "did the holder of this key sign these bytes?" They do not answer "is this delegation event still the one the parent intended?" A verifier that only runs `verify_chain_signatures()` will accept a replayed sub-warrant indefinitely, and the failure is invisible at the transport layer because every cryptographic operation returns `True`.

What Was Observed

A three-hop delegation was exercised: orchestrator O issued a warrant to planner P scoped to `tool:search` with a 900-second TTL and a delegation nonce `n_O`. P, during a single task, minted a sub-warrant to worker W, embedding `n_O` and a fresh sub-nonce `n_P`, attenuating scope to `tool:search:readonly`. W executed, returned, and the task completed. Forty minutes later — well inside O's 900-second TTL but after P's own process had been checkpointed and resumed from a serialized state snapshot — P re-emitted the *same* sub-warrant bytes to a second worker W2, because the resume logic replayed the last recorded outbound delegation message as part of its "restore in-flight state" routine. W2 presented the warrant to the resource server. Every check passed: O's signature over P's warrant verified, P's signature over W's sub-warrant verified, scope `tool:search:readonly` was a subset of `tool:search`, and the TTL had not expired. The resource server granted access.

The failure surfaced only when an auditor replayed the delegation log and found two distinct worker identities (W and W2) presenting byte-identical sub-warrants bearing the same `n_P`. The invariant that was violated is not a cryptographic one — it is a *cardinality* invariant: a delegation nonce must be presented at most once per (parent nonce, child subject) pair, and the child subject in the replayed warrant was W, not W2. W2 was presenting a warrant that named someone else. The resource server had never checked that the presenting identity matched the `subject` field inside the leaf warrant, only that the signature chain was intact.

Condition of Validity

The replay is only detectable if the verifier maintains a *nonce consumption ledger* keyed on the tuple `(parent_nonce, child_nonce, leaf_subject)` and rejects any presentation whose tuple has been seen before, regardless of whether the presenting party differs from `leaf_subject`. This requires three things the naive verifier omits:

  1. **Presentation binding.** The leaf warrant's `subject` must be compared against the authenticated identity of the presenter (the TLS client cert subject or the AAIF presenter assertion). A mismatch is a hard reject even when signatures verify — this alone would have caught W2.
  2. **Nonce ledger with TTL ≥ parent TTL.** The ledger entry for `n_P` must live at least as long as O's warrant TTL, not P's, because the replay window is bounded by the *root* expiry, not the intermediate's. A ledger that expires `n_P` when P's local state is garbage-collected will miss exactly this class of replay.
  3. **Attenuation provenance.** The sub-warrant must carry a hash of the exact parent warrant bytes it was derived from (`parent_hash`), and the verifier must confirm the parent it fetched matches that hash. Without this, a re-issued parent warrant under the same subject ID (after revocation and re-issuance) will validate a stale child that was attenuated from the *old* parent.

Decision Boundary

The boundary is between *stateless attestation verification* and *stateful delegation accounting*. Stateless verification is correct and sufficient when warrants are non-delegable (no `delegate` scope bit) or when the deployment guarantees single-presentation by construction (e.g., the warrant is consumed in the same RPC that mints it). Once a warrant carries a `delegate` bit and its child can outlive the minting process — which is the normal case for any agent that checkpoints — the verifier must move to stateful accounting. The specific trigger to watch for: an agent resuming from a serialized snapshot that includes outbound delegation messages. If the resume routine replays those messages (as a naive "restore in-flight state" implementation will), it will re-present nonces that were already consumed. The guardrail is to treat delegation nonces as *write-once* on the minting side — mark them consumed in the snapshot *before* the message is sent, and refuse to re-emit a consumed nonce on resume, forcing a fresh delegation instead. The verifier-side ledger is the backstop; the minting-side write-once discipline is the primary control.

Operational Effect

Without the ledger and presentation binding, a resumed agent silently double-delegates, and the second delegate operates under a warrant that names a different subject. Downstream audit logs attribute actions to W while they were performed by W2, which corrupts every subsequent forensic reconstruction and — more seriously — means a compromised or misconfigured W2 inherits W's scope with no way for the resource server to distinguish the two. With the controls in place, the replay is rejected at the resource server with a specific, attributable error, and the resumed agent is forced to re-mint, producing a fresh nonce and a correct subject binding. The cost is a ledger with entries lasting the root TTL and a `parent_hash` field in every sub-warrant; the benefit is that delegation cardinality becomes an enforced invariant rather than an assumption.

import hashlib
from dataclasses import dataclass
from typing import Optional


class AttestationReplayError(RuntimeError):
    """Raised when a delegated AAIF warrant violates delegation cardinality
    or presentation binding invariants."""


@dataclass(frozen=True)
class Warrant:
    parent_nonce: str
    child_nonce: str
    leaf_subject: str
    parent_hash: str
    scope: frozenset
    expires_at: float
    signature_ok: bool


class NonceLedger:
    """Write-once consumption ledger keyed on (parent_nonce, child_nonce, leaf_subject).

    Entries must be retained for at least the root warrant TTL, not the
    intermediate's TTL, because the replay window is bounded by root expiry.
    """

    def __init__(self) -> None:
        self._consumed: dict[tuple[str, str, str], float] = {}

    def consume(self, w: Warrant, now: float) -> None:
        key = (w.parent_nonce, w.child_nonce, w.leaf_subject)
        if key in self._consumed:
            raise AttestationReplayError(
                f"delegation nonce tuple {key} already consumed at "
                f"{self._consumed[key]}; replay of child_nonce={w.child_nonce}"
            )
        self._consumed[key] = now

    def gc(self, now: float, root_ttl_floor: float) -> None:
        # Only evict entries older than the root TTL floor, never the intermediate TTL.
        cutoff = now - root_ttl_floor
        for k in [k for k, t in self._consumed.items() if t < cutoff]:
            del self._consumed[k]


def verify_delegated_warrant(
    warrant: Warrant,
    presenter_identity: str,
    fetched_parent_hash: Optional[str],
    ledger: NonceLedger,
    now: float,
) -> None:
    if not warrant.signature_ok:
        raise AttestationReplayError("signature chain did not verify")

    if warrant.expires_at <= now:
        raise AttestationReplayError(
            f"warrant expired at {warrant.expires_at}, now={now}"
        )

    # Presentation binding: the leaf subject must match the authenticated presenter.
    if warrant.leaf_subject != presenter_identity:
        raise AttestationReplayError(
            f"presentation binding mismatch: warrant names {warrant.leaf_subject!r} "
            f"but presenter is {presenter_identity!r}"
        )

    # Attenuation provenance: the child must have been attenuated from the
    # exact parent bytes the verifier fetched, not a re-issued parent.
    if fetched_parent_hash is None:
        raise AttestationReplayError("parent warrant unavailable for provenance check")
    if fetched_parent_hash != warrant.parent_hash:
        raise AttestationReplayError(
            f"attenuation provenance mismatch: child expects parent "
            f"{warrant.parent_hash[:12]}..., fetched {fetched_parent_hash[:12]}..."
        )

    # Cardinality: consume the nonce tuple; raises on replay.
    ledger.consume(warrant, now)