use std::cmp::Ordering; use std::collections::BTreeMap; use std::env; use std::fs; use std::process::ExitCode; const EXPECTED_CONTRACT: &str = "OMEGA_NAUGHT/1.0"; const EXPECTED_ALGEBRA: &str = "Q(T)[lambda]/(lambda^2-T*lambda-T^2)"; const EXPECTED_Q: u128 = 339_949_771_344_778; const EXPECTED_S: u128 = 1_000_000_000_000_000; const EXPECTED_L60: &str = "339949771344778929576702809321279193551009905014259416689444"; const EXPECTED_U60: &str = "339949771344778929576702809321279193551009905014259416689445"; const LEDGER_STEPS: usize = 23; const FIRST_MISMATCH: u64 = 42_189_065; const REQUIRED_KEYS: [&str; 7] = ["contract", "algebra", "bits", "Q", "S", "L60", "U60"]; #[derive(Clone, Debug)] struct Manifest { contract: String, algebra: String, bits: u32, q: u128, s: u128, l60: String, u60: String, } impl Manifest { fn parse(text: &str) -> Result { let mut values = BTreeMap::::new(); for (index, raw) in text.lines().enumerate() { let line = raw.trim(); if line.is_empty() || line.starts_with('#') { continue; } let (raw_key, raw_value) = line .split_once('=') .ok_or_else(|| format!("bad manifest line {}: {raw:?}", index + 1))?; let key = raw_key.trim(); let value = raw_value.trim(); if key.is_empty() || value.is_empty() { return Err(format!("empty manifest field on line {}", index + 1)); } if !REQUIRED_KEYS.iter().any(|expected| *expected == key) { return Err(format!("unknown manifest key: {key}")); } if values.insert(key.to_string(), value.to_string()).is_some() { return Err(format!("duplicate manifest key: {key}")); } } for key in REQUIRED_KEYS { if !values.contains_key(key) { return Err(format!("missing manifest key: {key}")); } } let contract = values.remove("contract").expect("required key checked"); let algebra = values.remove("algebra").expect("required key checked"); let bits = parse_u32(values.remove("bits").expect("required key checked").as_str(), "bits")?; let q = parse_u128(values.remove("Q").expect("required key checked").as_str(), "Q")?; let s = parse_u128(values.remove("S").expect("required key checked").as_str(), "S")?; let l60 = values.remove("L60").expect("required key checked"); let u60 = values.remove("U60").expect("required key checked"); if !is_canonical_unsigned_decimal(&l60) || l60.len() != 60 { return Err("L60 must be a canonical 60-digit unsigned decimal".into()); } if !is_canonical_unsigned_decimal(&u60) || u60.len() != 60 { return Err("U60 must be a canonical 60-digit unsigned decimal".into()); } if q == 0 || s == 0 { return Err("Q and S must be positive".into()); } Ok(Self { contract, algebra, bits, q, s, l60, u60 }) } fn read(path: &str) -> Result { let text = fs::read_to_string(path).map_err(|error| format!("cannot read {path}: {error}"))?; Self::parse(&text) } } fn is_canonical_unsigned_decimal(value: &str) -> bool { !value.is_empty() && value.bytes().all(|byte| byte.is_ascii_digit()) && (value == "0" || !value.starts_with('0')) } fn parse_u32(value: &str, name: &str) -> Result { if !is_canonical_unsigned_decimal(value) { return Err(format!("{name} is not a canonical unsigned decimal")); } value.parse::().map_err(|_| format!("{name} is outside u32")) } fn parse_u128(value: &str, name: &str) -> Result { if !is_canonical_unsigned_decimal(value) { return Err(format!("{name} is not a canonical unsigned decimal")); } value.parse::().map_err(|_| format!("{name} is outside u128")) } #[derive(Clone, Debug, PartialEq, Eq)] struct Laurent(BTreeMap); impl Laurent { fn zero() -> Self { Self(BTreeMap::new()) } fn mono(exp: i32, coeff: i128) -> Self { let mut coefficients = BTreeMap::new(); if coeff != 0 { coefficients.insert(exp, coeff); } Self(coefficients) } fn add(&self, other: &Self) -> Result { let mut result = self.0.clone(); for (&exp, &value) in &other.0 { let old = result.get(&exp).copied().unwrap_or(0); let next = old.checked_add(value).ok_or("Laurent coefficient overflow in addition")?; if next == 0 { result.remove(&exp); } else { result.insert(exp, next); } } Ok(Self(result)) } fn neg(&self) -> Result { let mut result = BTreeMap::new(); for (&exp, &value) in &self.0 { result.insert(exp, value.checked_neg().ok_or("Laurent coefficient overflow in negation")?); } Ok(Self(result)) } fn sub(&self, other: &Self) -> Result { self.add(&other.neg()?) } fn mul(&self, other: &Self) -> Result { let mut result = BTreeMap::::new(); for (&left_exp, &left_value) in &self.0 { for (&right_exp, &right_value) in &other.0 { let exp = left_exp.checked_add(right_exp).ok_or("Laurent exponent overflow")?; let product = left_value .checked_mul(right_value) .ok_or("Laurent coefficient overflow in multiplication")?; let old = result.get(&exp).copied().unwrap_or(0); let next = old.checked_add(product).ok_or("Laurent coefficient overflow in accumulation")?; if next == 0 { result.remove(&exp); } else { result.insert(exp, next); } } } Ok(Self(result)) } fn shift(&self, amount: i32) -> Result { let mut result = BTreeMap::new(); for (&exp, &value) in &self.0 { result.insert(exp.checked_add(amount).ok_or("Laurent exponent overflow")?, value); } Ok(Self(result)) } fn is_zero(&self) -> bool { self.0.is_empty() } } #[derive(Clone, Debug, PartialEq, Eq)] struct K { a: Laurent, b: Laurent, } impl K { fn one() -> Self { Self { a: Laurent::mono(0, 1), b: Laurent::zero() } } fn t() -> Self { Self { a: Laurent::mono(1, 1), b: Laurent::zero() } } fn t_inverse() -> Self { Self { a: Laurent::mono(-1, 1), b: Laurent::zero() } } fn lambda() -> Self { Self { a: Laurent::zero(), b: Laurent::mono(0, 1) } } fn add(&self, other: &Self) -> Result { Ok(Self { a: self.a.add(&other.a)?, b: self.b.add(&other.b)? }) } fn neg(&self) -> Result { Ok(Self { a: self.a.neg()?, b: self.b.neg()? }) } fn sub(&self, other: &Self) -> Result { self.add(&other.neg()?) } fn mul(&self, other: &Self) -> Result { // lambda^2 = T*lambda + T^2. let bd = self.b.mul(&other.b)?; let a = self.a.mul(&other.a)?.add(&bd.shift(2)?)?; let b = self .a .mul(&other.b)? .add(&self.b.mul(&other.a)?)? .add(&bd.shift(1)?)?; Ok(Self { a, b }) } fn is_zero(&self) -> bool { self.a.is_zero() && self.b.is_zero() } } fn decimal_add_one(value: &str) -> Option { if !is_canonical_unsigned_decimal(value) { return None; } let mut bytes = value.as_bytes().to_vec(); let mut index = bytes.len(); while index > 0 { index -= 1; if bytes[index] < b'9' { bytes[index] += 1; return String::from_utf8(bytes).ok(); } bytes[index] = b'0'; } let mut result = vec![b'1']; result.extend(bytes); String::from_utf8(result).ok() } fn normalized_decimal(value: &str) -> &str { let stripped = value.trim_start_matches('0'); if stripped.is_empty() { "0" } else { stripped } } fn compare_decimals(left: &str, right: &str) -> Ordering { let left = normalized_decimal(left); let right = normalized_decimal(right); left.len().cmp(&right.len()).then_with(|| left.cmp(right)) } fn multiply_decimal_by_u64(value: &str, multiplier: u64) -> Option { if !is_canonical_unsigned_decimal(value) { return None; } if multiplier == 0 || value == "0" { return Some("0".into()); } let mut reversed = Vec::::new(); let mut carry = 0u128; for byte in value.bytes().rev() { let digit = u128::from(byte - b'0'); let product = digit.checked_mul(u128::from(multiplier))?.checked_add(carry)?; reversed.push((product % 10) as u8 + b'0'); carry = product / 10; } while carry > 0 { reversed.push((carry % 10) as u8 + b'0'); carry /= 10; } reversed.reverse(); String::from_utf8(reversed).ok() } fn divide_by_power_of_ten(value: &str, digits: usize) -> Option<(u128, bool)> { if !is_canonical_unsigned_decimal(value) { return None; } if value.len() <= digits { return Some((0, value.bytes().any(|byte| byte != b'0'))); } let split = value.len() - digits; let quotient = value[..split].parse::().ok()?; let remainder_nonzero = value[split..].bytes().any(|byte| byte != b'0'); Some((quotient, remainder_nonzero)) } fn exact_floor_from_open_interval(l60: &str, u60: &str, d: u64) -> Option { if d == 0 { return Some(0); } let lower_product = multiply_decimal_by_u64(l60, d)?; let upper_product = multiply_decimal_by_u64(u60, d)?; let (lower_floor, _) = divide_by_power_of_ten(&lower_product, 60)?; let (upper_quotient, upper_has_remainder) = divide_by_power_of_ten(&upper_product, 60)?; let upper_floor = if upper_has_remainder { upper_quotient } else { upper_quotient.checked_sub(1)? }; (lower_floor == upper_floor).then_some(lower_floor) } fn forward_step(d: u128, q: u128, s: u128) -> Option<(u128, u128)> { let product = q.checked_mul(d)?; Some((product / s, product % s)) } fn reverse_step(next: u128, remainder: u128, q: u128, s: u128) -> Option { if q == 0 || remainder >= s { return None; } let numerator = s.checked_mul(next)?.checked_add(remainder)?; (numerator % q == 0).then_some(numerator / q) } #[derive(Clone, Debug)] struct Ledger { terminal: u128, remainders: Vec, } fn build_ledger(seed: u128, steps: usize, q: u128, s: u128) -> Option { let mut state = seed; let mut remainders = Vec::with_capacity(steps); for _ in 0..steps { let (next, remainder) = forward_step(state, q, s)?; remainders.push(remainder); state = next; } Some(Ledger { terminal: state, remainders }) } fn recover_ledger(ledger: &Ledger, q: u128, s: u128) -> Option { let mut state = ledger.terminal; for &remainder in ledger.remainders.iter().rev() { state = reverse_step(state, remainder, q, s)?; } Some(state) } fn verify_unsigned_15bit_replay(manifest: &Manifest) -> bool { if manifest.bits != 15 { return false; } let limit = 1u128 << manifest.bits; for d in 0..limit { let Some((next, remainder)) = forward_step(d, manifest.q, manifest.s) else { return false; }; if remainder >= manifest.s || reverse_step(next, remainder, manifest.q, manifest.s) != Some(d) { return false; } } true } fn verify_ordered_23step_ledgers(manifest: &Manifest) -> bool { if manifest.bits != 15 { return false; } for d in 0..(1u128 << manifest.bits) { let Some(ledger) = build_ledger(d, LEDGER_STEPS, manifest.q, manifest.s) else { return false; }; if ledger.terminal != 0 || recover_ledger(&ledger, manifest.q, manifest.s) != Some(d) { return false; } } true } #[derive(Clone, Debug, PartialEq, Eq)] struct FoldedBytes { limbs: Vec, pad_bits: usize, } fn fold_bytes(bytes: &[u8], bits: usize) -> Option { if !(1..=16).contains(&bits) { return None; } let mask = (1u64 << bits) - 1; let mut limbs = Vec::new(); let mut accumulator = 0u64; let mut held_bits = 0usize; for &byte in bytes { accumulator = (accumulator << 8) | u64::from(byte); held_bits += 8; while held_bits >= bits { let shift = held_bits - bits; limbs.push(((accumulator >> shift) & mask) as u16); accumulator &= if shift == 0 { 0 } else { (1u64 << shift) - 1 }; held_bits = shift; } } let pad_bits = if held_bits == 0 { 0 } else { bits - held_bits }; if held_bits != 0 { limbs.push(((accumulator << pad_bits) & mask) as u16); } Some(FoldedBytes { limbs, pad_bits }) } fn unfold_bytes(folded: &FoldedBytes, byte_len: usize, bits: usize) -> Result, String> { if !(1..=16).contains(&bits) { return Err("limb width must be in 1..=16".into()); } let data_bits = byte_len.checked_mul(8).ok_or("byte length overflow")?; let expected_limbs = if data_bits == 0 { 0 } else { (data_bits + bits - 1) / bits }; if folded.limbs.len() != expected_limbs { return Err("noncanonical limb count".into()); } let total_bits = folded.limbs.len().checked_mul(bits).ok_or("limb length overflow")?; let pad_bits = total_bits.checked_sub(data_bits).ok_or("insufficient limb data")?; if pad_bits >= bits || folded.pad_bits != pad_bits { return Err("noncanonical padding length".into()); } let limit = 1u64 << bits; let mut accumulator = 0u64; let mut held_bits = 0usize; let mut bytes = Vec::with_capacity(byte_len); for &limb in &folded.limbs { if u64::from(limb) >= limit { return Err("limb outside declared width".into()); } accumulator = (accumulator << bits) | u64::from(limb); held_bits += bits; while held_bits >= 8 && bytes.len() < byte_len { let shift = held_bits - 8; bytes.push(((accumulator >> shift) & 0xff) as u8); accumulator &= if shift == 0 { 0 } else { (1u64 << shift) - 1 }; held_bits = shift; } } if bytes.len() != byte_len || held_bits != pad_bits || accumulator != 0 { return Err("nonzero or malformed trailing padding".into()); } Ok(bytes) } fn verify_byte_fold(manifest: &Manifest) -> bool { const PAYLOAD: &[u8] = b"Omega Naught"; const EXPECTED: [u16; 7] = [10_166, 22_873, 27_684, 1_254, 2_987, 7_585, 26_624]; let Some(folded) = fold_bytes(PAYLOAD, manifest.bits as usize) else { return false; }; if folded.limbs.as_slice() != EXPECTED.as_ref() || folded.pad_bits != 9 { return false; } match unfold_bytes(&folded, PAYLOAD.len(), manifest.bits as usize) { Ok(bytes) if bytes.as_slice() == PAYLOAD => {} _ => return false, } for &limb in &folded.limbs { let Some(ledger) = build_ledger(u128::from(limb), LEDGER_STEPS, manifest.q, manifest.s) else { return false; }; if recover_ledger(&ledger, manifest.q, manifest.s) != Some(u128::from(limb)) { return false; } } let mut corrupted = folded.clone(); let Some(last) = corrupted.limbs.last_mut() else { return false; }; *last |= 1; unfold_bytes(&corrupted, PAYLOAD.len(), manifest.bits as usize).is_err() } fn sha256(input: &[u8]) -> [u8; 32] { const K: [u32; 64] = [ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, ]; let mut state = [ 0x6a09e667u32, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, ]; let bit_len = (input.len() as u64).wrapping_mul(8); let mut message = input.to_vec(); message.push(0x80); while message.len() % 64 != 56 { message.push(0); } message.extend_from_slice(&bit_len.to_be_bytes()); for chunk in message.chunks_exact(64) { let mut words = [0u32; 64]; for index in 0..16 { let offset = index * 4; words[index] = u32::from_be_bytes([ chunk[offset], chunk[offset + 1], chunk[offset + 2], chunk[offset + 3], ]); } for index in 16..64 { let s0 = words[index - 15].rotate_right(7) ^ words[index - 15].rotate_right(18) ^ (words[index - 15] >> 3); let s1 = words[index - 2].rotate_right(17) ^ words[index - 2].rotate_right(19) ^ (words[index - 2] >> 10); words[index] = words[index - 16] .wrapping_add(s0) .wrapping_add(words[index - 7]) .wrapping_add(s1); } let mut a = state[0]; let mut b = state[1]; let mut c = state[2]; let mut d = state[3]; let mut e = state[4]; let mut f = state[5]; let mut g = state[6]; let mut h = state[7]; for index in 0..64 { let sum1 = e.rotate_right(6) ^ e.rotate_right(11) ^ e.rotate_right(25); let choose = (e & f) ^ ((!e) & g); let temp1 = h .wrapping_add(sum1) .wrapping_add(choose) .wrapping_add(K[index]) .wrapping_add(words[index]); let sum0 = a.rotate_right(2) ^ a.rotate_right(13) ^ a.rotate_right(22); let majority = (a & b) ^ (a & c) ^ (b & c); let temp2 = sum0.wrapping_add(majority); h = g; g = f; f = e; e = d.wrapping_add(temp1); d = c; c = b; b = a; a = temp1.wrapping_add(temp2); } state[0] = state[0].wrapping_add(a); state[1] = state[1].wrapping_add(b); state[2] = state[2].wrapping_add(c); state[3] = state[3].wrapping_add(d); state[4] = state[4].wrapping_add(e); state[5] = state[5].wrapping_add(f); state[6] = state[6].wrapping_add(g); state[7] = state[7].wrapping_add(h); } let mut output = [0u8; 32]; for (index, word) in state.iter().enumerate() { output[index * 4..index * 4 + 4].copy_from_slice(&word.to_be_bytes()); } output } fn hex(bytes: &[u8]) -> String { let mut output = String::with_capacity(bytes.len() * 2); for byte in bytes { output.push_str(&format!("{byte:02x}")); } output } fn verify_canonical_hashes() -> bool { const VECTORS: [(&str, &str); 3] = [ ( r#"{"a":{"den":["1"],"num":["0"]},"b":{"den":["1"],"num":["1"]},"basis":"1,lambda"}"#, "766659b6211a5bc601f3c88e8ae97614a3fe66abc87965d78efb0af3f59e0a49", ), ( r#"{"a":{"den":["1"],"num":["0"]},"b":{"den":["0","1"],"num":["1"]},"basis":"1,lambda"}"#, "9109f2d9f236b283767310a136314656f4b17d38f3bac1c96d4431177d3b586a", ), ( r#"{"a":{"den":["0","1"],"num":["1"]},"b":{"den":["0","1"],"num":["-1"]},"basis":"1,lambda"}"#, "815c7dd22e3b7ac29ec67a8f27398baad17dc4bc42c03a3146abb4c73e0ee163", ), ]; VECTORS.iter().all(|(record, expected)| hex(&sha256(record.as_bytes())) == *expected) } fn run_checks(manifest: &Manifest) -> Result, String> { let mut checks = Vec::<(&'static str, bool)>::new(); checks.push(("manifest.contract", manifest.contract == EXPECTED_CONTRACT)); checks.push(("manifest.algebra", manifest.algebra == EXPECTED_ALGEBRA)); checks.push(("manifest.expected_L60", manifest.l60 == EXPECTED_L60)); checks.push(("manifest.expected_U60", manifest.u60 == EXPECTED_U60)); checks.push(("manifest.expected_Q", manifest.q == EXPECTED_Q)); checks.push(("manifest.expected_S", manifest.s == EXPECTED_S)); let one = K::one(); let t = K::t(); let t_inverse = K::t_inverse(); let lambda = K::lambda(); let omega = t_inverse.clone(); let tau = t.clone(); let phi = lambda.mul(&t_inverse)?; let mu = one.sub(&lambda)?; let pi_k = omega.sub(&phi)?; checks.push(("exact.omega_tau", omega.mul(&tau)? == one)); checks.push(("exact.lambda_mu", lambda.add(&mu)? == one)); let lambda_squared = lambda.mul(&lambda)?; let tau_lambda = tau.mul(&lambda)?; let tau_squared = tau.mul(&tau)?; checks.push(( "exact.lambda_relation", lambda_squared.sub(&tau_lambda)?.sub(&tau_squared)?.is_zero(), )); let phi_quadratic = phi.mul(&phi)?.sub(&phi)?.sub(&one)?; checks.push(("exact.phi_quadratic", phi_quadratic.is_zero())); checks.push(("exact.phi_pi_omega", phi.add(&pi_k)? == omega)); let qs_decimal = if manifest.s == 1_000_000_000_000_000 && manifest.q < manifest.s { format!("0.{:015}", manifest.q) } else { String::new() }; checks.push(("finite.qs_decimal", qs_decimal == "0.339949771344778")); checks.push(( "finite.ledger_adjacent", decimal_add_one(&manifest.l60).as_deref() == Some(manifest.u60.as_str()), )); let q_scaled = format!("{}{}", manifest.q, "0".repeat(45)); checks.push(( "finite.qs_below_L60", compare_decimals(&q_scaled, &manifest.l60) == Ordering::Less, )); checks.push(("finite.unsigned_15bit_replay", verify_unsigned_15bit_replay(manifest))); let mut interval_ok = manifest.bits == 15; if interval_ok { for d in 0u128..(1u128 << 15) { let Some(k) = exact_floor_from_open_interval(&manifest.l60, &manifest.u60, u64::try_from(d).unwrap()) else { interval_ok = false; break; }; if k != manifest.q * d / manifest.s { interval_ok = false; break; } } } checks.push(("finite.interval_floor_15bit", interval_ok)); let max_15_product = manifest.q.checked_mul(32_767); let max_16_product = manifest.q.checked_mul(65_535); checks.push(( "finite.unsigned_15bit_u64_bounds", matches!(max_15_product, Some(value) if value <= u128::from(u64::MAX)) && matches!(max_16_product, Some(value) if value > u128::from(u64::MAX)), )); checks.push(("finite.ordered_23step_ledgers", verify_ordered_23step_ledgers(manifest))); checks.push(("finite.canonical_byte_fold", verify_byte_fold(manifest))); let before = FIRST_MISMATCH - 1; let exact_before = exact_floor_from_open_interval(&manifest.l60, &manifest.u60, before); let exact_at = exact_floor_from_open_interval(&manifest.l60, &manifest.u60, FIRST_MISMATCH); let machine_before = manifest.q.checked_mul(u128::from(before)).map(|value| value / manifest.s); let machine_at = manifest .q .checked_mul(u128::from(FIRST_MISMATCH)) .map(|value| value / manifest.s); checks.push(( "finite.first_mismatch_boundary", exact_before == machine_before && exact_at == Some(14_342_163) && machine_at == Some(14_342_162), )); checks.push(("canonical.sha256_records", verify_canonical_hashes())); Ok(checks) } fn execute(path: &str) -> Result { let manifest = Manifest::read(path)?; let checks = run_checks(&manifest)?; let passed = checks.iter().all(|(_, ok)| *ok); for (name, ok) in checks { println!("{name}={}", if ok { "PASS" } else { "FAIL" }); } println!("RESULT={}", if passed { "PASS" } else { "FAIL" }); Ok(passed) } fn main() -> ExitCode { let path = env::args() .nth(1) .unwrap_or_else(|| "OMEGA_NAUGHT_1_0.manifest".into()); match execute(&path) { Ok(true) => ExitCode::SUCCESS, Ok(false) => ExitCode::FAILURE, Err(error) => { eprintln!("ERROR={error}"); ExitCode::FAILURE } } } #[cfg(test)] mod tests { use super::*; const MANIFEST: &str = include_str!("OMEGA_NAUGHT_1_0.manifest"); #[test] fn frozen_manifest_passes_every_check() { let manifest = Manifest::parse(MANIFEST).expect("frozen manifest parses"); let checks = run_checks(&manifest).expect("checks execute"); assert!(checks.iter().all(|(_, ok)| *ok), "failed checks: {checks:?}"); } #[test] fn duplicate_and_unknown_manifest_keys_are_rejected() { let duplicate = format!("{MANIFEST}\nQ=1\n"); assert!(Manifest::parse(&duplicate).is_err()); let unknown = format!("{MANIFEST}\nextra=1\n"); assert!(Manifest::parse(&unknown).is_err()); } #[test] fn sha256_implementation_matches_standard_vector() { assert_eq!( hex(&sha256(b"abc")), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" ); assert!(verify_canonical_hashes()); } #[test] fn byte_fold_is_canonical_and_reversible() { let manifest = Manifest::parse(MANIFEST).expect("frozen manifest parses"); assert!(verify_byte_fold(&manifest)); } #[test] fn exact_boundary_values_are_distinguished() { let manifest = Manifest::parse(MANIFEST).expect("frozen manifest parses"); assert_eq!( exact_floor_from_open_interval(&manifest.l60, &manifest.u60, FIRST_MISMATCH), Some(14_342_163) ); assert_eq!( manifest.q * u128::from(FIRST_MISMATCH) / manifest.s, 14_342_162 ); } }