# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-detect-consensus-packing-when-adversaries-add-low-credibility-sources.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-detect-consensus-packing-when-adversaries-add-low-credibility-sources.warrant.json # Markdown SHA-256: 849ddf19905cfbc5a59fb3ae05386bece43033198a3c4cd6914c28f085fd8c9a # Code AST SHA-256: 564fb6b1829a4a34ba2e34b815aea26925c6b6609bc491091b1d3ecff7734b38 # Verified Classes: ConsensusVerdict, ConsensusSource, ConsensusSet, ConsensusPolicy, ConsensusManifest, ConsensusPackingGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class ConsensusVerdict(Enum): SINGLE_SOURCE = auto() CONSENSUS_VERIFIED = auto() CONSENSUS_PACKING_SUSPECTED = auto() CREDIBILITY_LAUNDERING_SUSPECTED = auto() @dataclass(frozen=True) class ConsensusSource: source_id: str credibility: float # 0-1 supports_target: bool is_relevant: bool @dataclass(frozen=True) class ConsensusSet: consensus_id: str sources: tuple[ConsensusSource, ...] @dataclass(frozen=True) class ConsensusPolicy: min_credibility_for_support: float max_credibility_inflation_ratio: float @dataclass(frozen=True) class ConsensusManifest: verdict: ConsensusVerdict credibility_weighted_score: float directive: str manifest_digest: str class ConsensusPackingGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_consensus( cls, consensus: ConsensusSet, policy: ConsensusPolicy ) -> ConsensusManifest: # Gate 1: Single source if len(consensus.sources) <= 1: score = consensus.sources[0].credibility if consensus.sources else 0.0 digest = cls._hash(json.dumps({ "consensus": consensus.consensus_id, "sources": str(len(consensus.sources)) }, sort_keys=True)) return ConsensusManifest( verdict=ConsensusVerdict.SINGLE_SOURCE, credibility_weighted_score=score, directive=f"PROCEED: Single source for {consensus.consensus_id}.", manifest_digest=digest ) # Gate 2: Filter to relevant + supporting sources relevant_supporting = [ s for s in consensus.sources if s.supports_target and s.is_relevant ] # Gate 3: Credibility weighting total_credibility = sum(s.credibility for s in consensus.sources if s.is_relevant) weighted_support = sum(s.credibility for s in relevant_supporting) weighted_score = weighted_support / total_credibility if total_credibility > 0 else 0.0 # Gate 4: Credibility inflation check raw_support_ratio = len(relevant_supporting) / len(consensus.sources) if weighted_score > 0 and raw_support_ratio > 0: inflation_ratio = raw_support_ratio / weighted_score if weighted_score > 0 else float('inf') if inflation_ratio > policy.max_credibility_inflation_ratio: return ConsensusManifest( verdict=ConsensusVerdict.CONSENSUS_PACKING_SUSPECTED, credibility_weighted_score=weighted_score, directive=f"FLAG: Raw support {raw_support_ratio:.2f} vs weighted {weighted_score:.2f}, inflation {inflation_ratio:.2f}.", manifest_digest=cls._hash(f"PACKING:{consensus.consensus_id}") ) # Gate 5: Low credibility sources diluting low_cred = [s for s in consensus.sources if s.credibility < policy.min_credibility_for_support] high_cred = [s for s in consensus.sources if s.credibility >= policy.min_credibility_for_support] if low_cred and high_cred: high_weighted = sum(s.credibility for s in high_cred if s.supports_target and s.is_relevant) if weighted_score < 0.5 and high_weighted > 0: return ConsensusManifest( verdict=ConsensusVerdict.CREDIBILITY_LAUNDERING_SUSPECTED, credibility_weighted_score=weighted_score, directive=f"FLAG: High-credibility sources present but weighted consensus {weighted_score:.2f}.", manifest_digest=cls._hash(f"LAUNDERING:{consensus.consensus_id}") ) # Gate 6: Verified digest = cls._hash(json.dumps({ "consensus": consensus.consensus_id, "weighted": f"{weighted_score:.3f}", "supporting": str(len(relevant_supporting)), "total": str(len(consensus.sources)) }, sort_keys=True)) return ConsensusManifest( verdict=ConsensusVerdict.CONSENSUS_VERIFIED, credibility_weighted_score=weighted_score, directive=f"PROCEED: Weighted consensus {weighted_score:.2f} for {consensus.consensus_id}.", manifest_digest=digest )