# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-refuse-to-sign-a-slashing-warrant-equivocation-proof-decay-under-partial-synchrony.md
# Remnant Warrant:    https://corpusfetch.com/c/when-must-an-instance-refuse-to-sign-a-slashing-warrant-equivocation-proof-decay-under-partial-synchrony.warrant.json
# Markdown SHA-256:   5d612e6227d5f8bf4fe2a1750ce5062d89f1e6933670e4967ca5eacee8cf3e92
# Code AST SHA-256:   02e540fb86128d31c939dc9410099c07d66d020d62fcd9d1e3497ed34db4a35f
# Verified Classes:   UnboundWarrantError
# Defensive Guards:   6 fail-closed invariants (zero external deps)

class UnboundWarrantError(RuntimeError):
    """Raised when a slashing warrant lacks two independently-sourced,
    same-epoch, same-slot conflicting artifacts."""
    pass


def verify_slashing_warrant(warrant, artifact_store, min_independent_sources=1):
    """
    Verify a slashing warrant under partial-synchrony assumptions.

    A warrant is bound (slashable) iff:
      - it cites exactly two artifacts (sigma, message),
      - both signatures verify under the accused's registered key,
      - both artifacts share the same logical epoch AND the same slot
        (task_id, baton_index),
      - the payloads differ (genuine conflict, not duplicate delivery),
      - the verifier can independently source both artifacts from at least
        `min_independent_sources` origin(s) other than the warrant originator.

    Anything else -- notably one artifact plus a timeout, or two artifacts
    at adjacent epochs (recovery duplication) -- raises UnboundWarrantError.
    """
    artifacts = warrant.get("artifacts", [])
    if len(artifacts) != 2:
        raise UnboundWarrantError(
            f"warrant cites {len(artifacts)} artifact(s); need exactly 2 "
            f"(one artifact + timeout is not evidence under partial synchrony)"
        )

    a1, a2 = artifacts
    if not (verify_sig(a1, warrant["accused_key"]) and
            verify_sig(a2, warrant["accused_key"])):
        raise UnboundWarrantError("artifact signature verification failed")

    if a1["epoch"] != a2["epoch"]:
        raise UnboundWarrantError(
            f"epoch mismatch {a1['epoch']} vs {a2['epoch']}: "
            f"adjacent-epoch conflict is recovery_duplication, not equivocation"
        )

    if a1["slot"] != a2["slot"]:
        raise UnboundWarrantError("slot mismatch: artifacts are not same-slot")

    if a1["payload"] == a2["payload"]:
        raise UnboundWarrantError("identical payloads: not a conflict")

    originator = warrant["originator"]
    for art in (a1, a2):
        sources = {
            s for s in artifact_store.sources(art["hash"])
            if s != originator
        }
        if len(sources) < min_independent_sources:
            raise UnboundWarrantError(
                f"artifact {art['hash'][:12]} not independently sourced; "
                f"only originator {originator} holds it -- signature "
                f"aggregation is not evidence aggregation"
            )

    return {"bound": True, "slash": True, "epoch": a1["epoch"]}
