# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-federated-quorum-slice-s-equivocation-proof-as-authoritative-across-org-boundaries.md
# Remnant Warrant:    https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-federated-quorum-slice-s-equivocation-proof-as-authoritative-across-org-boundaries.warrant.json
# Markdown SHA-256:   e19341ea95e4554014bda32c28694111bc026422628cc08451f16f522648be12
# Code AST SHA-256:   05ff77a08e1abfd6f4837c0c629da5a448cd8199957b47b19e193d37281a1ba1
# Verified Classes:   CrossSliceEquivocationError
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class CrossSliceEquivocationError(RuntimeError):
    """Raised when an equivocation verdict is propagated across a slice
    boundary that cannot locally verify it under its own fault threshold."""
    pass


def verify_slash_portable(
    proof: dict,            # {"sigma1", "sigma2", "witness_set", "epoch"}
    src_slice: dict,        # {"f": int, "conflict_key": tuple, "validators": set}
    dst_slice: dict,        # {"f": int, "conflict_key": tuple, "validators": set,
                            #  "accepts_delegated_slash": bool, "epoch_window": tuple}
) -> str:
    if src_slice["conflict_key"] != dst_slice["conflict_key"]:
        raise CrossSliceEquivocationError(
            f"conflict-key mismatch: src={src_slice['conflict_key']} "
            f"dst={dst_slice['conflict_key']}; proof is not a proof in dst"
        )

    if not (dst_slice["epoch_window"][0] <= proof["epoch"] <= dst_slice["epoch_window"][1]):
        raise CrossSliceEquivocationError(
            f"proof epoch {proof['epoch']} outside dst window {dst_slice['epoch_window']}"
        )

    overlap = proof["witness_set"] & dst_slice["validators"]
    required = dst_slice["f"] + 1

    if len(proof["witness_set"]) < required:
        raise CrossSliceEquivocationError(
            f"witness set size {len(proof['witness_set'])} < f_dst+1={required}: "
            f"single-validator fault, not a federated proof"
        )

    if len(overlap) >= required:
        return "SLASHED"

    if dst_slice["accepts_delegated_slash"] and src_slice["f"] >= dst_slice["f"]:
        return "SLASHED_DELEGATED"

    # The dangerous case: proof is real in src, unverifiable in dst.
    # Must NOT return CLEAN (lets equivocator run) and must NOT return
    # SLASHED (quarantines on unverifiable evidence). Escalate.
    raise CrossSliceEquivocationError(
        f"insufficient witness overlap {len(overlap)}/{required} in dst slice; "
        f"proof valid in src but unverifiable in dst — escalate to joint audit, "
        f"do not propagate verdict"
    )
