Repository navigation
Challenge 28: Verify flt2dec with production bodies (Kani) - #819
Open
fromtaoyuanhsinchuuuu wants to merge 5 commits into
Open
fromtaoyuanhsinchuuuu wants to merge 5 commits into
fromtaoyuanhsinchuuuu wants to merge 5 commits into
Conversation
Prove the Grisu digit-generation loops with Kani without swapping in alternate #[cfg(kani)] function bodies: * The real integral and fractional loops run unchanged apart from an explicit MAX_SIG_DIGITS guard, which is implied by the Loitsch bound and makes the write bound explicit. * A symbolic witness index tracks that every byte handed to assume_init* has been written; harness buffers are zeroed, so an unwritten byte fails the ASCII-digit obligation. * Heavy arithmetic helpers are replaced by documented models: Fp::mul returns the lower endpoint of the real product interval (monotone, preserving minus < v < plus), cached_power keeps its table postconditions, round_and_weed/round_up only touch initialized digits. * max_pow10_no_more_than is case-split into the ten decades, which is its complete specification; each harness therefore sees a concrete ten_kappa and the real division is tractable. 22 harnesses cover the four Grisu functions, including the two Dragon fallbacks through their wrappers, and pass in about 8 seconds each. Co-authored-by: v3risec <phalange123@126.com>
Remove the duplicated ghost helper in favor of the shared flt2dec::ghost module, give the Dragon digit loop an explicit MAX_SIG_DIGITS bound and carry guard, and document the exact property, ghost witness, arithmetic models, production bounds, non-vacuity anchors and limitations in the verify modules.
Add lemma harnesses for the three numeric models used by the strategy proofs: the Fp::mul interval, the cached_power table postcondition, and the complete max_pow10_no_more_than specification.
This branch has not been deployed
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
flt2decwith production bodiesResolves #524.
This is a rework of the earlier #818. It now verifies the production
function bodies for all twelve Challenge 28 targets, without the
#[cfg(kani)]body swaps orassume(q < 10)-at-the-digit-write pattern thatthe review of #606 correctly rejected.
What is proved
For the documented preconditions of each function (the
assert!s already inthe bodies):
MaybeUninit::assume_init*call sees a fully written prefix;format_shortest/format_exactlifetime laundering does not cause UB;problematic intrinsic use is reachable.
Ghost witness
flt2dec::ghostpicks one symbolic byte index and asserts withcore::hint::assert_uncheckedthat the byte is an ASCII digit. Because theindex is symbolic, one assertion covers every byte. Harness buffers start as
zeroes (not a digit), so an unwritten byte cannot satisfy the obligation.
assert_uncheckedis a non-panic UB check, so a panic cannot mask a violation.Grisu: no body swaps
MAX_SIG_DIGITSguard (implied by the Loitsch digit-count theorem) and anexplicit nine-step bound in the weeding loop.
round_and_weedis hoisted sothe wrapper harness can name it; its body is unchanged.
function bodies:
Fp::mulreturnsa.f / 2, the lower endpoint of the real productinterval
[a.f / 2, a.f)for a normalized cached power; it is monotone ina.f, preservingminus < v < plus.cached_powerreturns an arbitrary table-shaped entry withe in [alpha, gamma], i.e. exactly the table postcondition.round_and_weed/round_uponly read or rewrite bytes that are alreadyinitialized; their models never introduce new uninitialized memory.
max_pow10_no_more_thanis split into its ten possible return values. Thedecade assumption is its complete specification, so ten harnesses cover
every caller-visible result while keeping the real division concrete.
decode(f32)/decode(f64)domains, not a 4-bit or8-bit narrowed mantissa.
kani::coveranchors require both theSomeandNoneoutcomes.Dragon
The real
format_shortest/format_exactbodies run with bignum arithmeticreplaced by havoc models that keep the representation size valid; comparisons
and
is_zeroare nondeterministic.format_shortesthas an explicitMAX_SIG_DIGITSloop bound and a guarded final carry write. The harnesses are#[kani::should_panic]because the havoc models can violate bignum-specificdebug_assert!s; those paths panic, which is safe, while the initializationobligation is an
assert_uncheckedcheck thatshould_paniccannot mask.kani::coveranchors keep the digit-producing paths non-vacuous.Known limitation: the exact-mode Dragon harness constrains
len <= 8forsolver tractability; the loop structure and all write sites are identical for
longer buffers.
flt2dec::modThe formatting entry points run their real bodies with a callback that
over-approximates
format_*by returning an arbitrary non-empty digit slice.flt2dec::ghostallocates uninitialized buffers withmalloc(CBMC--object-bits 12), so the witness checks a genuinely unwritten buffer ratherthan a pre-initialized one.
Local verification
cargo check -p core: passes.rustfmt --checkwith the upstreamstyle_edition = "2024"config: clean.The
flt2dec::modand Dragon parts build on the earlier Challenge 28 work inthis branch; the Grisu approach is informed by the review feedback on #596
and #606 but keeps the production bodies and uses the models documented above.
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.
Model lemmas
check_fp_mul_interval,check_cached_power_contractandcheck_max_pow10_contractverify the three numeric models against the realFp::mul,cached_powerandmax_pow10_no_more_thanbodies.