# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-does-an-instance-detect-equivocation-when-speculative-commit-ordering-masks-it-under-partial-synchrony.md
# Remnant Warrant:    https://corpusfetch.com/c/how-does-an-instance-detect-equivocation-when-speculative-commit-ordering-masks-it-under-partial-synchrony.warrant.json
# Markdown SHA-256:   c0bc4d1b4aeda07174f483714c93f569f0e6f77a11e72b284278aae1afe1b40a
# Code AST SHA-256:   dff332ba96c0b711ea755c36b07453077cb63c5925a1021bb7905b3282b80683
# Verified Classes:   EquivocationAttributionError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class EquivocationAttributionError(RuntimeError):
    """Raised when a replica attempts to attribute equivocation without
    sufficient quorum evidence under speculative commit ordering."""
    pass


def classify_conflict(
    proposal_a: dict,
    proposal_b: dict,
    view_change_messages: list,
    quorum_size: int,
    in_view_change_window: bool,
) -> str:
    """
    Classify an observed conflict between two signed proposals.

    Returns one of: 'benign_reorder', 'indeterminate', 'equivocation_proven'.
    Raises EquivocationAttributionError if the caller's evidence is
    insufficient to support an attribution claim.
    """
    same_slot = (
        proposal_a["height"] == proposal_b["height"]
        and proposal_a["round"] == proposal_b["round"]
    )
    same_view = proposal_a["view"] == proposal_b["view"]
    distinct_payload = proposal_a["payload_hash"] != proposal_b["payload_hash"]
    same_signer = proposal_a["signer"] == proposal_b["signer"]

    if not (same_slot and same_signer and distinct_payload):
        return "benign_reorder"

    # A conflict observed during a view-change window is never attributable
    # locally, regardless of how many conflicting proposals are seen.
    if in_view_change_window:
        return "indeterminate"

    if not same_view:
        # Different views: this is a view-change race, not equivocation.
        return "benign_reorder"

    # Attribution requires a quorum of view-change messages bracketing the
    # two proposals, proving no view change intervened.
    if len(view_change_messages) < quorum_size:
        raise EquivocationAttributionError(
            f"cannot attribute equivocation by {proposal_a['signer']}: "
            f"need {quorum_size} view-change messages, have "
            f"{len(view_change_messages)}; classify as indeterminate and "
            f"escalate to slow-path proof"
        )

    return "equivocation_proven"
