# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-cross-org-slashing-from-double-debiting-an-agent-after-equivocation-forks.md # Remnant Warrant: https://corpusfetch.com/c/which-invariants-prevent-cross-org-slashing-from-double-debiting-an-agent-after-equivocation-forks.warrant.json # Markdown SHA-256: 3993238a32fef60f241b49fa82296189823c93c8c0328956b977ee871f5fb4bd # Code AST SHA-256: 538c10331f9fe8fc560d21f86608d14641f6b884b53d50a60aeff2ecbe29d1a6 # Verified Classes: SlashingInvariantError, Attestation, FederatedLedger # Defensive Guards: 2 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) import hashlib from dataclasses import dataclass, field class SlashingInvariantError(RuntimeError): """Raised when a federated slash would violate single-debit-per-evidence.""" @dataclass(frozen=True) class Attestation: worker_id: str task_id: str epoch: int result: str signature: bytes def canonical_evidence_id(a: Attestation, b: Attestation) -> str: # Deterministic over the sorted pair; serialization must be pinned. pair = sorted( [f"{x.worker_id}|{x.task_id}|{x.epoch}|{x.result}|{x.signature.hex()}" for x in (a, b)] ) return hashlib.sha256("::".join(pair).encode()).hexdigest() @dataclass class FederatedLedger: slash_amount: int applied_evidence: set = field(default_factory=set) def apply_slash(self, evidence_id: str, canonicalization_version: str) -> int: if canonicalization_version != "v3": # Unpinned canonicalization: cannot safely dedup, refuse to merge. raise SlashingInvariantError( f"evidence {evidence_id} presented under unpinned " f"canonicalization {canonicalization_version!r}; refusing debit" ) if evidence_id in self.applied_evidence: # Idempotent: same evidence, no new debit. return len(self.applied_evidence) * self.slash_amount self.applied_evidence.add(evidence_id) return len(self.applied_evidence) * self.slash_amount def federated_debit(ledgers, a: Attestation, b: Attestation, version: str) -> int: eid = canonical_evidence_id(a, b) totals = [led.apply_slash(eid, version) for led in ledgers] if len(set(totals)) != 1: raise SlashingInvariantError( f"domains diverged on debit for evidence {eid}: {totals}" ) return totals[0]