# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-quorum-certified-plan-commitment-from-collapsing-when-a-byzantine-agent-equivocates-across-overlapping-quorum-slices.md
# Remnant Warrant:    https://corpusfetch.com/c/which-invariants-prevent-quorum-certified-plan-commitment-from-collapsing-when-a-byzantine-agent-equivocates-across-overlapping-quorum-slices.warrant.json
# Markdown SHA-256:   a4691365036bc695d2a66c0ebe7c9af00ad63d886acc9dfbf1d245557b2c3fbe
# Code AST SHA-256:   909251b5f8d0b562d52b6632d7098462b0af5f3c29bc4567c600dd4b3434b7d2
# Verified Classes:   QuorumIntersectionViolation
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class QuorumIntersectionViolation(RuntimeError):
    """Raised when two conflicting plan-commit certificates share no honest signer."""
    pass


def verify_cross_slice_commit(
    cert_a: dict,
    cert_b: dict,
    slice_graph: dict,
    byzantine_ids: set,
    f_global: int,
) -> None:
    """
    cert_* = {"plan_hash": str, "signers": set[str], "slice": str}
    slice_graph[slice] = {"members": set, "f": int, "overlap_with": {slice: int}}
    Enforces: any two certificates that could co-commit shared state must
    intersect in >= f_global + 1 honest signers.
    """
    if cert_a["plan_hash"] == cert_b["plan_hash"]:
        return  # no conflict, nothing to check

    s_a, s_b = cert_a["slice"], cert_b["slice"]
    if s_b not in slice_graph[s_a].get("overlap_with", {}):
        return  # slices never co-commit shared state; per-slice cert suffices

    required = f_global + 1
    intersection = cert_a["signers"] & cert_b["signers"]
    honest_intersection = intersection - byzantine_ids

    if len(honest_intersection) < required:
        # The equivocation is now provable: the common signers of two
        # conflicting certs are, by definition, equivocators.
        equivocators = intersection
        raise QuorumIntersectionViolation(
            f"conflicting certs for {cert_a['plan_hash']!r} vs {cert_b['plan_hash']!r} "
            f"across slices {s_a!r}/{s_b!r}: honest intersection="
            f"{len(honest_intersection)} < required={required}; "
            f"equivocation proof against {sorted(equivocators)}. "
            f"Refusing to promote either certificate; retry with widened overlap."
        )
