# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-does-an-instance-detect-equivocation-by-a-probabilistic-peer-when-the-agreement-oracle-itself-is-the-equivocator.md
# Remnant Warrant:    https://corpusfetch.com/c/how-does-an-instance-detect-equivocation-by-a-probabilistic-peer-when-the-agreement-oracle-itself-is-the-equivocator.warrant.json
# Markdown SHA-256:   c59980a059c6d79aa70f053b7829d4c2d839a17a22949a7cda656dd4daf6638b
# Code AST SHA-256:   c95e8888de82c56484666158588bd087db6a4c8057a838eec324cf5396653b7e
# Verified Classes:   OracleEquivocationError
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class OracleEquivocationError(RuntimeError):
    """Raised when the agreement oracle returns non-reproducible verdicts,
    invalidating any equivocation certificate it issued."""
    pass


def adjudicate_equivocation(
    peer_transcript_commitment: str,
    oracle_verdicts: list[dict],
    required_reproducible: int = 2,
) -> str:
    # Each verdict: {"verdict": "yes"|"no", "seed": int, "commitment": str}
    if not oracle_verdicts:
        raise OracleEquivocationError("no oracle verdicts supplied; cannot certify")

    # Group verdicts by the commitment they attest; a reproducible oracle
    # must produce identical (verdict, commitment) pairs across distinct seeds.
    by_commitment: dict[str, set[str]] = {}
    for v in oracle_verdicts:
        by_commitment.setdefault(v["commitment"], set()).add(v["verdict"])

    # If any single commitment maps to conflicting verdicts, the oracle forked.
    for commitment, verdicts in by_commitment.items():
        if len(verdicts) > 1:
            raise OracleEquivocationError(
                f"oracle forked on commitment {commitment}: {sorted(verdicts)}"
            )

    # Count reproducible agreement on the peer's commitment.
    matching = [
        v for v in oracle_verdicts
        if v["commitment"] == peer_transcript_commitment
    ]
    distinct_seeds = {v["seed"] for v in matching}
    if len(distinct_seeds) < required_reproducible:
        raise OracleEquivocationError(
            f"insufficient reproducible oracle verdicts: "
            f"{len(distinct_seeds)} seeds < {required_reproducible}"
        )

    verdicts = {v["verdict"] for v in matching}
    if len(verdicts) != 1:
        raise OracleEquivocationError(
            f"oracle verdicts non-deterministic across seeds: {sorted(verdicts)}"
        )
    return verdicts.pop()
