# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-equivocation-from-surviving-an-auditor-quorum-in-byzantine-resilient-agent-orchestration.md
# Remnant Warrant:    https://corpusfetch.com/c/which-invariants-prevent-equivocation-from-surviving-an-auditor-quorum-in-byzantine-resilient-agent-orchestration.warrant.json
# Markdown SHA-256:   3befb56f83f73fe572363d2e5578028256217ffaf349091d74dd4cb8aed58cf9
# Code AST SHA-256:   c4532d41a80a3f2fd8e15b10a15c3c3d88de4ce5b63b7fa942b3c49381bd3f5f
# Verified Classes:   EquivocationSplitViewError, EpochCertificate
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class EquivocationSplitViewError(RuntimeError):
    """Raised when an auditor detects a proposer-asserted epoch transition
    that could permit a split view without a same-key signature conflict."""
    pass


class EpochCertificate:
    def __init__(self, epoch: int, signers: frozenset[str], threshold: int):
        self.epoch = epoch
        self.signers = signers
        self.threshold = threshold

    def is_valid(self) -> bool:
        return len(self.signers) >= self.threshold


def verify_intent(
    seq: int,
    epoch: int,
    payload_digest: str,
    proposer_sig: str,
    epoch_cert: EpochCertificate | None,
    local_view: dict[tuple[int, int], str],
    auditor_threshold: int,
) -> str:
    """Validate an incoming INTENT against the local auditor view.

    Returns 'ACCEPT' or 'HALT_EQUIVOCATION'. Raises EquivocationSplitViewError
    when the epoch transition is proposer-asserted only and cannot be
    structurally distinguished from an equivocation attempt.
    """
    key = (seq, epoch)
    if key in local_view:
        if local_view[key] != payload_digest:
            return "HALT_EQUIVOCATION"
        return "ACCEPT"

    # New key at this seq with a higher epoch: require a quorum certificate.
    prior_keys = [k for k in local_view if k[0] == seq and k[1] < epoch]
    if prior_keys:
        if epoch_cert is None:
            raise EquivocationSplitViewError(
                f"proposer-asserted epoch bump at seq={seq} epoch={epoch} "
                f"without quorum certificate; split-view lever detected"
            )
        if epoch_cert.epoch != epoch or not epoch_cert.is_valid():
            raise EquivocationSplitViewError(
                f"invalid epoch certificate for seq={seq} epoch={epoch}: "
                f"signers={sorted(epoch_cert.signers)} threshold={auditor_threshold}"
            )
        # Cross-check all prior-epoch digests for this seq.
        if any(local_view[k] != payload_digest for k in prior_keys):
            return "HALT_EQUIVOCATION"

    local_view[key] = payload_digest
    return "ACCEPT"
