// K2421-K2425: system_fuzz.inputs — Sınır parser korpusları // Invariant: DTB ELF FS IPC network hedefleri ayrıdır // Positive: Her parser küçük bounded girdiler // Counterexample: Tek korpus bütün parser diye sayılır // Acceptance: Target ve input hashleri ayrı pub const SYSTEM_FUZZ_INPUTS_SCHEMA: &str = "turkos.os.system_fuzz.inputs.v1"; pub const SYSTEM_FUZZ_INPUTS_INVARIANT: &str = "DTB ELF FS IPC network hedefleri ayrıdır"; pub const SYSTEM_FUZZ_INPUTS_POSITIVE: &str = "Her parser küçük bounded girdiler"; pub const SYSTEM_FUZZ_INPUTS_COUNTEREXAMPLE: &str = "Tek korpus bütün parser diye sayılır"; pub const SYSTEM_FUZZ_INPUTS_ACCEPTANCE: &str = "Target ve input hashleri ayrı"; pub const EXPECTED_DISTINCT_PARSER_TARGETS: u32 = 5; pub const EXPECTED_BOUNDED_CORPUS_SEEDS: u32 = 10; pub const EXPECTED_DISTINCT_TARGET_INPUT_HASHES: u32 = 5; pub const EXPECTED_MERGED_SINGLE_CORPUS_BYPASSES: u32 = 0; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum SystemFuzzInputsError { SingleCorpusCountedForAllParsers = 1, ParserTargetsCollapsed = 2, TargetOrInputHashesShared = 3, DistinctParserTargetsMismatch = 4, BoundedCorpusSeedsMismatch = 5, DistinctTargetInputHashesMismatch = 6, ZeroInputsEpoch = 7, NonMonotonicInputsEpoch = 8, ZeroInputsCorpusDigest = 9, UnboundSystemFuzzInputsDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct SystemFuzzInputsRequest { pub single_corpus_counted_for_all_parsers: bool, pub parser_targets_collapsed: bool, pub target_and_input_hashes_distinct: bool, pub distinct_parser_targets: u32, pub bounded_corpus_seeds: u32, pub distinct_target_input_hashes: u32, pub inputs_epoch: u64, pub previous_inputs_epoch: u64, pub inputs_corpus_digest: u64, pub inputs_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct SystemFuzzInputsReceipt { pub distinct_parser_targets: u32, pub bounded_corpus_seeds: u32, pub distinct_target_input_hashes: u32, pub merged_single_corpus_bypasses: u32, pub target_and_input_hashes_distinct: bool, pub inputs_epoch: u64, pub inputs_corpus_digest: u64, pub receipt_digest: u64, } pub const fn compute_system_fuzz_inputs_binding_digest( distinct_parser_targets: u32, bounded_corpus_seeds: u32, distinct_target_input_hashes: u32, merged_single_corpus_bypasses: u32, inputs_epoch: u64, inputs_corpus_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2425_5346_494e_5031).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (distinct_parser_targets as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (bounded_corpus_seeds as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (distinct_target_input_hashes as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (merged_single_corpus_bypasses as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ inputs_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ inputs_corpus_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct SystemFuzzInputsCoordinator { committed: bool, committed_total: u64, rejected_total: u64, corpus_separation_refusals: u64, corpus_accounting_refusals: u64, committed_receipt: Option, } impl SystemFuzzInputsCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, corpus_separation_refusals: 0, corpus_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 corpus_separation_refusals(&self) -> u64 { self.corpus_separation_refusals } pub fn corpus_accounting_refusals(&self) -> u64 { self.corpus_accounting_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_boundary_parser_corpora( &mut self, req: &SystemFuzzInputsRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(SystemFuzzInputsError::AlreadyCommitted); } if req.single_corpus_counted_for_all_parsers { self.rejected_total += 1; self.corpus_separation_refusals += 1; return Err(SystemFuzzInputsError::SingleCorpusCountedForAllParsers); } if req.parser_targets_collapsed { self.rejected_total += 1; self.corpus_separation_refusals += 1; return Err(SystemFuzzInputsError::ParserTargetsCollapsed); } if !req.target_and_input_hashes_distinct { self.rejected_total += 1; self.corpus_separation_refusals += 1; return Err(SystemFuzzInputsError::TargetOrInputHashesShared); } if req.distinct_parser_targets != EXPECTED_DISTINCT_PARSER_TARGETS { self.rejected_total += 1; self.corpus_accounting_refusals += 1; return Err(SystemFuzzInputsError::DistinctParserTargetsMismatch); } if req.bounded_corpus_seeds != EXPECTED_BOUNDED_CORPUS_SEEDS { self.rejected_total += 1; self.corpus_accounting_refusals += 1; return Err(SystemFuzzInputsError::BoundedCorpusSeedsMismatch); } if req.distinct_target_input_hashes != EXPECTED_DISTINCT_TARGET_INPUT_HASHES { self.rejected_total += 1; self.corpus_accounting_refusals += 1; return Err(SystemFuzzInputsError::DistinctTargetInputHashesMismatch); } if req.inputs_epoch == 0 { self.rejected_total += 1; return Err(SystemFuzzInputsError::ZeroInputsEpoch); } if req.inputs_epoch <= req.previous_inputs_epoch { self.rejected_total += 1; return Err(SystemFuzzInputsError::NonMonotonicInputsEpoch); } if req.inputs_corpus_digest == 0 { self.rejected_total += 1; return Err(SystemFuzzInputsError::ZeroInputsCorpusDigest); } let expected_binding = compute_system_fuzz_inputs_binding_digest( req.distinct_parser_targets, req.bounded_corpus_seeds, req.distinct_target_input_hashes, EXPECTED_MERGED_SINGLE_CORPUS_BYPASSES, req.inputs_epoch, req.inputs_corpus_digest, ); if req.inputs_binding_digest != expected_binding { self.rejected_total += 1; self.corpus_accounting_refusals += 1; return Err(SystemFuzzInputsError::UnboundSystemFuzzInputsDigest); } self.committed = true; self.committed_total += 1; let receipt = SystemFuzzInputsReceipt { distinct_parser_targets: req.distinct_parser_targets, bounded_corpus_seeds: req.bounded_corpus_seeds, distinct_target_input_hashes: req.distinct_target_input_hashes, merged_single_corpus_bypasses: EXPECTED_MERGED_SINGLE_CORPUS_BYPASSES, target_and_input_hashes_distinct: true, inputs_epoch: req.inputs_epoch, inputs_corpus_digest: req.inputs_corpus_digest, receipt_digest: expected_binding ^ 0x2425_ACE0_494e_5031, }; self.committed_receipt = Some(receipt); Ok(receipt) } }