Dispatcher contract and trace evidence Files inspected (SHA-256 from sha256sum 9.1): upstream/dec2flt/mod.rs 7198e238c554b692405537a446b3526ad66805ec2900cd0e299f10c51402a44a crate/dec2flt/mod.rs ecadc1d7df05dfda85fcf99fc45da7e40cb36aa9736d12d1b3a75f60f532907d upstream/dec2flt/parse.rs 9daf21ab9445a84552535152f376eef8c30f3d5827296c0645f5952d3b22bbf1 crate/dec2flt/parse.rs 50d95265e5b1af43ee4f0033c9ff8d1b8dfd62d766ab14668ceec19955adba1f Tablet/num_imp_dec2flt_dec2flt_with_trace.lean fc6b6d0c31c801820e9e1981a1a777701b6a70dac0892b22ace44edbca4eeeb7 Tablet/num_imp_dec2flt_Dec2FltAssemblyTrace.lean e1021975d4efe22771953025dd5145bc3f1305f2046a4cf20790ff9ff633c520 Reproduction commands: sha256sum upstream/dec2flt/mod.rs crate/dec2flt/mod.rs \ upstream/dec2flt/parse.rs crate/dec2flt/parse.rs \ Tablet/num_imp_dec2flt_dec2flt_with_trace.lean \ Tablet/num_imp_dec2flt_Dec2FltAssemblyTrace.lean nl -ba upstream/dec2flt/mod.rs | sed -n '209,255p' nl -ba crate/dec2flt/mod.rs | sed -n '354,523p' nl -ba upstream/dec2flt/parse.rs | sed -n '198,242p' nl -ba crate/dec2flt/parse.rs | sed -n '240,284p' nl -ba Tablet/num_imp_dec2flt_dec2flt_with_trace.lean | sed -n '36,194p' nl -ba Tablet/num_imp_dec2flt_Dec2FltAssemblyTrace.lean | sed -n '31,52p' Raw source observations: upstream lines 212-225 convert the string to bytes, strip at most one leading sign, reject an empty body, call parse_number first, and call parse_inf_nan only after parse_number returns None. upstream lines 227-232 overwrite Decimal.negative with the lexical sign and return a Some result from try_fast_path directly. upstream lines 238-249 call compute_float(exponent, mantissa), call compute_float(exponent, mantissa + 1) exactly when many_digits and the first biased exponent is nonnegative, set that exponent to -1 on disagreement, and replace every negative-exponent current pair with parse_long_mantissa(body). upstream lines 251-255 assemble the selected pair, negate only after assembly when Decimal.negative is true, and return the resulting float. upstream parse.rs lines 199-241 show the special helper's length branches, register construction and masking, keyword match, and final sign branch. They locate the helper body called by the dispatcher; this excerpt alone is not used to establish a DispatchContracts semantic law. Raw adapted-source observations: crate lines 354-504 are the traced dispatcher. Its sign/body and lexical branches are lines 364-403; the native call and direct return are lines 405-421; and integer calls, comparison/deferral, slow fallback, assembly, final sign, and trace construction are lines 424-503. These lines record branch order, call boundaries, and already-computed observations; they do not establish the semantic contracts of the called helpers. crate lines 506-523 define the public dispatcher as the first projection of the one traced implementation, with the projection call at line 522. crate parse.rs lines 241-283 retain that special-parser control structure: the same length split, case mask, three constants and matches, rejection branch, selected branch value, and final sign branch appear at lines 249-283. Concrete satisfaction of the abstract special-parser laws is not inferred from this syntactic comparison. Raw extracted-model observations: num_imp_dec2flt_dec2flt_with_trace.lean lines 36-77 retain the sign-removal, empty/sign-only, parse_number, parse_inf_nan, invalid, and special branches. Lines 78-115 retain the native call, first integer call, exact second-call guard, checked U64 addition, second call, equality comparison, and exponent -1 update. Lines 116-194 retain the slow replacement, Rust cast/shift/OR assembled word, biased_fp_to_float call, optional negation, and every trace field in both sign branches. num_imp_dec2flt_Dec2FltAssemblyTrace.lean lines 31-52 list, in order, the body and sign; parsed and fast-path values; first and second integer values; comparison and deferral values; post-comparison, slow, and selected pairs; and assembly, sign, and final-result values used by the paired contracts. Scope of this evidence: The excerpts below support only branch order, helper call boundaries, the observations recorded by the trace, and the fact that public dec2flt projects the result of the single traced computation. Seeing a helper call or its source body is not evidence that the extracted helper returns normally or satisfies a DispatchContracts semantic law. Those facts belong to the separate dispatch_component_compliance obligation. Captured excerpts (command output, with trailing whitespace removed): --- upstream/dec2flt/mod.rs lines 209-255 --- $ nl -ba upstream/dec2flt/mod.rs | sed -n '209,255p' 209 /// Converts a decimal string into a floating point number. 210 #[inline(always)] // Will be inlined into a function with `#[inline(never)]`, see above 211 pub fn dec2flt(s: &str) -> Result { 212 let mut s = s.as_bytes(); 213 let Some(&c) = s.first() else { return Err(pfe_empty()) }; 214 let negative = c == b'-'; 215 if c == b'-' || c == b'+' { 216 s = &s[1..]; 217 } 218 if s.is_empty() { 219 return Err(pfe_invalid()); 220 } 221 222 let mut num = match parse_number(s) { 223 Some(r) => r, 224 None if let Some(value) = parse_inf_nan(s, negative) => return Ok(value), 225 None => return Err(pfe_invalid()), 226 }; 227 num.negative = negative; 228 if !cfg!(feature = "optimize_for_size") { 229 if let Some(value) = num.try_fast_path::() { 230 return Ok(value); 231 } 232 } 233 234 // If significant digits were truncated, then we can have rounding error 235 // only if `mantissa + 1` produces a different result. We also avoid 236 // redundantly using the Eisel-Lemire algorithm if it was unable to 237 // correctly round on the first pass. 238 let mut fp = compute_float::(num.exponent, num.mantissa); 239 if num.many_digits 240 && fp.p_biased >= 0 241 && fp != compute_float::(num.exponent, num.mantissa + 1) 242 { 243 fp.p_biased = -1; 244 } 245 // Unable to correctly round the float using the Eisel-Lemire algorithm. 246 // Fallback to a slower, but always correct algorithm. 247 if fp.p_biased < 0 { 248 fp = parse_long_mantissa::(s); 249 } 250 251 let mut float = biased_fp_to_float::(fp); 252 if num.negative { 253 float = -float; 254 } 255 Ok(float) --- crate/dec2flt/mod.rs lines 354-523 --- $ nl -ba crate/dec2flt/mod.rs | sed -n '354,523p' 354 /// Run the actual dispatcher while retaining its approved internal observations. 355 pub fn dec2flt_with_trace< 356 'a, 357 F: Lemire 358 + core::ops::Div 359 + core::ops::Mul 360 + core::ops::Neg, 361 >( 362 s: &'a str, 363 ) -> (Result, Dec2FltTrace<'a, F>) { 364 let mut body = s.as_bytes(); 365 let Some(&c) = body.first() else { 366 return (Err(pfe_empty()), Dec2FltTrace::EmptyInput); 367 }; 368 let negative = c == b'-'; 369 if c == b'-' || c == b'+' { 370 body = &body[1..]; 371 } 372 if body.is_empty() { 373 return (Err(pfe_invalid()), Dec2FltTrace::SignOnly { body, negative }); 374 } 375 376 let parse_number_result = parse_number(body); 377 let parsed = match parse_number_result { 378 Some(r) => r, 379 None => { 380 let parse_inf_nan_result = parse_inf_nan(body, negative); 381 return match parse_inf_nan_result { 382 Some(value) => ( 383 Ok(value), 384 Dec2FltTrace::Special { 385 body, 386 negative, 387 parse_number_result, 388 parse_inf_nan_result, 389 result: value, 390 }, 391 ), 392 None => ( 393 Err(pfe_invalid()), 394 Dec2FltTrace::Invalid { 395 body, 396 negative, 397 parse_number_result, 398 parse_inf_nan_result, 399 }, 400 ), 401 }; 402 } 403 }; 404 405 let mut num = parsed; 406 num.negative = negative; 407 if !cfg!(feature = "optimize_for_size") { 408 let fast_path_result = num.try_fast_path::(); 409 if let Some(value) = fast_path_result { 410 return ( 411 Ok(value), 412 Dec2FltTrace::FastPath { 413 body, 414 negative, 415 parse_number_result, 416 fast_path_input: num, 417 fast_path_result, 418 result: value, 419 }, 420 ); 421 } 422 } 423 424 let first_compute_exponent = num.exponent; 425 let first_compute_mantissa = num.mantissa; 426 let first_compute_result = compute_float::(first_compute_exponent, first_compute_mantissa); 427 let mut fp = first_compute_result; 428 429 // This expands the source short-circuit conjunction without moving the 430 // checked `mantissa + 1`: that addition and the second helper call still 431 // occur exactly when `many_digits && fp.p_biased >= 0`. 432 let second_compute_guard = num.many_digits && fp.p_biased >= 0; 433 let mut second_compute_exponent = None; 434 let mut second_compute_mantissa = None; 435 let mut second_compute_result = None; 436 let mut second_equals_first = None; 437 let mut forced_deferral = false; 438 if second_compute_guard { 439 let exponent = num.exponent; 440 let mantissa = num.mantissa + 1; 441 let second = compute_float::(exponent, mantissa); 442 let equal = fp == second; 443 second_compute_exponent = Some(exponent); 444 second_compute_mantissa = Some(mantissa); 445 second_compute_result = Some(second); 446 second_equals_first = Some(equal); 447 if !equal { 448 fp.p_biased = -1; 449 forced_deferral = true; 450 } 451 } 452 let post_comparison_pair = fp; 453 454 let slow_path_guard = fp.p_biased < 0; 455 let mut slow_path_result = None; 456 if slow_path_guard { 457 // The exact slow-path input is the trace's common `body`; the guard 458 // records whether this call occurred, avoiding a duplicate live slice 459 // reference that Aeneas cannot join across this branch. 460 let replacement = parse_long_mantissa::(body); 461 slow_path_result = Some(replacement); 462 fp = replacement; 463 } 464 465 let selected_pair = fp; 466 // This is the same pure cast/shift/OR used by `biased_fp_to_float`; recording 467 // it neither changes the selected pair nor introduces a new branch or call. 468 let assembled_word = fp.m | ((fp.p_biased as u64) << F::SIG_BITS); 469 let assembly_result = biased_fp_to_float::(fp); 470 let lexical_sign_applied = num.negative; 471 let result = if lexical_sign_applied { 472 core::ops::Neg::neg(assembly_result) 473 } else { 474 assembly_result 475 }; 476 477 ( 478 Ok(result), 479 Dec2FltTrace::Assembled(Dec2FltAssemblyTrace { 480 body, 481 negative, 482 parse_number_result, 483 fast_path_input: num, 484 fast_path_result: None, 485 first_compute_exponent, 486 first_compute_mantissa, 487 first_compute_result, 488 second_compute_guard, 489 second_compute_exponent, 490 second_compute_mantissa, 491 second_compute_result, 492 second_equals_first, 493 forced_deferral, 494 post_comparison_pair, 495 slow_path_guard, 496 slow_path_result, 497 selected_pair, 498 assembled_word, 499 assembly_result, 500 lexical_sign_applied, 501 result, 502 }), 503 ) 504 } 505 506 /// Converts a decimal string into a floating point number. 507 #[inline(always)] // Will be inlined into a function with `#[inline(never)]`, see above 508 pub fn dec2flt< 509 F: Lemire 510 + core::ops::Div 511 + core::ops::Mul 512 + core::ops::Neg, 513 >( 514 s: &str, 515 ) -> Result { 516 // `Lemire` already implies `Neg` through `Float`; the direct 517 // clause admits exactly the same instances and lets Charon resolve the 518 // explicit, source-equivalent final negation. 519 // The public function is now exactly the result projection of the single 520 // instrumented implementation. No conversion step is duplicated, and 521 // discarding the trace cannot affect Rust evaluation or the returned bits. 522 dec2flt_with_trace::(s).0 523 } --- upstream/dec2flt/parse.rs lines 198-242 --- $ nl -ba upstream/dec2flt/parse.rs | sed -n '198,242p' 198 /// Try to parse a special, non-finite float. 199 pub(crate) fn parse_inf_nan(s: &[u8], negative: bool) -> Option { 200 // Since a valid string has at most the length 8, we can load 201 // all relevant characters into a u64 and work from there. 202 // This also generates much better code. 203 204 let mut register; 205 let len: usize; 206 207 // All valid strings are either of length 8 or 3. 208 if s.len() == 8 { 209 register = s.read_u64(); 210 len = 8; 211 } else if s.len() == 3 { 212 let a = s[0] as u64; 213 let b = s[1] as u64; 214 let c = s[2] as u64; 215 register = (c << 16) | (b << 8) | a; 216 len = 3; 217 } else { 218 return None; 219 } 220 221 // Clear out the bits which turn ASCII uppercase characters into 222 // lowercase characters. The resulting string is all uppercase. 223 // What happens to other characters is irrelevant. 224 register &= 0xDFDFDFDFDFDFDFDF; 225 226 // u64 values corresponding to relevant cases 227 const INF_3: u64 = 0x464E49; // "INF" 228 const INF_8: u64 = 0x5954494E49464E49; // "INFINITY" 229 const NAN: u64 = 0x4E414E; // "NAN" 230 231 // Match register value to constant to parse string. 232 // Also match on the string length to catch edge cases 233 // like "inf\0\0\0\0\0". 234 let float = match (register, len) { 235 (INF_3, 3) => F::INFINITY, 236 (INF_8, 8) => F::INFINITY, 237 (NAN, 3) => F::NAN, 238 _ => return None, 239 }; 240 241 if negative { Some(-float) } else { Some(float) } 242 } --- crate/dec2flt/parse.rs lines 240-284 --- $ nl -ba crate/dec2flt/parse.rs | sed -n '240,284p' 240 /// Try to parse a special, non-finite float. 241 pub(crate) fn parse_inf_nan(s: &[u8], negative: bool) -> Option { 242 // Since a valid string has at most the length 8, we can load 243 // all relevant characters into a u64 and work from there. 244 // This also generates much better code. 245 246 let mut register; 247 let len: usize; 248 249 // All valid strings are either of length 8 or 3. 250 if s.len() == 8 { 251 register = s.read_u64(); 252 len = 8; 253 } else if s.len() == 3 { 254 let a = s[0] as u64; 255 let b = s[1] as u64; 256 let c = s[2] as u64; 257 register = (c << 16) | (b << 8) | a; 258 len = 3; 259 } else { 260 return None; 261 } 262 263 // Clear out the bits which turn ASCII uppercase characters into 264 // lowercase characters. The resulting string is all uppercase. 265 // What happens to other characters is irrelevant. 266 register &= 0xDFDFDFDFDFDFDFDF; 267 268 // u64 values corresponding to relevant cases 269 const INF_3: u64 = 0x464E49; // "INF" 270 const INF_8: u64 = 0x5954494E49464E49; // "INFINITY" 271 const NAN: u64 = 0x4E414E; // "NAN" 272 273 // Match register value to constant to parse string. 274 // Also match on the string length to catch edge cases 275 // like "inf\0\0\0\0\0". 276 let float = match (register, len) { 277 (INF_3, 3) => F::INFINITY, 278 (INF_8, 8) => F::INFINITY, 279 (NAN, 3) => F::NAN, 280 _ => return None, 281 }; 282 283 if negative { Some(-float) } else { Some(float) } 284 } --- Tablet/num_imp_dec2flt_dec2flt_with_trace.lean lines 36-194 --- $ nl -ba Tablet/num_imp_dec2flt_dec2flt_with_trace.lean | sed -n '36,194p' 36 do 37 let body ← core.str.Str.as_bytes s 38 let o ← core.slice.Slice.first body 39 match o with 40 | none => 41 let pfe ← num.imp.dec2flt.pfe_empty 42 ok (core.result.Result.Err pfe, num.imp.dec2flt.Dec2FltTrace.EmptyInput) 43 | some c => 44 let body1 ← 45 if c = 45#u8 46 then 47 core.slice.index.Slice.index 48 (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) body 49 { start := 1#usize } 50 else 51 if c = 43#u8 52 then 53 core.slice.index.Slice.index 54 (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) body 55 { start := 1#usize } 56 else ok body 57 let b ← core.slice.Slice.is_empty body1 58 if b 59 then 60 let pfe ← num.imp.dec2flt.pfe_invalid 61 ok (core.result.Result.Err pfe, num.imp.dec2flt.Dec2FltTrace.SignOnly 62 body1 (c = 45#u8)) 63 else 64 let parse_number_result ← num.imp.dec2flt.parse.parse_number body1 65 match parse_number_result with 66 | none => 67 let parse_inf_nan_result ← 68 num.imp.dec2flt.parse.parse_inf_nan 69 LemireInst.traitsFloatExtInst.FloatInst body1 (c = 45#u8) 70 match parse_inf_nan_result with 71 | none => 72 let pfe ← num.imp.dec2flt.pfe_invalid 73 ok (core.result.Result.Err pfe, num.imp.dec2flt.Dec2FltTrace.Invalid 74 body1 (c = 45#u8) none none) 75 | some value => 76 ok (core.result.Result.Ok value, num.imp.dec2flt.Dec2FltTrace.Special 77 body1 (c = 45#u8) none parse_inf_nan_result value) 78 | some r => 79 let fast_path_result ← 80 num.imp.dec2flt.decimal.Decimal.try_fast_path LemireInst 81 coreopsarithDivInst coreopsarithMulInst coreopsarithNegInst 82 { r with negative := (c = 45#u8) } 83 match fast_path_result with 84 | none => 85 let first_compute_result ← 86 num.imp.dec2flt.lemire.compute_float 87 LemireInst.traitsFloatExtInst.FloatInst r.exponent r.mantissa 88 let (b1, b2, first_compute_result1, fp, second_compute_guard) ← 89 if r.many_digits 90 then 91 ok (true, true, first_compute_result, first_compute_result, 92 first_compute_result.p_biased >= 0#i32) 93 else 94 ok (false, false, first_compute_result, first_compute_result, 95 false) 96 let (post_comparison_pair, second_compute_exponent, 97 second_compute_mantissa, second_compute_result, 98 second_equals_first, forced_deferral) ← 99 if second_compute_guard 100 then 101 do 102 let mantissa ← r.mantissa + 1#u64 103 let second ← 104 num.imp.dec2flt.lemire.compute_float 105 LemireInst.traitsFloatExtInst.FloatInst r.exponent mantissa 106 let equal ← 107 num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq 108 fp second 109 let (bf, b3) ← 110 if equal 111 then ok (fp, false) 112 else ok ({ fp with p_biased := (-1)#i32 }, true) 113 ok (bf, some r.exponent, some mantissa, some second, some equal, 114 b3) 115 else ok (fp, none, none, none, none, false) 116 let (selected_pair, slow_path_guard, slow_path_result) ← 117 if post_comparison_pair.p_biased < 0#i32 118 then 119 do 120 let replacement ← 121 num.imp.dec2flt.slow.parse_long_mantissa 122 LemireInst.traitsFloatExtInst.FloatInst body1 123 ok (replacement, true, some replacement) 124 else ok (post_comparison_pair, false, none) 125 let i ← lift (IScalar.hcast .U64 selected_pair.p_biased) 126 let i1 ← LemireInst.traitsFloatExtInst.FloatInst.SIG_BITS 127 let i2 ← i <<< i1 128 let assembled_word ← lift (selected_pair.m ||| i2) 129 let assembly_result ← 130 num.imp.dec2flt.biased_fp_to_float LemireInst.traitsFloatExtInst 131 selected_pair 132 if c = 45#u8 133 then 134 let result ← coreopsarithNegInst.neg assembly_result 135 ok (core.result.Result.Ok result, 136 num.imp.dec2flt.Dec2FltTrace.Assembled 137 { 138 body := body1, 139 negative := true, 140 parse_number_result := (some { r with many_digits := b1 }), 141 fast_path_input := 142 { r with negative := true, many_digits := b2 }, 143 fast_path_result := none, 144 first_compute_exponent := r.exponent, 145 first_compute_mantissa := r.mantissa, 146 first_compute_result := first_compute_result1, 147 second_compute_guard, 148 second_compute_exponent, 149 second_compute_mantissa, 150 second_compute_result, 151 second_equals_first, 152 forced_deferral, 153 post_comparison_pair, 154 slow_path_guard, 155 slow_path_result, 156 selected_pair, 157 assembled_word, 158 assembly_result, 159 lexical_sign_applied := true, 160 result 161 }) 162 else 163 ok (core.result.Result.Ok assembly_result, 164 num.imp.dec2flt.Dec2FltTrace.Assembled 165 { 166 body := body1, 167 negative := false, 168 parse_number_result := (some { r with many_digits := b1 }), 169 fast_path_input := 170 { r with negative := false, many_digits := b2 }, 171 fast_path_result := none, 172 first_compute_exponent := r.exponent, 173 first_compute_mantissa := r.mantissa, 174 first_compute_result := first_compute_result1, 175 second_compute_guard, 176 second_compute_exponent, 177 second_compute_mantissa, 178 second_compute_result, 179 second_equals_first, 180 forced_deferral, 181 post_comparison_pair, 182 slow_path_guard, 183 slow_path_result, 184 selected_pair, 185 assembled_word, 186 assembly_result, 187 lexical_sign_applied := false, 188 result := assembly_result 189 }) 190 | some value => 191 ok (core.result.Result.Ok value, 192 num.imp.dec2flt.Dec2FltTrace.FastPath body1 (c = 45#u8) 193 parse_number_result { r with negative := (c = 45#u8) } 194 fast_path_result value) --- Tablet/num_imp_dec2flt_Dec2FltAssemblyTrace.lean lines 31-52 --- $ nl -ba Tablet/num_imp_dec2flt_Dec2FltAssemblyTrace.lean | sed -n '31,52p' 31 body : Slice Std.U8 32 negative : Bool 33 parse_number_result : Option num.imp.dec2flt.decimal.Decimal 34 fast_path_input : num.imp.dec2flt.decimal.Decimal 35 fast_path_result : Option F 36 first_compute_exponent : Std.I64 37 first_compute_mantissa : Std.U64 38 first_compute_result : num.imp.dec2flt.common.BiasedFp 39 second_compute_guard : Bool 40 second_compute_exponent : Option Std.I64 41 second_compute_mantissa : Option Std.U64 42 second_compute_result : Option num.imp.dec2flt.common.BiasedFp 43 second_equals_first : Option Bool 44 forced_deferral : Bool 45 post_comparison_pair : num.imp.dec2flt.common.BiasedFp 46 slow_path_guard : Bool 47 slow_path_result : Option num.imp.dec2flt.common.BiasedFp 48 selected_pair : num.imp.dec2flt.common.BiasedFp 49 assembled_word : Std.U64 50 assembly_result : F 51 lexical_sign_applied : Bool 52 result : F