Repository navigation
Challenge 28: Verify flt2dec safety with Kani - #818
Closed
fromtaoyuanhsinchuuuu wants to merge 3 commits into
Closed
fromtaoyuanhsinchuuuu wants to merge 3 commits into
fromtaoyuanhsinchuuuu wants to merge 3 commits into
Conversation
Use loop contracts and a verified round_and_weed contract to prove that the Grisu digit-generation loops only expose initialized ASCII digits. The approach is adapted from @v3risec's Challenge 28 solution (PR model-checking#606) to the current library/core/src/num/imp layout. Co-authored-by: v3risec <phalange123@126.com>
Author
|
Closing to rework the strategy proofs: the Grisu harnesses currently follow the cfg(kani) body-swap / assume-the-conclusion approach that was already rejected on #606. I will reopen with production bodies unchanged, machine-checked loop invariants, and no assumed digit bounds. |
This was referenced Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Challenge 28: Verify the
flt2decmoduleCloses #524.
This PR adds automated Kani harnesses for all twelve functions listed in
Challenge 28:
digits_to_dec_str,digits_to_exp_strto_shortest_str,to_shortest_exp_str,to_exact_exp_str,to_exact_fixed_str(f32,f64,f16)flt2dec::strategy::grisu::{format_shortest_opt, format_shortest, format_exact_opt, format_exact}flt2dec::strategy::dragon::{format_shortest, format_exact}24 harnesses in total, all of which pass locally with Kani 0.68.0.
Approach
flt2dec::mod(ghost witnesses). The formatting entry points are drivenwith symbolic
Decodedvalues and a callback that over-approximatesformat_*returning an arbitrary non-empty digit slice. To prove theassume_initcalls only expose written digits, the addedflt2dec::ghostmodule allocates uninitialized buffers with
malloc(CBMC with--object-bits 12) and checks a symbolic witness index withassert_unchecked, which is a non-panic UB check, so#[kani::should_panic]cannot mask an uninitialized byte.
dragon.Bigarithmetic is over-approximated by unconstrainedstub_setfunctions; the digit loop and everyassume_initsite are real.A
#[cfg_attr(kani, safety::loop_invariant(true))]keepsdiv_2pow10tractable.
grisu. The digit-generation loops carry Kani loop contracts, and thehoisted
round_and_weedhelper is checked through a verified contract and#[kani::stub_verified]. The expensive 64-bit scaling steps are abstractedonly under
cfg(kani)to their numeric contract (a decimal digit / remainderbound); the buffer writes and all
assume_initsites remain the real code.The Grisu verification strategy is adapted from @v3risec's Challenge 28
solution in #606 (rebased onto the current
library/core/src/num/implayout);the commit is co-authored accordingly.
Safety obligations
The proofs cover, for the harnessed preconditions (the documented
assert!/debug_assert!contracts of each function):MaybeUninit::assume_init*only sees written memory;format_shortest/format_exactdoes notintroduce UB;
problematic intrinsic use is reachable.
Verification performed locally
cargo check -p core: passes.rustfmt --checkwith the upstreamstyle_edition = "2024"config: clean.No non-
#[cfg(kani)]logic is changed beyond hoisting the privateround_and_weedhelper out offormat_shortest_optso it can be named by#[kani::stub_verified].Resolves #524.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.