// K2481-K2485: release_acceptance.reproduction — Temiz kaynak yeniden üretim // Invariant: Target cache ve eski rapor yeni kanıt olmaz // Positive: İzole source toolchain imaj site // Counterexample: Eski target kopyalanır // Acceptance: Kaynak ve çıktı hash zinciri ölçülür pub const RELEASE_ACCEPTANCE_REPRODUCTION_SCHEMA: &str = "turkos.os.release_acceptance.reproduction.v1"; pub const RELEASE_ACCEPTANCE_REPRODUCTION_INVARIANT: &str = "Target cache ve eski rapor yeni kanıt olmaz"; pub const RELEASE_ACCEPTANCE_REPRODUCTION_POSITIVE: &str = "İzole source toolchain imaj site"; pub const RELEASE_ACCEPTANCE_REPRODUCTION_COUNTEREXAMPLE: &str = "Eski target kopyalanır"; pub const RELEASE_ACCEPTANCE_REPRODUCTION_ACCEPTANCE: &str = "Kaynak ve çıktı hash zinciri ölçülür"; pub const EXPECTED_ISOLATED_REPRODUCTION_STAGES: u32 = 4; pub const EXPECTED_HASH_CHAIN_LINKS: u32 = 4; pub const EXPECTED_CLEAN_BUILD_ATTESTATIONS: u32 = 2; pub const EXPECTED_REUSED_TARGET_CACHE_ARTIFACTS: u32 = 0; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ReleaseAcceptanceReproductionError { OldTargetCopiedIntoBuild = 1, TargetCacheOrOldReportCountedAsNewEvidence = 2, SourceToOutputHashChainUnmeasured = 3, IsolatedReproductionStagesMismatch = 4, HashChainLinksMismatch = 5, CleanBuildAttestationsMismatch = 6, ZeroReproductionEpoch = 7, NonMonotonicReproductionEpoch = 8, ZeroReproductionChainDigest = 9, UnboundReleaseAcceptanceReproductionDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct ReleaseAcceptanceReproductionRequest { pub old_target_copied_into_build: bool, pub target_cache_or_old_report_counted_as_new_evidence: bool, pub source_to_output_hash_chain_measured: bool, pub isolated_reproduction_stages: u32, pub hash_chain_links: u32, pub clean_build_attestations: u32, pub reproduction_epoch: u64, pub previous_reproduction_epoch: u64, pub reproduction_chain_digest: u64, pub reproduction_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct ReleaseAcceptanceReproductionReceipt { pub isolated_reproduction_stages: u32, pub hash_chain_links: u32, pub clean_build_attestations: u32, pub reused_target_cache_artifacts: u32, pub source_to_output_hash_chain_measured: bool, pub reproduction_epoch: u64, pub reproduction_chain_digest: u64, pub receipt_digest: u64, } pub const fn compute_release_acceptance_reproduction_binding_digest( isolated_reproduction_stages: u32, hash_chain_links: u32, clean_build_attestations: u32, reused_target_cache_artifacts: u32, reproduction_epoch: u64, reproduction_chain_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2485_524c_5250_5231).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (isolated_reproduction_stages as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (hash_chain_links as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (clean_build_attestations as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (reused_target_cache_artifacts as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ reproduction_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ reproduction_chain_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct ReleaseAcceptanceReproductionCoordinator { committed: bool, committed_total: u64, rejected_total: u64, reproduction_hygiene_refusals: u64, reproduction_accounting_refusals: u64, committed_receipt: Option, } impl ReleaseAcceptanceReproductionCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, reproduction_hygiene_refusals: 0, reproduction_accounting_refusals: 0, committed_receipt: None, } } pub fn is_committed(&self) -> bool { self.committed } pub fn committed_total(&self) -> u64 { self.committed_total } pub fn rejected_total(&self) -> u64 { self.rejected_total } pub fn reproduction_hygiene_refusals(&self) -> u64 { self.reproduction_hygiene_refusals } pub fn reproduction_accounting_refusals(&self) -> u64 { self.reproduction_accounting_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_clean_reproduction( &mut self, req: &ReleaseAcceptanceReproductionRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(ReleaseAcceptanceReproductionError::AlreadyCommitted); } if req.old_target_copied_into_build { self.rejected_total += 1; self.reproduction_hygiene_refusals += 1; return Err(ReleaseAcceptanceReproductionError::OldTargetCopiedIntoBuild); } if req.target_cache_or_old_report_counted_as_new_evidence { self.rejected_total += 1; self.reproduction_hygiene_refusals += 1; return Err( ReleaseAcceptanceReproductionError::TargetCacheOrOldReportCountedAsNewEvidence, ); } if !req.source_to_output_hash_chain_measured { self.rejected_total += 1; self.reproduction_hygiene_refusals += 1; return Err(ReleaseAcceptanceReproductionError::SourceToOutputHashChainUnmeasured); } if req.isolated_reproduction_stages != EXPECTED_ISOLATED_REPRODUCTION_STAGES { self.rejected_total += 1; self.reproduction_accounting_refusals += 1; return Err(ReleaseAcceptanceReproductionError::IsolatedReproductionStagesMismatch); } if req.hash_chain_links != EXPECTED_HASH_CHAIN_LINKS { self.rejected_total += 1; self.reproduction_accounting_refusals += 1; return Err(ReleaseAcceptanceReproductionError::HashChainLinksMismatch); } if req.clean_build_attestations != EXPECTED_CLEAN_BUILD_ATTESTATIONS { self.rejected_total += 1; self.reproduction_accounting_refusals += 1; return Err(ReleaseAcceptanceReproductionError::CleanBuildAttestationsMismatch); } if req.reproduction_epoch == 0 { self.rejected_total += 1; return Err(ReleaseAcceptanceReproductionError::ZeroReproductionEpoch); } if req.reproduction_epoch <= req.previous_reproduction_epoch { self.rejected_total += 1; return Err(ReleaseAcceptanceReproductionError::NonMonotonicReproductionEpoch); } if req.reproduction_chain_digest == 0 { self.rejected_total += 1; return Err(ReleaseAcceptanceReproductionError::ZeroReproductionChainDigest); } let expected_binding = compute_release_acceptance_reproduction_binding_digest( req.isolated_reproduction_stages, req.hash_chain_links, req.clean_build_attestations, EXPECTED_REUSED_TARGET_CACHE_ARTIFACTS, req.reproduction_epoch, req.reproduction_chain_digest, ); if req.reproduction_binding_digest != expected_binding { self.rejected_total += 1; self.reproduction_accounting_refusals += 1; return Err( ReleaseAcceptanceReproductionError::UnboundReleaseAcceptanceReproductionDigest, ); } self.committed = true; self.committed_total += 1; let receipt = ReleaseAcceptanceReproductionReceipt { isolated_reproduction_stages: req.isolated_reproduction_stages, hash_chain_links: req.hash_chain_links, clean_build_attestations: req.clean_build_attestations, reused_target_cache_artifacts: EXPECTED_REUSED_TARGET_CACHE_ARTIFACTS, source_to_output_hash_chain_measured: true, reproduction_epoch: req.reproduction_epoch, reproduction_chain_digest: req.reproduction_chain_digest, receipt_digest: expected_binding ^ 0x2485_ACE0_5250_5231, }; self.committed_receipt = Some(receipt); Ok(receipt) } }