# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-detect-exit-cost-extraction-in-contract-negotiation.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-detect-exit-cost-extraction-in-contract-negotiation.warrant.json # Markdown SHA-256: c1f8f24b121d6f857ac032a8fc1ac428fa009774942abc18d5864ebe55effaab # Code AST SHA-256: 908448810ed5ff8bb1192d6395c554a72f78bbdffdde13549085173d2e920257 # Verified Classes: ExitCostVerdict, ExitCostTerms, ExitCostPolicy, ExitCostManifest, ExitCostExtractionGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class ExitCostVerdict(Enum): NO_EXIT_COSTS = auto() EXIT_COST_WITHIN_BOUNDS = auto() ASYMMETRIC_LEVERAGE_DETECTED = auto() LOCK_IN_EXTRACTION_DETECTED = auto() @dataclass(frozen=True) class ExitCostTerms: contract_id: str has_exit_costs: bool session_exit_cost: float peer_exit_cost: float max_exit_cost: float min_remaining_value: float @dataclass(frozen=True) class ExitCostPolicy: max_acceptable_asymmetry: float max_acceptable_cost_to_value: float @dataclass(frozen=True) class ExitCostManifest: verdict: ExitCostVerdict directive: str manifest_digest: str class ExitCostExtractionGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_terms( cls, terms: ExitCostTerms, policy: ExitCostPolicy ) -> ExitCostManifest: # Gate 1: No exit costs if not terms.has_exit_costs: digest = cls._hash(json.dumps({ "contract": terms.contract_id, "exit_costs": False }, sort_keys=True)) return ExitCostManifest( verdict=ExitCostVerdict.NO_EXIT_COSTS, directive=f"PROCEED: Contract {terms.contract_id} no exit costs.", manifest_digest=digest ) # Gate 2: Symmetry asymmetry = abs(terms.session_exit_cost - terms.peer_exit_cost) if asymmetry > policy.max_acceptable_asymmetry: return ExitCostManifest( verdict=ExitCostVerdict.ASYMMETRIC_LEVERAGE_DETECTED, directive=f"FLAG: Contract {terms.contract_id} exit asymmetry {asymmetry:.2f}.", manifest_digest=cls._hash(f"ASYM:{terms.contract_id}") ) # Gate 3: Cost-value ratio if terms.min_remaining_value > 0: ratio = terms.max_exit_cost / terms.min_remaining_value if ratio > policy.max_acceptable_cost_to_value: return ExitCostManifest( verdict=ExitCostVerdict.LOCK_IN_EXTRACTION_DETECTED, directive=f"FLAG: Contract {terms.contract_id} cost-to-value {ratio:.2f}.", manifest_digest=cls._hash(f"LOCKIN:{terms.contract_id}") ) # Gate 4: Bounded digest = cls._hash(json.dumps({ "contract": terms.contract_id, "session_cost": f"{terms.session_exit_cost:.3f}", "peer_cost": f"{terms.peer_exit_cost:.3f}", "max_cost": f"{terms.max_exit_cost:.3f}" }, sort_keys=True)) return ExitCostManifest( verdict=ExitCostVerdict.EXIT_COST_WITHIN_BOUNDS, directive=f"PROCEED: Contract {terms.contract_id} exit costs within bounds.", manifest_digest=digest )