Repository navigation
Conversation
For `phoare[while e do c : P ==> Q] >= bd` (resp. `= bd`), the rule of `while I v k eps` (`t_bdhoare_while_rev_geq_r`) only required, when the loop is not entered, `!Q => bd = 0%r` (resp. `bd = if Q then 1 else 0`), never `bd <= 1%r` elsewhere. With a loop that is never entered, every other goal is vacuous, so (#1127) phoare[M.f : true ==> true] >= 2%r was accepted for `while (false) {}`, from which `false` follows. Requiring `Q => bd <= 1%r` on loop exit, as suggested in #1127, is not enough. The rule is an induction on the iterations of the loop that starts from the probability 1: it needs `bd <= 1%r` in every memory satisfying the pre-condition. Otherwise, the hypothesis of the inductive goal holds for no statement, and that goal can be proved for a bound that grows along the iterations. For a loop that exits with probability 1/2 and otherwise increments `i`, the bound if b then 2 ^ i + 1 else 1 satisfies every goal, including the suggested one (it is 1 on exit), with `>=` as with `=`, and gives `false` as well. The rule now also emits forall &hr, P => bd <= 1%r as a last goal, which it tries to close with `trivial` (as #1130 does for the upper-bound rule), so constant bounds such as `1%r` need no extra step. This premise loses no valid judgement: `Pr[...] >= bd`, and a fortiori `Pr[...] = bd`, implies it. Three proofs with an `=` bound that is not a constant need one more step to establish it: theories/distributions/Dexcepted.ec, and examples/PIR.ec (twice) and examples/vonNeumann.eca. Fixes #1127. Origin: the rule was introduced in edb2017 (2013-09-20, first released in r2022.04); 70ac960 (2022-06-19) added the exit check on `Q` for `=` only. Test: tests/phoare-while-geq-bound.ec (the #1127 reproducer and the growing bound, with `>=` and with `=`; the previous build proves them). unit (140 files), stdlib (128) and examples (49) pass.
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.
For
phoare[while e do c : P ==> Q] >= bd(resp.= bd), the rule ofwhile I v k eps(t_bdhoare_while_rev_geq_r) only required, when theloop is not entered,
!Q => bd = 0%r(resp.bd = if Q then 1 else 0), neverbd <= 1%relsewhere. With a loopthat is never entered, every other goal is vacuous, so (#1127)
was accepted for
while (false) {}, from whichfalsefollows.Requiring
Q => bd <= 1%ron loop exit, as suggested in #1127, is notenough. The rule is an induction on the iterations of the loop that
starts from the probability 1: it needs
bd <= 1%rin every memorysatisfying the pre-condition. Otherwise, the hypothesis of the
inductive goal holds for no statement, and that goal can be proved for
a bound that grows along the iterations. For a loop that exits with
probability 1/2 and otherwise increments
i, the boundsatisfies every goal, including the suggested one (it is 1 on exit),
with
>=as with=, and givesfalseas well.The rule now also emits
as a last goal, which it tries to close with
trivial(as #1130 doesfor the upper-bound rule), so constant bounds such as
1%rneed noextra step. This premise loses no valid judgement:
Pr[...] >= bd, anda fortiori
Pr[...] = bd, implies it. Three proofs with an=boundthat is not a constant need one more step to establish it:
theories/distributions/Dexcepted.ec, and examples/PIR.ec (twice) and
examples/vonNeumann.eca.
Fixes #1127.
Origin: the rule was introduced in edb2017 (2013-09-20, first
released in r2022.04); 70ac960 (2022-06-19) added the exit check on
Qfor=only.Test: tests/phoare-while-geq-bound.ec (the #1127 reproducer and the
growing bound, with
>=and with=; the previous build provesthem). unit (140 files), stdlib (128) and examples (49) pass.